effecto patronum ✨
☄️ Effector utility library delivering modularity and convenience
import { createEvent } from 'effector';
import { condition } from 'patronum/condition';
const trigger = createEvent<string>();
const longString = createEvent<string>();
const shortString = createEvent<string>();
condition({
source: trigger,
if: (string) => string.length > 8,
then: longString,
else: shortString,
});
import { createEvent } from 'effector';
import { delay } from 'patronum/delay';
const trigger = createEvent<string>();
const delayed = delay(trigger, 300);
delayed.watch((payload) => console.info('triggered', payload));
trigger('hello');
⏺ Debounce
import { createEvent } from 'effector';
import { createDebounce } from 'patronum/debounce';
const trigger = createEvent<number>();
const target = createDebounce(trigger, 200);
target.watch((payload) => console.info('debounced', payload));
trigger(1);
trigger(2);
trigger(3);
trigger(4);
⏺ Throttle
import { createEvent } from 'effector';
import { createThrottle } from 'patronum/throttle';
const trigger = createEvent<number>();
const target = createThrottle(trigger, 200);
target.watch((payload) => console.info('throttled', payload));
trigger(1);
trigger(2);
trigger(3);
trigger(4);
⏺ Reshape
import { createStore } from 'effector';
import { reshape } from 'patronum/reshape';
const $original = createStore<string>('Hello world');
const parts = reshape($original, {
length: (string) => string.length,
first: (string) => string.split(' ')[0] || '',
second: (string) => string.split(' ')[1] || '',
});
parts.length.watch(console.info);
parts.first.watch(console.log);
parts.second.watch(console.log);
⏺ Spread
import { createEvent, createStore } from 'effector';
import { spread } from 'patronum/spread';
const trigger = createEvent<{ first: string; second: string }>();
const $first = createStore('');
const $second = createStore('');
spread(trigger, {
first: $first,
second: $second,
});
trigger({ first: 'Hello', second: 'World' });
$first.getState();
$second.getState();
⏺ SplitMap
import { createEvent } from 'effector';
import { splitMap } from 'patronum/splitmap';
const nameReceived = createEvent<string>();
const received = splitMap(nameReceived, {
firstName: (string) => string.split(' ')[0],
lastName: (string) => string.split(' ')[1],
});
received.firstName.watch((first) => console.info('firstname received', first));
received.lastName.watch((last) => console.info('lastname received', last));
nameReceived('Sergey');
nameReceived('Sergey Sova');