@fbltd/async 1.0.5 → 1.0.6

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.
@@ -2,14 +2,27 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.DependencyStream = void 0;
4
4
  const utils_1 = require("../utils");
5
+ function baseComparer(prev, cur) {
6
+ return prev === cur;
7
+ }
5
8
  class DependencyStream {
6
9
  _value;
7
10
  promiseConf;
8
11
  abortPromise = (0, utils_1.getPromise)();
9
- constructor(_value) {
12
+ config;
13
+ constructor(_value, config = {}) {
10
14
  this._value = _value;
15
+ this.config = {
16
+ isEqual: baseComparer,
17
+ ...config,
18
+ };
11
19
  }
12
- _set(v) {
20
+ _set(v, force) {
21
+ if (!force) {
22
+ if (this.config.isEqual(this._value, v)) {
23
+ return;
24
+ }
25
+ }
13
26
  if (v === this._value)
14
27
  return;
15
28
  this._value = v;
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.delay = delay;
4
4
  const get_promise_1 = require("./get-promise");
5
- function delay(ms) {
5
+ function delay(ms = 0) {
6
6
  ms = Math.max(ms, 0);
7
7
  const { promise, resolve } = (0, get_promise_1.getPromise)();
8
8
  setTimeout(() => {
@@ -1,8 +1,15 @@
1
+ interface ICompareFn<T> {
2
+ (prev: T, cur: T): boolean;
3
+ }
4
+ type IDependencyStreamConfig<T> = {
5
+ isEqual: ICompareFn<T>;
6
+ };
1
7
  export declare class DependencyStream<T = any> {
2
8
  private _value;
3
9
  private promiseConf;
4
10
  private abortPromise;
5
- constructor(_value: T);
11
+ private config;
12
+ constructor(_value: T, config?: Partial<IDependencyStreamConfig<T>>);
6
13
  private _set;
7
14
  set value(v: T);
8
15
  get value(): T;
@@ -19,3 +26,4 @@ export declare class DependencyStream<T = any> {
19
26
  };
20
27
  dispose(this: DependencyStream<T>): void;
21
28
  }
29
+ export {};
@@ -1 +1 @@
1
- export declare function delay(ms: number): Promise<void>;
1
+ export declare function delay(ms?: number): Promise<void>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fbltd/async",
3
- "version": "1.0.5",
3
+ "version": "1.0.6",
4
4
  "description": "R&D async tools",
5
5
  "exports": {
6
6
  "require": "./dist/bin/index.js",