New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

patronum

Package Overview
Dependencies
Maintainers
1
Versions
98
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

patronum - npm Package Compare versions

Comparing version 0.14.0 to 0.100.0

5

package.json
{
"name": "patronum",
"version": "0.14.0",
"version": "0.100.0",
"description": "☄️ Effector utility library delivering modularity and convenience",

@@ -62,5 +62,4 @@ "main": "index.js",

"dependencies": {
"effector-debounce": "^1.1.0",
"effector-throttle": "^1.1.0"
"effector-debounce": "^1.1.0"
}
}

17

README.md

@@ -1,2 +0,2 @@

# effecto patronum ✨
# ☄️ effecto patronum ✨

@@ -15,3 +15,5 @@ [![Commitizen friendly](https://img.shields.io/badge/commitizen-friendly-brightgreen.svg)](http://commitizen.github.io/cz-cli/) [![Conventional Commits](https://img.shields.io/badge/Conventional%20Commits-1.0.0-yellow.svg)](https://conventionalcommits.org) [![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg)](http://prettier.io) ![Node.js CI](https://github.com/sergeysova/patronum/workflows/Node.js%20CI/badge.svg)

- [Every](#every)
- [Reshape](#reshape)
- [Some](#some)
- [SplitMap](#splitmap)
- [Spread](#spread)

@@ -21,7 +23,2 @@ - [Status](#status)

---
- [Reshape](#reshape)
- [SplitMap](#splitmap)
## Usage

@@ -114,3 +111,3 @@

const target = throttle(trigger, 200);
const target = throttle({ source: trigger, timeout: 200 });

@@ -239,8 +236,4 @@ target.watch((payload) => console.info('throttled', payload));

---
## [Reshape](/reshape 'Documentation')
> No tests yet
```ts

@@ -265,4 +258,2 @@ import { createStore } from 'effector';

> No tests yet
```ts

@@ -269,0 +260,0 @@ import { createEvent } from 'effector';

@@ -1,3 +0,13 @@

import { createThrottle } from 'effector-throttle';
import { Unit, Event } from 'effector';
export const throttle = createThrottle;
export function throttle<T>(_: {
source: Unit<T>;
timeout: number;
name?: string;
}): Event<T>;
export function throttle<T, R extends Unit<T>>(_: {
source: Unit<T>;
timeout: number;
target: R;
name?: string;
}): R;

@@ -1,5 +0,51 @@

const { createThrottle } = require('effector-throttle');
const { createEffect, createEvent, guard, is, sample } = require('effector');
const { readConfig } = require('../library');
module.exports = {
throttle: createThrottle,
};
function throttle(argument) {
const { source, timeout, target, sid, loc, name } = readConfig(argument, [
'source',
'timeout',
'target',
'loc',
'name',
'sid',
]);
if (!is.unit(source))
throw new TypeError('callee must be unit from effector');
if (typeof timeout !== 'number' || timeout < 0)
throw new Error('timeout must be positive number or zero');
const actualName = name || source.shortName || 'unknown';
const tick =
target ||
createEvent({
name: `${actualName}ThrottleTick`,
loc,
});
const timerFx = createEffect({
name: `${actualName}ThrottleTimer`,
sid,
loc,
handler: () => new Promise((resolve) => setTimeout(resolve, timeout)),
});
guard({
source,
filter: timerFx.pending.map((pending) => !pending),
target: timerFx,
});
sample({
source,
clock: timerFx.done,
target: tick,
});
return tick;
}
module.exports = { throttle };

@@ -7,6 +7,23 @@ # Patronum/Throttle

## Example
## `throttle({ source, timeout })`
### Formulae
```ts
result = throttle({ source, timeout });
```
### Usage
Create event that should be throttled:
```ts
import { createEvent } from 'effector';
const someHappened = createEvent<number>();
```
Create throttled event from it:
```ts
import { throttle } from 'patronum/throttle';

@@ -16,5 +33,11 @@

const someHappened = createEvent<number>();
const throttled = createThrottle(someHappened, THROTTLE_TIMEOUT_IN_MS);
const throttled = throttle({
source: someHappened,
timeout: THROTTLE_TIMEOUT_IN_MS,
});
```
When you call `someHappened` it will make throttled call the `throttled` event:
```ts
throttled.watch((payload) => {

@@ -28,2 +51,49 @@ console.info('someHappened now', payload);

someHappened(4);
// after 200 ms after first call
// => someHappened now 4
```
Also you can use `Effect` and `Store` as trigger. `throttle` always returns `Event`:
```ts
const event = createEvent<number>();
const throttledEvent: Event<number> = throttle({ source: event, timeout: 100 });
const fx = createEffect<number, void>();
const throttledEffect: Event<number> = throttle({ source: fx, timeout: 100 });
const $store = createStore<number>(0);
const throttledStore: Event<number> = throttle({
source: $store,
timeout: 100,
});
```
## `throttle({ source, timeout, target })`
### Formulae
```ts
throttle({ source, timeout, target });
```
### Usage
```ts
const change = createEvent();
const $source = createStore(0).on(change, (state) => state + 1);
const $dumped = createStore(0);
$dumped.watch((payload) => {
localStorage.setItem('dump', JSON.stringify(payload));
});
throttle({ source: $source, timeout: 40, target: $dumped });
change();
change();
change();
// after 40ms after first call, 3 will be saved to localStorage
```
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc