@fbltd/async 1.0.21 → 1.0.23
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/dist/bin/{dependency-stream → dependency}/dependency.js +2 -0
- package/dist/bin/dependency/global.js +24 -0
- package/dist/bin/{dependency-stream → dependency}/stream-utils/index.js +1 -0
- package/dist/bin/dependency/stream-utils/reaction.js +21 -0
- package/dist/bin/index.js +2 -2
- package/dist/types/dependency/global.d.ts +11 -0
- package/dist/types/{dependency-stream → dependency}/stream-utils/index.d.ts +1 -0
- package/dist/types/dependency/stream-utils/reaction.d.ts +11 -0
- package/dist/types/index.d.ts +2 -2
- package/package.json +4 -4
- /package/dist/bin/{dependency-stream → dependency}/contracts.js +0 -0
- /package/dist/bin/{dependency-stream → dependency}/dependency.stream.js +0 -0
- /package/dist/bin/{dependency-stream → dependency}/index.js +0 -0
- /package/dist/bin/{dependency-stream → dependency}/integrations/index.js +0 -0
- /package/dist/bin/{dependency-stream → dependency}/integrations/react/index.js +0 -0
- /package/dist/bin/{dependency-stream → dependency}/integrations/react/race-stream.controller.js +0 -0
- /package/dist/bin/{dependency-stream → dependency}/integrations/react/use-race.stream.js +0 -0
- /package/dist/bin/{dependency-stream → dependency}/integrations/react/utils.js +0 -0
- /package/dist/bin/{dependency-stream → dependency}/stream-utils/contracts.js +0 -0
- /package/dist/bin/{dependency-stream → dependency}/stream-utils/next.js +0 -0
- /package/dist/bin/{dependency-stream → dependency}/stream-utils/once.stream.js +0 -0
- /package/dist/bin/{dependency-stream → dependency}/stream-utils/race.stream.js +0 -0
- /package/dist/bin/{dependency-stream → dependency}/utils.js +0 -0
- /package/dist/types/{dependency-stream → dependency}/contracts.d.ts +0 -0
- /package/dist/types/{dependency-stream → dependency}/dependency.d.ts +0 -0
- /package/dist/types/{dependency-stream → dependency}/dependency.stream.d.ts +0 -0
- /package/dist/types/{dependency-stream → dependency}/index.d.ts +0 -0
- /package/dist/types/{dependency-stream → dependency}/integrations/index.d.ts +0 -0
- /package/dist/types/{dependency-stream → dependency}/integrations/react/index.d.ts +0 -0
- /package/dist/types/{dependency-stream → dependency}/integrations/react/race-stream.controller.d.ts +0 -0
- /package/dist/types/{dependency-stream → dependency}/integrations/react/use-race.stream.d.ts +0 -0
- /package/dist/types/{dependency-stream → dependency}/integrations/react/utils.d.ts +0 -0
- /package/dist/types/{dependency-stream → dependency}/stream-utils/contracts.d.ts +0 -0
- /package/dist/types/{dependency-stream → dependency}/stream-utils/next.d.ts +0 -0
- /package/dist/types/{dependency-stream → dependency}/stream-utils/once.stream.d.ts +0 -0
- /package/dist/types/{dependency-stream → dependency}/stream-utils/race.stream.d.ts +0 -0
- /package/dist/types/{dependency-stream → dependency}/utils.d.ts +0 -0
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { PromiseConfiguration } from "../promise-configuration.js";
|
|
2
2
|
import { DependencyStream } from "./dependency.stream.js";
|
|
3
3
|
import { baseComparer } from "./utils.js";
|
|
4
|
+
import { setDep } from "./global.js";
|
|
4
5
|
export class Dependency {
|
|
5
6
|
_value;
|
|
6
7
|
reactionPromise;
|
|
@@ -28,6 +29,7 @@ export class Dependency {
|
|
|
28
29
|
this._set(v);
|
|
29
30
|
}
|
|
30
31
|
get value() {
|
|
32
|
+
setDep(this);
|
|
31
33
|
return this._value;
|
|
32
34
|
}
|
|
33
35
|
getStream() {
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
const global = {
|
|
2
|
+
watchFlag: false,
|
|
3
|
+
dependencies: null
|
|
4
|
+
};
|
|
5
|
+
const notImplemented = new Error('Watching while watching is not implemented');
|
|
6
|
+
export function watchDeps(fn) {
|
|
7
|
+
if (global.watchFlag) {
|
|
8
|
+
throw notImplemented;
|
|
9
|
+
}
|
|
10
|
+
global.watchFlag = true;
|
|
11
|
+
global.dependencies = new Set();
|
|
12
|
+
let result = fn();
|
|
13
|
+
let deps = global.dependencies;
|
|
14
|
+
global.dependencies = null;
|
|
15
|
+
global.watchFlag = false;
|
|
16
|
+
return {
|
|
17
|
+
result, deps
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
export function setDep(dep) {
|
|
21
|
+
if (!global.watchFlag)
|
|
22
|
+
return;
|
|
23
|
+
global.dependencies.add(dep);
|
|
24
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { watchDeps } from "../global.js";
|
|
2
|
+
import { symAI } from "../../constants.js";
|
|
3
|
+
/**
|
|
4
|
+
* @deprecated
|
|
5
|
+
*/
|
|
6
|
+
export function reaction(fn) {
|
|
7
|
+
return {
|
|
8
|
+
[Symbol.asyncIterator]: () => {
|
|
9
|
+
let { result, deps } = watchDeps(fn);
|
|
10
|
+
return {
|
|
11
|
+
next: async () => {
|
|
12
|
+
const dependencies = Array.from(deps);
|
|
13
|
+
const streams = dependencies.map(dep => dep[symAI]());
|
|
14
|
+
await Promise.race(streams.map(s => s.next()));
|
|
15
|
+
({ result, deps } = watchDeps(fn));
|
|
16
|
+
return { done: false, value: result };
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
}
|
package/dist/bin/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export * from "./dependency
|
|
2
|
-
export * from "./dependency
|
|
1
|
+
export * from "./dependency/index.js";
|
|
2
|
+
export * from "./dependency/integrations/react/index.js";
|
|
3
3
|
export * from "./delay.js";
|
|
4
4
|
export * from "./promise-configuration.js";
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Dependency } from "./dependency.js";
|
|
2
|
+
declare const global: {
|
|
3
|
+
watchFlag: boolean;
|
|
4
|
+
dependencies: Set<Dependency>;
|
|
5
|
+
};
|
|
6
|
+
export declare function watchDeps<T>(fn: () => T): {
|
|
7
|
+
result: T;
|
|
8
|
+
deps: typeof global.dependencies;
|
|
9
|
+
};
|
|
10
|
+
export declare function setDep(dep: Dependency): void;
|
|
11
|
+
export {};
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export * from './dependency
|
|
2
|
-
export * from './dependency
|
|
1
|
+
export * from './dependency/index.ts';
|
|
2
|
+
export * from './dependency/integrations/react/index.ts';
|
|
3
3
|
export * from './delay.ts';
|
|
4
4
|
export * from './promise-configuration.ts';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fbltd/async",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.23",
|
|
4
4
|
"description": "Miscellaneous async utils",
|
|
5
5
|
"homepage": "https://github.com/GlennMiller1991/async",
|
|
6
6
|
"type": "module",
|
|
@@ -21,8 +21,8 @@
|
|
|
21
21
|
"tsconfig.json"
|
|
22
22
|
],
|
|
23
23
|
"scripts": {
|
|
24
|
-
"clearDist": "rm dist -
|
|
25
|
-
"clearModules": "rm node_modules -
|
|
24
|
+
"clearDist": "rm dist -r || true",
|
|
25
|
+
"clearModules": "rm node_modules -r || true",
|
|
26
26
|
"clearAll": "npm run clearDist && npm run clearModules",
|
|
27
27
|
"build": "npm run clearAll && npm i && mkdir dist && tsc",
|
|
28
28
|
"test": "node --expose-gc node_modules/.bin/jest --config=./__tests__/jest.config.cjs",
|
|
@@ -37,8 +37,8 @@
|
|
|
37
37
|
"react": "^19.x.x"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
|
-
"@types/react": "^19.x.x",
|
|
41
40
|
"@types/jest": "^30.0.0",
|
|
41
|
+
"@types/react": "^19.x.x",
|
|
42
42
|
"jest": "^30.0.4",
|
|
43
43
|
"ts-jest": "^29.4.0",
|
|
44
44
|
"typescript": "^5.x.x"
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
/package/dist/bin/{dependency-stream → dependency}/integrations/react/race-stream.controller.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
|
/package/dist/types/{dependency-stream → dependency}/integrations/react/race-stream.controller.d.ts
RENAMED
|
File without changes
|
/package/dist/types/{dependency-stream → dependency}/integrations/react/use-race.stream.d.ts
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|