Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/sergeysova/effector-throttle
Simple throttle for effector events
https://github.com/sergeysova/effector-throttle
effector throttle
Last synced: 3 months ago
JSON representation
Simple throttle for effector events
- Host: GitHub
- URL: https://github.com/sergeysova/effector-throttle
- Owner: sergeysova
- Archived: true
- Created: 2020-02-17T17:41:12.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2020-06-13T14:44:55.000Z (over 4 years ago)
- Last Synced: 2024-02-11T15:55:01.692Z (9 months ago)
- Topics: effector, throttle
- Language: TypeScript
- Homepage: https://npmjs.com/effector-throttle
- Size: 209 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Effector Throttle
[![npm bundle size](https://img.shields.io/bundlephobia/min/effector-throttle)](https://bundlephobia.com/result?p=effector-throttle)
> **Deprecated**: use [patronum](https://github.com/sergeysova/patronum) instead
https://codesandbox.io/s/effector-throttle-debounce-w32tk
## Installation
```bash
npm install --save effector effector-throttle# or
yarn add effector effector-throttle
```## Usage
Create event that should be throttled:
```ts
import { createEvent } from 'effector';const someHappened = createEvent();
```Create throttled event from it:
```ts
import { createThrottle } from 'effector-throttle';const THROTTLE_TIMEOUT_IN_MS = 200;
const throttled = createThrottle(someHappened, THROTTLE_TIMEOUT_IN_MS);
```When you call `someHappened` it will throttle call to `throttled` event:
```ts
throttled.watch((payload) => {
console.info('someHappened now', payload);
});someHappened(1);
someHappened(2);
someHappened(3);
someHappened(4);
```Also you can use `Effect` and `Store` as trigger. `createThrottle` always returns `Event`:
```ts
const event = createEvent();
const debouncedEvent: Event = createThrottle(event, 100);const fx = createEffect();
const debouncedEffect: Event = createThrottle(fx, 100);const $store = createStore(0);
const debouncedStore: Event = createThrottle($store, 100);
```### Change name
```ts
const trigger = createEvent();
const throttled = createThrottle(trigger, 100);// Now throttled var has `triggerThrottleTick` name
```To change name:
```ts
const trigger = createEvent();
const throttled = createThrottle(trigger, 100, { name: 'Hello' });// Now throttled var has `HelloThrottleTick` name
```