@fbltd/async 1.0.31 → 1.0.32
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +14 -1
- package/dist/bin/debounce.js +16 -0
- package/dist/bin/dependency/dep.factory.js +1 -1
- package/dist/bin/dependency/index.js +2 -2
- package/dist/bin/dependency/{integrations/react → react}/reactive/index.js +1 -1
- package/dist/bin/dependency/{integrations/react → react}/reactive/utils.js +1 -1
- package/dist/bin/dependency/{integrations/react → react}/use-race-stream/race-stream.controller.js +1 -1
- package/dist/types/debounce.d.ts +5 -0
- package/dist/types/dependency/index.d.ts +2 -2
- package/dist/types/dependency/react/reactive/utils.d.ts +2 -0
- package/dist/types/dependency/{integrations/react → react}/use-race-stream/race-stream.controller.d.ts +1 -1
- package/dist/types/dependency/{integrations/react → react}/use-race-stream/use-race.stream.d.ts +1 -1
- package/package.json +1 -1
- package/dist/bin/dependency/integrations/index.js +0 -1
- package/dist/types/dependency/integrations/index.d.ts +0 -1
- package/dist/types/dependency/integrations/react/reactive/utils.d.ts +0 -2
- /package/dist/bin/dependency/{integrations/react → react}/index.js +0 -0
- /package/dist/bin/dependency/{integrations/react → react}/use-race-stream/index.js +0 -0
- /package/dist/bin/dependency/{integrations/react → react}/use-race-stream/use-race.stream.js +0 -0
- /package/dist/bin/dependency/{integrations/react → react}/utils.js +0 -0
- /package/dist/bin/dependency/{stream-utils → vanilla}/contracts.js +0 -0
- /package/dist/bin/dependency/{stream-utils → vanilla}/get.stream.js +0 -0
- /package/dist/bin/dependency/{stream-utils → vanilla}/index.js +0 -0
- /package/dist/bin/dependency/{stream-utils → vanilla}/next.js +0 -0
- /package/dist/bin/dependency/{stream-utils → vanilla}/once.stream.js +0 -0
- /package/dist/bin/dependency/{stream-utils → vanilla}/race.stream.js +0 -0
- /package/dist/bin/dependency/{stream-utils → vanilla}/reaction/index.js +0 -0
- /package/dist/bin/dependency/{stream-utils → vanilla}/reaction/reaction.js +0 -0
- /package/dist/bin/dependency/{stream-utils → vanilla}/reaction/utils.js +0 -0
- /package/dist/types/dependency/{integrations/react → react}/index.d.ts +0 -0
- /package/dist/types/dependency/{integrations/react → react}/reactive/index.d.ts +0 -0
- /package/dist/types/dependency/{integrations/react → react}/use-race-stream/index.d.ts +0 -0
- /package/dist/types/dependency/{integrations/react → react}/utils.d.ts +0 -0
- /package/dist/types/dependency/{stream-utils → vanilla}/contracts.d.ts +0 -0
- /package/dist/types/dependency/{stream-utils → vanilla}/get.stream.d.ts +0 -0
- /package/dist/types/dependency/{stream-utils → vanilla}/index.d.ts +0 -0
- /package/dist/types/dependency/{stream-utils → vanilla}/next.d.ts +0 -0
- /package/dist/types/dependency/{stream-utils → vanilla}/once.stream.d.ts +0 -0
- /package/dist/types/dependency/{stream-utils → vanilla}/race.stream.d.ts +0 -0
- /package/dist/types/dependency/{stream-utils → vanilla}/reaction/index.d.ts +0 -0
- /package/dist/types/dependency/{stream-utils → vanilla}/reaction/reaction.d.ts +0 -0
- /package/dist/types/dependency/{stream-utils → vanilla}/reaction/utils.d.ts +0 -0
package/README.md
CHANGED
|
@@ -19,6 +19,19 @@ await delay(number);
|
|
|
19
19
|
delay(number, 'sync');
|
|
20
20
|
```
|
|
21
21
|
|
|
22
|
+
### debounce
|
|
23
|
+
debounce is a function that passed function after waiting for the passed time
|
|
24
|
+
without another function calls
|
|
25
|
+
```typescript
|
|
26
|
+
const myFunc = () => console.log('debounced running');
|
|
27
|
+
const debounced = debounce(myFunc, 100);
|
|
28
|
+
|
|
29
|
+
debounced();
|
|
30
|
+
debounced();
|
|
31
|
+
// after 100ms there will be only one console.log
|
|
32
|
+
// debounced running
|
|
33
|
+
```
|
|
34
|
+
|
|
22
35
|
### PromiseConfiguration
|
|
23
36
|
PromiseConfiguration is a class that creates and provide promise,
|
|
24
37
|
its fulfillment functions and status flags.
|
|
@@ -133,7 +146,7 @@ export const Counter: React.FC<ICounter> = React.memo(({
|
|
|
133
146
|
})
|
|
134
147
|
```
|
|
135
148
|
|
|
136
|
-
Or you can use
|
|
149
|
+
Or you can use Reactive HOC:
|
|
137
150
|
```typescript jsx
|
|
138
151
|
type ICounter = {
|
|
139
152
|
dependecy: Dependency,
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export function debounce(fn, ms = 0) {
|
|
2
|
+
let id;
|
|
3
|
+
function cancelPrevious() {
|
|
4
|
+
id !== void 0 && clearTimeout(id);
|
|
5
|
+
}
|
|
6
|
+
ms = Math.max(ms, 0);
|
|
7
|
+
const functionToReturn = ((...args) => {
|
|
8
|
+
cancelPrevious?.();
|
|
9
|
+
id = setTimeout(() => {
|
|
10
|
+
fn(...args);
|
|
11
|
+
id = undefined;
|
|
12
|
+
}, ms);
|
|
13
|
+
});
|
|
14
|
+
functionToReturn.dispose = cancelPrevious;
|
|
15
|
+
return functionToReturn;
|
|
16
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export * from "./dependency.js";
|
|
2
2
|
export * from "./dependency.stream.js";
|
|
3
3
|
export * from "./dep.factory.js";
|
|
4
|
-
export * from "./
|
|
5
|
-
export * from "./
|
|
4
|
+
export * from "./vanilla/index.js";
|
|
5
|
+
export * from "./react/index.js";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React, { useEffect, useState } from "react";
|
|
2
|
-
import { observationState } from "
|
|
2
|
+
import { observationState } from "../../observe.state.js";
|
|
3
3
|
import { usePromise } from "./utils.js";
|
|
4
4
|
export function Reactive(fn) {
|
|
5
5
|
return React.memo((props) => {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { useState } from "react";
|
|
2
|
-
import { PromiseConfiguration } from "
|
|
2
|
+
import { PromiseConfiguration } from "../../../promise-configuration.js";
|
|
3
3
|
export function usePromise() {
|
|
4
4
|
const [promise] = useState(() => new PromiseConfiguration());
|
|
5
5
|
return promise;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export interface IDebounce<TReturn extends any, TArgs extends Array<any>> {
|
|
2
|
+
(...args: TArgs): TReturn;
|
|
3
|
+
dispose(): void;
|
|
4
|
+
}
|
|
5
|
+
export declare function debounce<TReturn extends any, TArgs extends Array<any>>(fn: (...args: TArgs) => TReturn, ms?: number): IDebounce<TReturn, TArgs>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export * from './dependency.ts';
|
|
2
2
|
export * from './dependency.stream.ts';
|
|
3
3
|
export * from './dep.factory.ts';
|
|
4
|
-
export * from './
|
|
5
|
-
export * from './
|
|
4
|
+
export * from './vanilla/index.ts';
|
|
5
|
+
export * from './react/index.ts';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Dispatch, SetStateAction } from "react";
|
|
2
|
-
import { IDepObjectArgument, IDepObjectReturn, raceStream } from "
|
|
2
|
+
import { IDepObjectArgument, IDepObjectReturn, raceStream } from "../../vanilla/index.ts";
|
|
3
3
|
export declare class RaceStreamController<T extends IDepObjectArgument> {
|
|
4
4
|
private _value;
|
|
5
5
|
private isFirstWas;
|
package/dist/types/dependency/{integrations/react → react}/use-race-stream/use-race.stream.d.ts
RENAMED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { IDepObjectArgument, IDepObjectReturn } from "
|
|
1
|
+
import { IDepObjectArgument, IDepObjectReturn } from "../../index.ts";
|
|
2
2
|
export declare function useRaceStream<T extends IDepObjectArgument>(deps: T): {
|
|
3
3
|
value: IDepObjectReturn<T>;
|
|
4
4
|
dispose: Function;
|
package/package.json
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "./react/index.js";
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './react/index.ts';
|
|
File without changes
|
|
File without changes
|
/package/dist/bin/dependency/{integrations/react → react}/use-race-stream/use-race.stream.js
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|