@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.
Files changed (42) hide show
  1. package/README.md +14 -1
  2. package/dist/bin/debounce.js +16 -0
  3. package/dist/bin/dependency/dep.factory.js +1 -1
  4. package/dist/bin/dependency/index.js +2 -2
  5. package/dist/bin/dependency/{integrations/react → react}/reactive/index.js +1 -1
  6. package/dist/bin/dependency/{integrations/react → react}/reactive/utils.js +1 -1
  7. package/dist/bin/dependency/{integrations/react → react}/use-race-stream/race-stream.controller.js +1 -1
  8. package/dist/types/debounce.d.ts +5 -0
  9. package/dist/types/dependency/index.d.ts +2 -2
  10. package/dist/types/dependency/react/reactive/utils.d.ts +2 -0
  11. package/dist/types/dependency/{integrations/react → react}/use-race-stream/race-stream.controller.d.ts +1 -1
  12. package/dist/types/dependency/{integrations/react → react}/use-race-stream/use-race.stream.d.ts +1 -1
  13. package/package.json +1 -1
  14. package/dist/bin/dependency/integrations/index.js +0 -1
  15. package/dist/types/dependency/integrations/index.d.ts +0 -1
  16. package/dist/types/dependency/integrations/react/reactive/utils.d.ts +0 -2
  17. /package/dist/bin/dependency/{integrations/react → react}/index.js +0 -0
  18. /package/dist/bin/dependency/{integrations/react → react}/use-race-stream/index.js +0 -0
  19. /package/dist/bin/dependency/{integrations/react → react}/use-race-stream/use-race.stream.js +0 -0
  20. /package/dist/bin/dependency/{integrations/react → react}/utils.js +0 -0
  21. /package/dist/bin/dependency/{stream-utils → vanilla}/contracts.js +0 -0
  22. /package/dist/bin/dependency/{stream-utils → vanilla}/get.stream.js +0 -0
  23. /package/dist/bin/dependency/{stream-utils → vanilla}/index.js +0 -0
  24. /package/dist/bin/dependency/{stream-utils → vanilla}/next.js +0 -0
  25. /package/dist/bin/dependency/{stream-utils → vanilla}/once.stream.js +0 -0
  26. /package/dist/bin/dependency/{stream-utils → vanilla}/race.stream.js +0 -0
  27. /package/dist/bin/dependency/{stream-utils → vanilla}/reaction/index.js +0 -0
  28. /package/dist/bin/dependency/{stream-utils → vanilla}/reaction/reaction.js +0 -0
  29. /package/dist/bin/dependency/{stream-utils → vanilla}/reaction/utils.js +0 -0
  30. /package/dist/types/dependency/{integrations/react → react}/index.d.ts +0 -0
  31. /package/dist/types/dependency/{integrations/react → react}/reactive/index.d.ts +0 -0
  32. /package/dist/types/dependency/{integrations/react → react}/use-race-stream/index.d.ts +0 -0
  33. /package/dist/types/dependency/{integrations/react → react}/utils.d.ts +0 -0
  34. /package/dist/types/dependency/{stream-utils → vanilla}/contracts.d.ts +0 -0
  35. /package/dist/types/dependency/{stream-utils → vanilla}/get.stream.d.ts +0 -0
  36. /package/dist/types/dependency/{stream-utils → vanilla}/index.d.ts +0 -0
  37. /package/dist/types/dependency/{stream-utils → vanilla}/next.d.ts +0 -0
  38. /package/dist/types/dependency/{stream-utils → vanilla}/once.stream.d.ts +0 -0
  39. /package/dist/types/dependency/{stream-utils → vanilla}/race.stream.d.ts +0 -0
  40. /package/dist/types/dependency/{stream-utils → vanilla}/reaction/index.d.ts +0 -0
  41. /package/dist/types/dependency/{stream-utils → vanilla}/reaction/reaction.d.ts +0 -0
  42. /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 Reaction HOC:
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
  import { Dependency } from "./dependency.js";
2
- import { reaction } from "./stream-utils/index.js";
2
+ import { reaction } from "./vanilla/index.js";
3
3
  export class DepFactory {
4
4
  static ofValue(value, config) {
5
5
  return new Dependency(value, config);
@@ -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 "./stream-utils/index.js";
5
- export * from "./integrations/index.js";
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 "../../../observe.state.js";
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 "../../../../promise-configuration.js";
2
+ import { PromiseConfiguration } from "../../../promise-configuration.js";
3
3
  export function usePromise() {
4
4
  const [promise] = useState(() => new PromiseConfiguration());
5
5
  return promise;
@@ -1,5 +1,5 @@
1
1
  import { isObjectsContentEqual } from "../utils.js";
2
- import { raceStream } from "../../../stream-utils/index.js";
2
+ import { raceStream } from "../../vanilla/index.js";
3
3
  export class RaceStreamController {
4
4
  _value;
5
5
  isFirstWas = false;
@@ -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 './stream-utils/index.ts';
5
- export * from './integrations/index.ts';
4
+ export * from './vanilla/index.ts';
5
+ export * from './react/index.ts';
@@ -0,0 +1,2 @@
1
+ import { PromiseConfiguration } from "../../../promise-configuration.ts";
2
+ export declare function usePromise<T = void>(): PromiseConfiguration<T>;
@@ -1,5 +1,5 @@
1
1
  import { Dispatch, SetStateAction } from "react";
2
- import { IDepObjectArgument, IDepObjectReturn, raceStream } from "../../../stream-utils/index.ts";
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;
@@ -1,4 +1,4 @@
1
- import { IDepObjectArgument, IDepObjectReturn } from "../../../index.ts";
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,6 +1,6 @@
1
1
  {
2
2
  "name": "@fbltd/async",
3
- "version": "1.0.31",
3
+ "version": "1.0.32",
4
4
  "description": "Miscellaneous async utils",
5
5
  "homepage": "https://github.com/GlennMiller1991/async",
6
6
  "type": "module",
@@ -1 +0,0 @@
1
- export * from "./react/index.js";
@@ -1 +0,0 @@
1
- export * from './react/index.ts';
@@ -1,2 +0,0 @@
1
- import { PromiseConfiguration } from "../../../../promise-configuration.ts";
2
- export declare function usePromise<T = void>(): PromiseConfiguration<T>;