@fbltd/async 1.0.13 → 1.0.15
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 +7 -7
- package/dist/bin/constants.js +1 -4
- package/dist/bin/delay.js +3 -6
- package/dist/bin/dependency-stream/contracts.js +1 -2
- package/dist/bin/dependency-stream/dependency-stream.js +6 -10
- package/dist/bin/dependency-stream/index.js +4 -20
- package/dist/bin/dependency-stream/integrations/index.js +1 -17
- package/dist/bin/dependency-stream/integrations/react/index.js +1 -1
- package/dist/bin/dependency-stream/integrations/react/src/index.js +1 -1
- package/dist/bin/dependency-stream/utils/index.js +3 -19
- package/dist/bin/dependency-stream/utils/next.js +4 -8
- package/dist/bin/dependency-stream/utils/once.stream.js +6 -9
- package/dist/bin/dependency-stream/utils/race.stream.js +6 -9
- package/dist/bin/get-promise.js +1 -4
- package/dist/bin/index.js +4 -20
- package/dist/types/dependency-stream/dependency-stream.d.ts +2 -2
- package/dist/types/dependency-stream/index.d.ts +4 -4
- package/dist/types/dependency-stream/integrations/index.d.ts +1 -1
- package/dist/types/dependency-stream/integrations/react/index.d.ts +1 -1
- package/dist/types/dependency-stream/integrations/react/src/index.d.ts +1 -1
- package/dist/types/dependency-stream/utils/index.d.ts +3 -3
- package/dist/types/dependency-stream/utils/next.d.ts +5 -1
- package/dist/types/dependency-stream/utils/once.stream.d.ts +2 -2
- package/dist/types/dependency-stream/utils/race.stream.d.ts +2 -2
- package/dist/types/index.d.ts +4 -4
- package/package.json +3 -2
- package/tsconfig.base.json +1 -0
- package/tsconfig.json +2 -3
package/README.md
CHANGED
|
@@ -1,4 +1,10 @@
|
|
|
1
1
|
# Async tools
|
|
2
|
+
R&D async tools tree-shakable ES module
|
|
3
|
+
|
|
4
|
+
## Installation
|
|
5
|
+
You can install this package with your favorite package manager.<br/>
|
|
6
|
+
Npm, for example, will be looks like:
|
|
7
|
+
```npm i @fbltd/async```
|
|
2
8
|
|
|
3
9
|
## Overview
|
|
4
10
|
|
|
@@ -99,10 +105,4 @@ export const Counter: React.FC<ITest> = React.memo(({
|
|
|
99
105
|
</div>
|
|
100
106
|
)
|
|
101
107
|
})
|
|
102
|
-
```
|
|
103
|
-
|
|
104
|
-
### Disclaimer
|
|
105
|
-
Now this package is CommonJS module but should be an ESM.
|
|
106
|
-
|
|
107
|
-
## Installation
|
|
108
|
-
Just type ```npm i @fbltd/async```
|
|
108
|
+
```
|
package/dist/bin/constants.js
CHANGED
package/dist/bin/delay.js
CHANGED
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.delay = delay;
|
|
4
|
-
const get_promise_1 = require("./get-promise");
|
|
5
|
-
function delay(ms = 0, syncKey) {
|
|
1
|
+
import { getPromise } from "./get-promise.js";
|
|
2
|
+
export function delay(ms = 0, syncKey) {
|
|
6
3
|
ms = Math.max(ms, 0);
|
|
7
4
|
return delay.methods[typeof syncKey](ms);
|
|
8
5
|
}
|
|
@@ -17,7 +14,7 @@ Object.defineProperty(delay, 'methods', {
|
|
|
17
14
|
}
|
|
18
15
|
},
|
|
19
16
|
undefined: (ms) => {
|
|
20
|
-
const { promise, resolve } =
|
|
17
|
+
const { promise, resolve } = getPromise();
|
|
21
18
|
setTimeout(() => {
|
|
22
19
|
resolve();
|
|
23
20
|
}, ms);
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
export {};
|
|
@@ -1,14 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.DependencyStream = void 0;
|
|
4
|
-
const get_promise_1 = require("../get-promise");
|
|
1
|
+
import { getPromise } from "../get-promise.js";
|
|
5
2
|
function baseComparer(prev, cur) {
|
|
6
3
|
return prev === cur;
|
|
7
4
|
}
|
|
8
|
-
class DependencyStream {
|
|
5
|
+
export class DependencyStream {
|
|
9
6
|
_value;
|
|
10
7
|
reactionPromise;
|
|
11
|
-
abortPromise =
|
|
8
|
+
abortPromise = getPromise();
|
|
12
9
|
config;
|
|
13
10
|
constructor(_value, config = {}) {
|
|
14
11
|
this._value = _value;
|
|
@@ -40,7 +37,7 @@ class DependencyStream {
|
|
|
40
37
|
let firstPromise;
|
|
41
38
|
const withReactionOnSubscribe = this.config.withReactionOnSubscribe || thisStreamConfig.withReactionOnSubscribe;
|
|
42
39
|
if (withReactionOnSubscribe) {
|
|
43
|
-
firstPromise =
|
|
40
|
+
firstPromise = getPromise();
|
|
44
41
|
firstPromise.resolve(this.value);
|
|
45
42
|
externalPromises.push(firstPromise.promise);
|
|
46
43
|
}
|
|
@@ -57,7 +54,7 @@ class DependencyStream {
|
|
|
57
54
|
},
|
|
58
55
|
next: async () => {
|
|
59
56
|
if (!this.reactionPromise) {
|
|
60
|
-
this.reactionPromise =
|
|
57
|
+
this.reactionPromise = getPromise();
|
|
61
58
|
this._set(this._value);
|
|
62
59
|
}
|
|
63
60
|
await Promise.race([
|
|
@@ -83,8 +80,7 @@ class DependencyStream {
|
|
|
83
80
|
}
|
|
84
81
|
dispose() {
|
|
85
82
|
this.abortPromise.resolve();
|
|
86
|
-
this.abortPromise =
|
|
83
|
+
this.abortPromise = getPromise();
|
|
87
84
|
this.reactionPromise = undefined;
|
|
88
85
|
}
|
|
89
86
|
}
|
|
90
|
-
exports.DependencyStream = DependencyStream;
|
|
@@ -1,20 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./dependency-stream"), exports);
|
|
18
|
-
__exportStar(require("./utils"), exports);
|
|
19
|
-
__exportStar(require("./integrations"), exports);
|
|
20
|
-
__exportStar(require("./contracts"), exports);
|
|
1
|
+
export * from "./dependency-stream.js";
|
|
2
|
+
export * from "./utils/index.js";
|
|
3
|
+
export * from "./integrations/index.js";
|
|
4
|
+
export * from "./contracts.js";
|
|
@@ -1,17 +1 @@
|
|
|
1
|
-
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./react"), exports);
|
|
1
|
+
export * from "./react/index.js";
|
|
@@ -14,4 +14,4 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./src"), exports);
|
|
17
|
+
__exportStar(require("./src/index.js"), exports);
|
|
@@ -14,4 +14,4 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./use-stream"), exports);
|
|
17
|
+
__exportStar(require("./use-stream.js"), exports);
|
|
@@ -1,19 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./once.stream"), exports);
|
|
18
|
-
__exportStar(require("./race.stream"), exports);
|
|
19
|
-
__exportStar(require("./next"), exports);
|
|
1
|
+
export * from "./once.stream.js";
|
|
2
|
+
export * from "./race.stream.js";
|
|
3
|
+
export * from "./next.js";
|
|
@@ -1,11 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.InternalStreamFinishError = void 0;
|
|
4
|
-
exports.next = next;
|
|
5
|
-
const constants_1 = require("../../constants");
|
|
1
|
+
import { symAI } from "../../constants.js";
|
|
6
2
|
const StreamFinishError = new Error("Stream is done");
|
|
7
|
-
async function next(dep) {
|
|
8
|
-
const res = await dep[
|
|
3
|
+
export async function next(dep) {
|
|
4
|
+
const res = await dep[symAI]().next();
|
|
9
5
|
if (res.done) {
|
|
10
6
|
throw StreamFinishError;
|
|
11
7
|
}
|
|
@@ -14,4 +10,4 @@ async function next(dep) {
|
|
|
14
10
|
/**
|
|
15
11
|
* @internal
|
|
16
12
|
*/
|
|
17
|
-
|
|
13
|
+
export const InternalStreamFinishError = StreamFinishError;
|
|
@@ -1,11 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
function onceStream(dep) {
|
|
7
|
-
const externalDispose = (0, get_promise_1.getPromise)();
|
|
8
|
-
const iterator = dep[constants_1.symAI]({ externalDispose });
|
|
1
|
+
import { getPromise } from "../../get-promise.js";
|
|
2
|
+
import { symAI } from "../../constants.js";
|
|
3
|
+
export function onceStream(dep) {
|
|
4
|
+
const externalDispose = getPromise();
|
|
5
|
+
const iterator = dep[symAI]({ externalDispose });
|
|
9
6
|
function isDisposed() {
|
|
10
7
|
return externalDispose.isFulfilled || iterator.isDisposed;
|
|
11
8
|
}
|
|
@@ -14,7 +11,7 @@ function onceStream(dep) {
|
|
|
14
11
|
return isDisposed();
|
|
15
12
|
},
|
|
16
13
|
dispose: externalDispose.resolve,
|
|
17
|
-
[
|
|
14
|
+
[symAI]() {
|
|
18
15
|
return {
|
|
19
16
|
next: async () => {
|
|
20
17
|
const result = await iterator.next();
|
|
@@ -1,12 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const get_promise_1 = require("../../get-promise");
|
|
6
|
-
function raceStream(...deps) {
|
|
7
|
-
let selfDisposePromise = (0, get_promise_1.getPromise)();
|
|
1
|
+
import { symAI } from "../../constants.js";
|
|
2
|
+
import { getPromise } from "../../get-promise.js";
|
|
3
|
+
export function raceStream(...deps) {
|
|
4
|
+
let selfDisposePromise = getPromise();
|
|
8
5
|
let isDisposed = false;
|
|
9
|
-
const streams = deps.map((dep) => dep[
|
|
6
|
+
const streams = deps.map((dep) => dep[symAI]({
|
|
10
7
|
externalDispose: selfDisposePromise
|
|
11
8
|
}));
|
|
12
9
|
return {
|
|
@@ -14,7 +11,7 @@ function raceStream(...deps) {
|
|
|
14
11
|
get isDisposed() {
|
|
15
12
|
return isDisposed;
|
|
16
13
|
},
|
|
17
|
-
[
|
|
14
|
+
[symAI]() {
|
|
18
15
|
return {
|
|
19
16
|
next: async () => {
|
|
20
17
|
const res = await Promise.race([selfDisposePromise.promise, ...streams.map(s => s.next())]);
|
package/dist/bin/get-promise.js
CHANGED
package/dist/bin/index.js
CHANGED
|
@@ -1,20 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./dependency-stream"), exports);
|
|
18
|
-
__exportStar(require("./dependency-stream/integrations/react"), exports);
|
|
19
|
-
__exportStar(require("./delay"), exports);
|
|
20
|
-
__exportStar(require("./get-promise"), exports);
|
|
1
|
+
export * from "./dependency-stream/index.js";
|
|
2
|
+
export * from "./dependency-stream/integrations/react/index.js";
|
|
3
|
+
export * from "./delay.js";
|
|
4
|
+
export * from "./get-promise.js";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { IPromiseConfiguration } from "../get-promise";
|
|
2
|
-
import { IIteratorOwner, IStreamIterator } from "./contracts";
|
|
1
|
+
import { IPromiseConfiguration } from "../get-promise.ts";
|
|
2
|
+
import { IIteratorOwner, IStreamIterator } from "./contracts.ts";
|
|
3
3
|
interface IIsEquals<T> {
|
|
4
4
|
(prev: T, cur: T): boolean;
|
|
5
5
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export * from './dependency-stream';
|
|
2
|
-
export * from './utils';
|
|
3
|
-
export * from './integrations';
|
|
4
|
-
export * from './contracts';
|
|
1
|
+
export * from './dependency-stream.ts';
|
|
2
|
+
export * from './utils/index.ts';
|
|
3
|
+
export * from './integrations/index.ts';
|
|
4
|
+
export * from './contracts.ts';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from './react';
|
|
1
|
+
export * from './react/index.ts';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from './src';
|
|
1
|
+
export * from './src/index.ts';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from './use-stream';
|
|
1
|
+
export * from './use-stream.ts';
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export * from "./once.stream";
|
|
2
|
-
export * from "./race.stream";
|
|
3
|
-
export * from "./next";
|
|
1
|
+
export * from "./once.stream.ts";
|
|
2
|
+
export * from "./race.stream.ts";
|
|
3
|
+
export * from "./next.ts";
|
|
@@ -1,2 +1,6 @@
|
|
|
1
|
-
import { DependencyStream } from "../dependency-stream";
|
|
1
|
+
import { DependencyStream } from "../dependency-stream.ts";
|
|
2
2
|
export declare function next<T>(dep: DependencyStream<T>): Promise<T>;
|
|
3
|
+
/**
|
|
4
|
+
* @internal
|
|
5
|
+
*/
|
|
6
|
+
export declare const InternalStreamFinishError: Error;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { DependencyStream } from "../dependency-stream";
|
|
2
|
-
import { IStreamOwner } from "../contracts";
|
|
1
|
+
import { DependencyStream } from "../dependency-stream.ts";
|
|
2
|
+
import { IStreamOwner } from "../contracts.ts";
|
|
3
3
|
export declare function onceStream<T>(dep: DependencyStream<T>): IStreamOwner<T>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { DependencyStream } from "../dependency-stream";
|
|
2
|
-
import { symAI } from "../../constants";
|
|
1
|
+
import { DependencyStream } from "../dependency-stream.ts";
|
|
2
|
+
import { symAI } from "../../constants.ts";
|
|
3
3
|
export declare function raceStream<TArray extends DependencyStream[]>(...deps: NoInfer<TArray>): {
|
|
4
4
|
dispose: () => void;
|
|
5
5
|
readonly isDisposed: boolean;
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export * from './dependency-stream';
|
|
2
|
-
export * from './dependency-stream/integrations/react';
|
|
3
|
-
export * from './delay';
|
|
4
|
-
export * from './get-promise';
|
|
1
|
+
export * from './dependency-stream/index.ts';
|
|
2
|
+
export * from './dependency-stream/integrations/react/index.ts';
|
|
3
|
+
export * from './delay.ts';
|
|
4
|
+
export * from './get-promise.ts';
|
package/package.json
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fbltd/async",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.15",
|
|
4
4
|
"description": "Miscellaneous async utils",
|
|
5
5
|
"homepage": "https://github.com/GlennMiller1991/async",
|
|
6
|
+
"type": "module",
|
|
6
7
|
"keywords": [
|
|
7
8
|
"Reactivity",
|
|
8
9
|
"State Management",
|
|
@@ -24,7 +25,7 @@
|
|
|
24
25
|
"clearModules": "rm node_modules -rf || true",
|
|
25
26
|
"clearAll": "npm run clearDist && npm run clearModules",
|
|
26
27
|
"build": "cd src/dependency-stream/integrations/react && npm run build && cd ../../../../ && npm run clearAll && npm i && mkdir dist && tsc",
|
|
27
|
-
"test": "jest --config=./__tests__/jest.config.
|
|
28
|
+
"test": "jest --config=./__tests__/jest.config.cjs",
|
|
28
29
|
"postVersionCommit": "git commit -m='post version commit' || true",
|
|
29
30
|
"postVersionPush": "git push || true",
|
|
30
31
|
"patch": "npm version patch && npm run postVersionCommit && npm run postVersionPush",
|
package/tsconfig.base.json
CHANGED