Skip to content
Simple throttle for effector events
TypeScript JavaScript
Branch: master
Clone or download

Latest commit

Latest commit db84e32 Mar 24, 2020

Files

Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.github/workflows ci: add github action Mar 24, 2020
src
tests feat: derive name from trigger Mar 24, 2020
.babelrc
.commitlintrc.json
.editorconfig Initial commit Feb 17, 2020
.eslintignore
.eslintrc.json
.gitignore Initial commit Feb 17, 2020
.huskyrc
.prettierrc.json Initial commit Feb 17, 2020
README.md
jest.config.js feat: upgrade deps, add test framework Mar 24, 2020
package.json 1.1.0 Mar 24, 2020
rollup.config.js Initial commit Feb 17, 2020
tsconfig.json
yarn.lock test: add main tests Mar 24, 2020

README.md

Effector Throttle

npm bundle size

https://codesandbox.io/s/effector-throttle-debounce-w32tk

Installation

npm install --save effector effector-throttle

# or

yarn add effector effector-throttle

Usage

Create event that should be throttled:

import { createEvent } from 'effector';

const someHappened = createEvent<number>();

Create throttled event from it:

import { createThrottle } from 'effector-throttle';

const THROTTLE_TIMEOUT_IN_MS = 200;

const throttled = createThrottle(someHappened, THROTTLE_TIMEOUT_IN_MS);

To test that original event is correctly throttled you can add watcher:

someHappened.watch((payload) => {
  console.info('someHappened now', payload);
});

throttled(1);
throttled(2);
throttled(3);
throttled(4);

Also you can use Effect and Store as trigger. createThrottle always returns Event:

const event = createEvent<number>();
const debouncedEvent: Event<number> = createThrottle(event, 100);

const fx = createEffect<number, void>();
const debouncedEffect: Event<number> = createThrottle(fx, 100);

const $store = createStore<number>(0);
const debouncedStore: Event<number> = createThrottle($store, 100);

Change name

const trigger = createEvent();
const throttled = createThrottle(trigger, 100);

// Now throttled var has `triggerThrottleTick` name

To change name:

const trigger = createEvent();
const throttled = createThrottle(trigger, 100, { name: 'Hello' });

// Now throttled var has `HelloThrottleTick` name
You can’t perform that action at this time.