Skip to content

Commit

Permalink
style: reformat for 86 sym line width
Browse files Browse the repository at this point in the history
  • Loading branch information
sergeysova committed May 10, 2021
1 parent 4739ea5 commit 6714233
Show file tree
Hide file tree
Showing 29 changed files with 51 additions and 132 deletions.
2 changes: 1 addition & 1 deletion .prettierrc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"arrowParens": "always",
"printWidth": 80,
"printWidth": 86,
"semi": true,
"singleQuote": true,
"tabWidth": 2,
Expand Down
4 changes: 1 addition & 3 deletions .scripts/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,7 @@ async function createPresetPlugins(names) {

const factories = ['patronum', ...methods];

const mapping = Object.fromEntries(
names.map((name) => [camelCase(name), name]),
);
const mapping = Object.fromEntries(names.map((name) => [camelCase(name), name]));

await writeFile(
'./babel-plugin-factories.json',
Expand Down
6 changes: 1 addition & 5 deletions combine-events/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,4 @@ export function combineEvents<P extends Shape>(config: {
export function combineEvents<
P extends Shape,
T extends Unit<P extends Tuple ? P : Partial<P>>,
>(config: {
events: Events<P>;
target: T;
reset?: Unit<any>;
}): ReturnTarget<P, T>;
>(config: { events: Events<P>; target: T; reset?: Unit<any> }): ReturnTarget<P, T>;
6 changes: 1 addition & 5 deletions combine-events/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,7 @@ const throwError = (message) => {
throw new Error(message);
};

function combineEvents({
events,
reset,
target = createEvent({ named: 'target' }),
}) {
function combineEvents({ events, reset, target = createEvent({ named: 'target' }) }) {
if (!is.unit(target)) throwError('target should be a unit');
if (reset && !is.unit(reset)) throwError('reset should be a unit');

Expand Down
12 changes: 6 additions & 6 deletions debounce/debounce.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ describe('arguments validation', () => {
});

test('domain is not allowed', () => {
expect(() =>
debounce({ source: createDomain(), timeout: 10 }),
).toThrowError(/cannot be domain/);
expect(() => debounce({ source: createDomain(), timeout: 10 })).toThrowError(
/cannot be domain/,
);
});

test('negative timeout is wrong', () => {
Expand All @@ -33,9 +33,9 @@ describe('arguments validation', () => {
});

test('Infinity timeout is wrong', () => {
expect(() =>
debounce({ source: createEvent(), timeout: Infinity }),
).toThrowError(/must be positive/);
expect(() => debounce({ source: createEvent(), timeout: Infinity })).toThrowError(
/must be positive/,
);
expect(() =>
debounce({ source: createEvent(), timeout: -Infinity }),
).toThrowError(/must be positive/);
Expand Down
3 changes: 1 addition & 2 deletions debounce/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
const { is, createEffect, forward, createEvent } = require('effector');

function debounce({ source, timeout, target }) {
if (!is.unit(source))
throw new TypeError('source must be unit from effector');
if (!is.unit(source)) throw new TypeError('source must be unit from effector');

if (is.domain(source)) throw new TypeError('source cannot be domain');

Expand Down
4 changes: 1 addition & 3 deletions debug/debug.fork.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@ afterEach(() => {
test('works in forked scope', async () => {
const app = createDomain();
const event = app.createEvent<number>();
const effect = app.createEffect(
async (payload: string) => `result ${payload}`,
);
const effect = app.createEffect(async (payload: string) => `result ${payload}`);
const $store = app
.createStore(0)
.on(event, (counter, payload) => counter + payload)
Expand Down
4 changes: 1 addition & 3 deletions debug/debug.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@ afterEach(() => {

test('debug event, store, effect simultaneously', async () => {
const event = createEvent<number>();
const effect = createEffect().use((payload) =>
Promise.resolve('result' + payload),
);
const effect = createEffect().use((payload) => Promise.resolve('result' + payload));
const $store = createStore(0)
.on(event, (state, value) => state + value)
.on(effect.done, (state) => state * 10);
Expand Down
10 changes: 3 additions & 7 deletions delay/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@ const { createEffect, createEvent, forward, is, sample } = require('effector');
const { readConfig } = require('../library');

function delay({ source, timeout, target = createEvent() }) {
if (!is.unit(source))
throw new TypeError('source must be a unit from effector');
if (!is.unit(source)) throw new TypeError('source must be a unit from effector');

if (!is.unit(target))
throw new TypeError('target must be a unit from effector');
if (!is.unit(target)) throw new TypeError('target must be a unit from effector');

const ms = validateTimeout(timeout);

Expand All @@ -26,9 +24,7 @@ function delay({ source, timeout, target = createEvent() }) {
fn: ({ milliseconds }, payload) => ({
payload,
milliseconds:
typeof milliseconds === 'function'
? milliseconds(payload)
: milliseconds,
typeof milliseconds === 'function' ? milliseconds(payload) : milliseconds,
}),
target: timerFx,
});
Expand Down
8 changes: 2 additions & 6 deletions every/every.fork.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,7 @@ test('throttle do not affect another forks', async () => {
const app = createDomain();
const change = app.createEvent<number>();
const $first = app.createStore(0);
const $second = app
.createStore(0)
.on(change, (state, payload) => state + payload);
const $second = app.createStore(0).on(change, (state, payload) => state + payload);
const $third = app.createStore(0);

const _$result = every({
Expand Down Expand Up @@ -85,9 +83,7 @@ test('throttle do not affect original store value', async () => {
const app = createDomain();
const change = app.createEvent<number>();
const $first = app.createStore(0);
const $second = app
.createStore(0)
.on(change, (state, payload) => state + payload);
const $second = app.createStore(0).on(change, (state, payload) => state + payload);
const $third = app.createStore(0);

const $result = every({
Expand Down
4 changes: 1 addition & 3 deletions every/index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
const { combine } = require('effector');

function every({ predicate, stores }) {
const checker = isFunction(predicate)
? predicate
: (value) => value === predicate;
const checker = isFunction(predicate) ? predicate : (value) => value === predicate;

return combine(stores, (values) => values.every(checker));
}
Expand Down
16 changes: 6 additions & 10 deletions in-flight/in-flight.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,11 +180,9 @@ describe('effects', () => {
`);

await waitFor(
combine(
effect2.inFlight,
effect1.inFlight,
(a, b) => a + b,
).updates.filter({ fn: (c) => c === 0 }),
combine(effect2.inFlight, effect1.inFlight, (a, b) => a + b).updates.filter({
fn: (c) => c === 0,
}),
);
expect(argumentHistory(fn)).toMatchInlineSnapshot(`
Array [
Expand Down Expand Up @@ -381,11 +379,9 @@ describe('domain', () => {
`);

await waitFor(
combine(
effect2.inFlight,
effect1.inFlight,
(a, b) => a + b,
).updates.filter({ fn: (c) => c === 0 }),
combine(effect2.inFlight, effect1.inFlight, (a, b) => a + b).updates.filter({
fn: (c) => c === 0,
}),
);
expect(argumentHistory(fn)).toMatchInlineSnapshot(`
Array [
Expand Down
4 changes: 1 addition & 3 deletions in-flight/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import { Store, Effect, Domain } from 'effector';

export function inFlight(_: {
effects: Array<Effect<any, any, any>>;
}): Store<number>;
export function inFlight(_: { effects: Array<Effect<any, any, any>> }): Store<number>;

export function inFlight(_: { domain: Domain }): Store<number>;
4 changes: 1 addition & 3 deletions in-flight/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ function inFlight({ effects, domain }) {
const $inFlight = domain.createStore(0);

domain.onCreateEffect((fx) => {
$inFlight
.on(fx, (count) => count + 1)
.on(fx.finally, (count) => count - 1);
$inFlight.on(fx, (count) => count + 1).on(fx.finally, (count) => count - 1);
});

return $inFlight;
Expand Down
5 changes: 1 addition & 4 deletions integration/custom/babel.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@ module.exports = {
presets: [
['@babel/preset-env', { targets: { node: 'current' } }],
'@babel/preset-typescript',
[
'@effector/patronum/babel-preset',
{ importModuleName: '@effector/patronum' },
],
['@effector/patronum/babel-preset', { importModuleName: '@effector/patronum' }],
],
plugins: [
[
Expand Down
10 changes: 2 additions & 8 deletions macro.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,7 @@ function patronum({
references,
state,
babel,
config: {
importModuleName = 'patronum',
importFromRoot = false,
...options
} = {},
config: { importModuleName = 'patronum', importFromRoot = false, ...options } = {},
}) {
const program = state.file.path;

Expand All @@ -32,9 +28,7 @@ function patronum({

const instance = babelPlugin(babel, {
...options,
factories: factories.map((name) =>
name.replace('patronum', importModuleName),
),
factories: factories.map((name) => name.replace('patronum', importModuleName)),
noDefaults: true,
});

Expand Down
5 changes: 1 addition & 4 deletions pending/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,4 @@ export function pending(config: {
effects: Array<Effect<any, any, any>>;
of?: Strategy;
}): Store<boolean>;
export function pending(config: {
domain: Domain;
of?: Strategy;
}): Store<boolean>;
export function pending(config: { domain: Domain; of?: Strategy }): Store<boolean>;
16 changes: 6 additions & 10 deletions pending/pending.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,11 +206,9 @@ describe('effects', () => {
`);

await waitFor(
combine(
effect2.inFlight,
effect1.inFlight,
(a, b) => a + b,
).updates.filter({ fn: (c) => c === 0 }),
combine(effect2.inFlight, effect1.inFlight, (a, b) => a + b).updates.filter({
fn: (c) => c === 0,
}),
);
expect(argumentHistory(fn)).toMatchInlineSnapshot(`
Array [
Expand Down Expand Up @@ -411,11 +409,9 @@ describe('domain', () => {
`);

await waitFor(
combine(
effect2.inFlight,
effect1.inFlight,
(a, b) => a + b,
).updates.filter({ fn: (c) => c === 0 }),
combine(effect2.inFlight, effect1.inFlight, (a, b) => a + b).updates.filter({
fn: (c) => c === 0,
}),
);
expect(argumentHistory(fn)).toMatchInlineSnapshot(`
Array [
Expand Down
5 changes: 1 addition & 4 deletions some/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,4 @@ export function some<T extends string>(_: {
stores: Array<Store<T>>;
}): Store<boolean>;

export function some<T>(_: {
predicate: T;
stores: Array<Store<T>>;
}): Store<boolean>;
export function some<T>(_: { predicate: T; stores: Array<Store<T>> }): Store<boolean>;
4 changes: 1 addition & 3 deletions some/index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
const { combine } = require('effector');

function some({ predicate, stores }) {
const checker = isFunction(predicate)
? predicate
: (value) => value === predicate;
const checker = isFunction(predicate) ? predicate : (value) => value === predicate;

return combine(stores, (values) => values.some(checker));
}
Expand Down
8 changes: 2 additions & 6 deletions some/some.fork.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,7 @@ test('throttle do not affect another forks', async () => {
const app = createDomain();
const change = app.createEvent<number>();
const $first = app.createStore(0);
const $second = app
.createStore(0)
.on(change, (state, payload) => state + payload);
const $second = app.createStore(0).on(change, (state, payload) => state + payload);
const $third = app.createStore(0);

const _$result = some({
Expand Down Expand Up @@ -85,9 +83,7 @@ test('throttle do not affect original store value', async () => {
const app = createDomain();
const change = app.createEvent<number>();
const $first = app.createStore(0);
const $second = app
.createStore(0)
.on(change, (state, payload) => state + payload);
const $second = app.createStore(0).on(change, (state, payload) => state + payload);
const $third = app.createStore(0);

const $result = some({
Expand Down
6 changes: 2 additions & 4 deletions split-map/split-map.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,10 +156,8 @@ test('from readme', () => {
const received = splitMap({
source: serverActionReceived,
cases: {
update: (action) =>
action.type === 'update' ? action.content : undefined,
created: (action) =>
action.type === 'created' ? action.value : undefined,
update: (action) => (action.type === 'update' ? action.content : undefined),
created: (action) => (action.type === 'created' ? action.value : undefined),
},
});

Expand Down
4 changes: 1 addition & 3 deletions test-typings/debounce.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,7 @@ import { debounce } from '../debounce';
expectType<Store<number>>(
debounce({ source, target, timeout: 10, name: undefined }),
);
expectType<Store<number>>(
debounce({ source, target, timeout: 10, name: 'demo' }),
);
expectType<Store<number>>(debounce({ source, target, timeout: 10, name: 'demo' }));

// @ts-expect-error
debounce({ source, target, timeout: 10, name: null });
Expand Down
4 changes: 1 addition & 3 deletions test-typings/pending.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@ import { pending } from '../pending';
const fx3 = createEffect<string, number>();

expectType<Store<boolean>>(pending({ effects: [fx1, fx2, fx3], of: 'some' }));
expectType<Store<boolean>>(
pending({ effects: [fx1, fx2, fx3], of: 'every' }),
);
expectType<Store<boolean>>(pending({ effects: [fx1, fx2, fx3], of: 'every' }));
}

// Fails on invalid units
Expand Down
4 changes: 1 addition & 3 deletions test-typings/some.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@ import { some } from '../some';
const value: Enum = 'c';

expectType<Store<boolean>>(some({ predicate: value, stores: [$a, $b] }));
expectType<Store<boolean>>(
some({ predicate: (b) => b === 'b', stores: [$a, $b] }),
);
expectType<Store<boolean>>(some({ predicate: (b) => b === 'b', stores: [$a, $b] }));

// @ts-expect-error
some({ predicate: value, stores: [$a, $invalid] });
Expand Down
4 changes: 1 addition & 3 deletions test-typings/status.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ import { status, EffectState } from '../status';

// Check that accepts only effect
{
expectType<Store<EffectState>>(
status({ effect: createEffect<number, string>() }),
);
expectType<Store<EffectState>>(status({ effect: createEffect<number, string>() }));

// @ts-expect-error
status({ effect: createEvent() });
Expand Down
4 changes: 1 addition & 3 deletions test-typings/throttle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,7 @@ import { throttle } from '../throttle';
expectType<Store<number>>(
throttle({ source, target, timeout: 10, name: undefined }),
);
expectType<Store<number>>(
throttle({ source, target, timeout: 10, name: 'demo' }),
);
expectType<Store<number>>(throttle({ source, target, timeout: 10, name: 'demo' }));

// @ts-expect-error
throttle({ source, target, timeout: 10, name: null });
Expand Down
Loading

0 comments on commit 6714233

Please sign in to comment.