Skip to content

Commit

Permalink
feat(throttle): introduce throttle
Browse files Browse the repository at this point in the history
  • Loading branch information
Sergey Sova committed Apr 23, 2020
1 parent 82a4ae4 commit be72e8e
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 4 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,16 +60,16 @@ trigger(4);
// => debounced 4
```

## Throttle
## [🧁 Throttle](/throttle 'Documentation')

```ts
import { createEvent } from 'effector';
import { createThrottle } from 'patronum/throttle';
import { throttle } from 'patronum/throttle';

// You should call this event
const trigger = createEvent<number>();

const target = createThrottle(trigger, 200);
const target = throttle(trigger, 200);

target.watch((payload) => console.info('throttled', payload));

Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
}
},
"dependencies": {
"effector-debounce": "^1.1.0"
"effector-debounce": "^1.1.0",
"effector-throttle": "^1.1.0"
}
}
3 changes: 3 additions & 0 deletions throttle/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { createThrottle } from 'effector-throttle';

export const throttle = createThrottle;
5 changes: 5 additions & 0 deletions throttle/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const { createThrottle } = require('effector-throttle');

module.exports = {
throttle: createThrottle,
};
26 changes: 26 additions & 0 deletions throttle/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Patronum/Throttle

```ts
import { throttle } from 'patronum/throttle';
```

## Example

```ts
import { createEvent } from 'effector';
import { throttle } from 'patronum/throttle';

const THROTTLE_TIMEOUT_IN_MS = 200;

const someHappened = createEvent<number>();
const throttled = createThrottle(someHappened, THROTTLE_TIMEOUT_IN_MS);

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

someHappened(1);
someHappened(2);
someHappened(3);
someHappened(4);
```
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1821,6 +1821,11 @@ effector-debounce@^1.1.0:
resolved "https://registry.yarnpkg.com/effector-debounce/-/effector-debounce-1.1.0.tgz#e6aa74efd302d480f57b2e945e71ab34772ba360"
integrity sha512-UfJLUQx2fIjNIGx9kmPvmCjClInXvJP+jmREpVMamLQkEoMw3PqdnzoLUqFPJQI/tXGD9LQ1OYrL9eANVpIAtg==

effector-throttle@^1.1.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/effector-throttle/-/effector-throttle-1.1.0.tgz#8d3b4b7c24ed60be746fdfdfc2bf627f0c9f6983"
integrity sha512-hkFwr8W6QZMnvxb8XIqwFyQQCT4kwzHV2eaoVCGfRSixwPs0GrTcZIrXTg03pTHRLXn+4x2owRD/OXoAfTQTYQ==

effector@^20.7.0:
version "20.14.0"
resolved "https://registry.yarnpkg.com/effector/-/effector-20.14.0.tgz#890ca40f2a7cf9041e6f22b7baf8c4273042dbcb"
Expand Down

0 comments on commit be72e8e

Please sign in to comment.