vivth 0.9.4 → 0.11.0
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 +21 -46
- package/dev/index.mjs +2 -0
- package/index.mjs +8 -8
- package/package.json +1 -1
- package/src/class/$.mjs +39 -29
- package/src/class/Derived.mjs +27 -11
- package/src/class/PingFIFO.mjs +78 -0
- package/src/class/PingUnique.mjs +84 -0
- package/src/class/Q.mjs +22 -12
- package/src/class/Signal.mjs +31 -23
- package/src/function/NewQBlock.mjs +39 -0
- package/src/function/{tryAsync.export.mjs → TryAsync.mjs} +1 -1
- package/src/function/{trySync.export.mjs → TrySync.mjs} +1 -1
- package/src/types/{anyButUndefined.type.mjs → AnyButUndefined.type.mjs} +1 -1
- package/tsconfig.json +1 -1
- package/types/index.d.mts +6 -8
- package/types/src/class/$.d.mts +26 -13
- package/types/src/class/Derived.d.mts +18 -4
- package/types/src/class/PingFIFO.d.mts +57 -0
- package/types/src/class/PingUnique.d.mts +48 -0
- package/types/src/class/Q.d.mts +12 -5
- package/types/src/class/Signal.d.mts +15 -14
- package/types/src/function/NewQBlock.d.mts +1 -0
- package/types/src/function/{tryAsync.export.d.mts → TryAsync.d.mts} +1 -1
- package/types/src/function/TrySync.d.mts +1 -0
- package/types/src/types/AnyButUndefined.type.d.mts +1 -0
- package/src/function/New$.mjs +0 -28
- package/src/function/NewDerived.mjs +0 -28
- package/src/function/NewPingFIFO.mjs +0 -91
- package/src/function/NewPingUnique.mjs +0 -92
- package/src/function/NewSignal.mjs +0 -28
- package/types/src/function/New$.d.mts +0 -2
- package/types/src/function/NewDerived.d.mts +0 -2
- package/types/src/function/NewPingFIFO.d.mts +0 -1
- package/types/src/function/NewPingUnique.d.mts +0 -1
- package/types/src/function/NewSignal.d.mts +0 -2
- package/types/src/function/trySync.export.d.mts +0 -1
- package/types/src/types/anyButUndefined.type.d.mts +0 -1
package/src/class/Signal.mjs
CHANGED
|
@@ -5,33 +5,43 @@ import { $ } from './$.mjs';
|
|
|
5
5
|
/**
|
|
6
6
|
* @description
|
|
7
7
|
* - a class for creating signal;
|
|
8
|
-
*
|
|
9
|
-
*
|
|
8
|
+
* ```js
|
|
9
|
+
* import { $, Derived, Signal } from 'vivth';
|
|
10
|
+
* const signal = new Signal(0);
|
|
11
|
+
* const derived = new Derived(async () =>{
|
|
12
|
+
* // runs everytime signal.value changes;
|
|
13
|
+
* return signal.value * 2;
|
|
14
|
+
* });
|
|
15
|
+
* const autosubscriber = new $(async ()=>{
|
|
16
|
+
* // runs everytime signal.value changes;
|
|
17
|
+
* console.log(signal.value);
|
|
18
|
+
* });
|
|
19
|
+
* signal.value = 1;
|
|
20
|
+
* ```
|
|
10
21
|
*/
|
|
11
22
|
/**
|
|
12
23
|
* @template Value
|
|
13
24
|
*/
|
|
14
25
|
export class Signal {
|
|
15
26
|
/**
|
|
16
|
-
* subscribed
|
|
17
27
|
* @protected
|
|
18
28
|
*/
|
|
19
|
-
get
|
|
20
|
-
return $.
|
|
29
|
+
get subscribed() {
|
|
30
|
+
return $.mappedSignals.get(this);
|
|
21
31
|
}
|
|
22
32
|
/**
|
|
23
33
|
* destroy all props
|
|
24
34
|
*/
|
|
25
35
|
unRef = () => {
|
|
26
36
|
this.removeAll$();
|
|
27
|
-
this
|
|
37
|
+
this.#Value = null;
|
|
28
38
|
};
|
|
29
39
|
/**
|
|
30
40
|
* remove all effects
|
|
31
41
|
* @return {void}
|
|
32
42
|
*/
|
|
33
43
|
removeAll$ = () => {
|
|
34
|
-
this.
|
|
44
|
+
this.subscribed?.forEach(($_) => {
|
|
35
45
|
$_.remove$();
|
|
36
46
|
});
|
|
37
47
|
};
|
|
@@ -41,7 +51,7 @@ export class Signal {
|
|
|
41
51
|
* @return {void}
|
|
42
52
|
*/
|
|
43
53
|
remove$ = ($_) => {
|
|
44
|
-
if ($.
|
|
54
|
+
if ($.effects.get($_)?.has(this)) {
|
|
45
55
|
$_.remove$();
|
|
46
56
|
}
|
|
47
57
|
};
|
|
@@ -49,54 +59,52 @@ export class Signal {
|
|
|
49
59
|
* @param {Value} value
|
|
50
60
|
*/
|
|
51
61
|
constructor(value) {
|
|
52
|
-
this
|
|
62
|
+
this.#Value = value;
|
|
53
63
|
}
|
|
54
64
|
/**
|
|
55
|
-
* @private
|
|
56
65
|
* @type {Value}
|
|
57
66
|
*/
|
|
58
|
-
|
|
67
|
+
#prev = undefined;
|
|
59
68
|
get prev() {
|
|
60
|
-
return this
|
|
69
|
+
return this.#prev;
|
|
61
70
|
}
|
|
62
71
|
/**
|
|
63
|
-
* @private
|
|
64
72
|
* @type {Value}
|
|
65
73
|
*/
|
|
66
|
-
|
|
74
|
+
#Value;
|
|
67
75
|
/**
|
|
68
76
|
* @type {Value}
|
|
69
77
|
*/
|
|
70
78
|
get nonReactiveValue() {
|
|
71
|
-
return this
|
|
79
|
+
return this.#Value;
|
|
72
80
|
}
|
|
73
81
|
/**
|
|
74
82
|
* @type {Value}
|
|
75
83
|
*/
|
|
76
84
|
get value() {
|
|
77
|
-
if ($.
|
|
78
|
-
$.
|
|
85
|
+
if ($.isRegistering) {
|
|
86
|
+
$.activeSignal.add(this);
|
|
79
87
|
}
|
|
80
|
-
return this
|
|
88
|
+
return this.#Value;
|
|
81
89
|
}
|
|
82
90
|
/**
|
|
83
91
|
* @type {Value}
|
|
84
92
|
*/
|
|
85
93
|
set value(newValue) {
|
|
86
|
-
if (this
|
|
94
|
+
if (this.#Value === newValue) {
|
|
87
95
|
return;
|
|
88
96
|
}
|
|
89
|
-
this
|
|
90
|
-
this
|
|
97
|
+
this.#prev = this.#Value;
|
|
98
|
+
this.#Value = newValue;
|
|
91
99
|
this.call$();
|
|
92
100
|
}
|
|
93
101
|
/**
|
|
94
102
|
* @returns {void}
|
|
95
103
|
*/
|
|
96
104
|
call$ = () => {
|
|
97
|
-
if (!this.
|
|
105
|
+
if (!this.subscribed) {
|
|
98
106
|
return;
|
|
99
107
|
}
|
|
100
|
-
this.
|
|
108
|
+
this.subscribed.forEach(($_) => $_.effect({ remove$: $_.remove$ }));
|
|
101
109
|
};
|
|
102
110
|
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
|
|
3
|
+
import { Q } from '../class/Q.mjs';
|
|
4
|
+
import { TryAsync } from './TryAsync.mjs';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* @description
|
|
8
|
+
* - a function for Queue;
|
|
9
|
+
* - will wait next execution of the same `arg1`:`objectReferenceID`, without blocking other calls;
|
|
10
|
+
* ```js
|
|
11
|
+
* // @ts-check
|
|
12
|
+
* import { NewQBlock } from 'vivth';
|
|
13
|
+
* const objectReferenceID = 'yourUniqueID'; // can be anything, reference to object is preferable;
|
|
14
|
+
* const handler = () =>{
|
|
15
|
+
* NewQBlock(async () => {
|
|
16
|
+
* // your code
|
|
17
|
+
* }, objectReferenceID //- default, will refer to `arg0`:`asyncCallaback`;
|
|
18
|
+
* );
|
|
19
|
+
* }
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
/**
|
|
23
|
+
* will wait next execution of the same `arg1`:`objectReferenceID`, without blocking other calls;
|
|
24
|
+
* @param {()=>Promise<void>} asyncCallaback
|
|
25
|
+
* @param {any} [objectReferenceID]
|
|
26
|
+
* - default, will refer to `arg0`:`asyncCallaback`;
|
|
27
|
+
*/
|
|
28
|
+
export const NewQBlock = (asyncCallaback, objectReferenceID = undefined) => {
|
|
29
|
+
TryAsync(async () => {
|
|
30
|
+
const { resume } = await Q.unique(objectReferenceID ?? asyncCallaback);
|
|
31
|
+
await asyncCallaback();
|
|
32
|
+
resume();
|
|
33
|
+
}).then(([_, error]) => {
|
|
34
|
+
if (!error) {
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
console.error(error);
|
|
38
|
+
});
|
|
39
|
+
};
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
* @param {()=>Promise<ResultType>} asyncFunction_
|
|
11
11
|
* @returns {Promise<[ResultType|undefined, Error|undefined]>}
|
|
12
12
|
*/
|
|
13
|
-
export const
|
|
13
|
+
export const TryAsync = async (asyncFunction_) => {
|
|
14
14
|
try {
|
|
15
15
|
const result = await asyncFunction_();
|
|
16
16
|
return [result, undefined];
|
package/tsconfig.json
CHANGED
package/types/index.d.mts
CHANGED
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
export { $ } from "./src/class/$.mjs";
|
|
2
2
|
export { Derived } from "./src/class/Derived.mjs";
|
|
3
|
+
export { PingFIFO } from "./src/class/PingFIFO.mjs";
|
|
4
|
+
export { PingUnique } from "./src/class/PingUnique.mjs";
|
|
3
5
|
export { Q } from "./src/class/Q.mjs";
|
|
4
6
|
export { Signal } from "./src/class/Signal.mjs";
|
|
5
|
-
export {
|
|
6
|
-
export {
|
|
7
|
-
export {
|
|
8
|
-
export
|
|
9
|
-
export { NewSignal } from "./src/function/NewSignal.mjs";
|
|
10
|
-
export { tryAsync } from "./src/function/tryAsync.export.mjs";
|
|
11
|
-
export { trySync } from "./src/function/trySync.export.mjs";
|
|
12
|
-
export type anyButUndefined = {} | null | number | string | boolean | symbol | bigint | Function;
|
|
7
|
+
export { NewQBlock } from "./src/function/NewQBlock.mjs";
|
|
8
|
+
export { TryAsync } from "./src/function/TryAsync.mjs";
|
|
9
|
+
export { TrySync } from "./src/function/TrySync.mjs";
|
|
10
|
+
export type AnyButUndefined = {} | null | number | string | boolean | symbol | bigint | Function;
|
package/types/src/class/$.d.mts
CHANGED
|
@@ -1,42 +1,55 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @description
|
|
3
3
|
* - a class to `autosubscribe` to an signal changes (`Derived` and `Signal` alike);
|
|
4
|
-
*
|
|
4
|
+
* ```js
|
|
5
|
+
* import { $, Derived, Signal } from 'vivth';
|
|
6
|
+
* const signal = new Signal(0);
|
|
7
|
+
* const derived = new Derived(async () =>{
|
|
8
|
+
* // runs everytime signal.value changes;
|
|
9
|
+
* return signal.value * 2;
|
|
10
|
+
* });
|
|
11
|
+
* const autosubscriber = new $(async ()=>{
|
|
12
|
+
* // runs everytime signal.value changes;
|
|
13
|
+
* console.log(signal.value);
|
|
14
|
+
* // console.log(derived.value);
|
|
15
|
+
* });
|
|
16
|
+
* signal.value = 1;
|
|
17
|
+
* ```
|
|
5
18
|
*/
|
|
6
19
|
export class $ {
|
|
7
20
|
/**
|
|
8
21
|
* @typedef {import('../class/Signal.mjs').Signal} Signal
|
|
9
22
|
*/
|
|
10
23
|
/**
|
|
11
|
-
* effects
|
|
12
24
|
* @type {Map<$, Set<Signal>>}
|
|
13
25
|
*/
|
|
14
|
-
static
|
|
26
|
+
static effects: Map<$, Set<import("../class/Signal.mjs").Signal<any>>>;
|
|
15
27
|
/**
|
|
16
|
-
* signalInstance
|
|
17
28
|
* @type {Map<Signal, Set<$>>}
|
|
18
29
|
*/
|
|
19
|
-
static
|
|
30
|
+
static mappedSignals: Map<import("../class/Signal.mjs").Signal<any>, Set<$>>;
|
|
20
31
|
/**
|
|
21
|
-
* activeSignalUponRegistering
|
|
22
32
|
* @type {Set<Signal>}
|
|
23
33
|
*/
|
|
24
|
-
static
|
|
34
|
+
static activeSignal: Set<import("../class/Signal.mjs").Signal<any>>;
|
|
25
35
|
/**
|
|
26
|
-
* isRegistering
|
|
27
36
|
* @type {boolean}
|
|
28
37
|
*/
|
|
29
|
-
static
|
|
38
|
+
static isRegistering: boolean;
|
|
30
39
|
/**
|
|
31
|
-
* @param {
|
|
40
|
+
* @param {(arg:{remove$:$["remove$"]})=>void} effect
|
|
32
41
|
*/
|
|
33
|
-
constructor(effect:
|
|
42
|
+
constructor(effect: (arg: {
|
|
43
|
+
remove$: $["remove$"];
|
|
44
|
+
}) => void);
|
|
34
45
|
/**
|
|
35
46
|
* @returns {void}
|
|
36
47
|
*/
|
|
37
48
|
remove$: () => void;
|
|
38
49
|
/**
|
|
39
|
-
* @type {()=>void}
|
|
50
|
+
* @type {(arg:{remove$:$["remove$"]})=>void};
|
|
40
51
|
*/
|
|
41
|
-
effect: (
|
|
52
|
+
effect: (arg: {
|
|
53
|
+
remove$: $["remove$"];
|
|
54
|
+
}) => void;
|
|
42
55
|
}
|
|
@@ -1,8 +1,19 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @description
|
|
3
3
|
* - a class for creating signal which its value are derived from other signal (`Derived` and `Signal` alike);
|
|
4
|
-
*
|
|
5
|
-
*
|
|
4
|
+
* ```js
|
|
5
|
+
* import { $, Derived, Signal } from 'vivth';
|
|
6
|
+
* const signal = new Signal(0);
|
|
7
|
+
* const derived = new Derived(async () =>{
|
|
8
|
+
* // runs everytime signal.value changes;
|
|
9
|
+
* return signal.value * 2;
|
|
10
|
+
* });
|
|
11
|
+
* const autosubscriber = new $(async ()=>{
|
|
12
|
+
* // runs everytime derived.value changes;
|
|
13
|
+
* console.log(derived.value);
|
|
14
|
+
* });
|
|
15
|
+
* signal.value = 1;
|
|
16
|
+
* ```
|
|
6
17
|
*/
|
|
7
18
|
/**
|
|
8
19
|
* @template V
|
|
@@ -10,8 +21,11 @@
|
|
|
10
21
|
*/
|
|
11
22
|
export class Derived<V> extends Signal<V> {
|
|
12
23
|
/**
|
|
13
|
-
* @param {()=>V} derivedFunction
|
|
24
|
+
* @param {(arg:{remove$:$["remove$"]})=>V} derivedFunction
|
|
14
25
|
*/
|
|
15
|
-
constructor(derivedFunction: (
|
|
26
|
+
constructor(derivedFunction: (arg: {
|
|
27
|
+
remove$: $["remove$"];
|
|
28
|
+
}) => V);
|
|
16
29
|
}
|
|
17
30
|
import { Signal } from './Signal.mjs';
|
|
31
|
+
import { $ } from './$.mjs';
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @description
|
|
3
|
+
* ```js
|
|
4
|
+
* /**
|
|
5
|
+
* * @typedef {[callback:()=>(any|Promise<any>),debounce?:(number)]} queueFIFODetails
|
|
6
|
+
* *[blank]/
|
|
7
|
+
* ```
|
|
8
|
+
* - a class for Queue;
|
|
9
|
+
* - function to auto queue callbacks that will be called `first in first out` style;
|
|
10
|
+
* ```js
|
|
11
|
+
* // @ts-check
|
|
12
|
+
* import { PingFIFO } from 'vivth';
|
|
13
|
+
* const debounceMS = 0; // in miliseconds, optionals, default is 0;
|
|
14
|
+
* const handler = () =>{
|
|
15
|
+
* new PingFIFO(async () => {
|
|
16
|
+
* // your code
|
|
17
|
+
* }, debounceMS);
|
|
18
|
+
* }
|
|
19
|
+
* ```
|
|
20
|
+
* - this class provides `QFIFO.makeQClass`;
|
|
21
|
+
* >- this method will setup `QFIFO` to use the inputed `queueArray`(as arg0) as centralized lookup for queue managed by `QFIFO`;
|
|
22
|
+
* >- usefull to modify this class for browser runtime, since `vivth` cannot just refer to window, you can just add `window["someobject"]`: `Array<queueFIFODetails>` as lookups;
|
|
23
|
+
*/
|
|
24
|
+
export class PingFIFO {
|
|
25
|
+
/**
|
|
26
|
+
* @param {queueFIFODetails[]} queueArray
|
|
27
|
+
* @returns {typeof PingFIFO}
|
|
28
|
+
*/
|
|
29
|
+
static makeQClass: (queueArray: queueFIFODetails[]) => typeof PingFIFO;
|
|
30
|
+
/**
|
|
31
|
+
* @type {queueFIFODetails[]}
|
|
32
|
+
*/
|
|
33
|
+
static "__#3@#queue": queueFIFODetails[];
|
|
34
|
+
/**
|
|
35
|
+
* @type {boolean}
|
|
36
|
+
*/
|
|
37
|
+
static "__#3@#isRunning": boolean;
|
|
38
|
+
/**
|
|
39
|
+
* @param {queueFIFODetails} _queue
|
|
40
|
+
*/
|
|
41
|
+
static "__#3@#push": (_queue: queueFIFODetails) => void;
|
|
42
|
+
static "__#3@#run": () => Promise<void>;
|
|
43
|
+
/**
|
|
44
|
+
* @param {()=>(any|Promise<any>)} callback
|
|
45
|
+
* @param {number} [debounce]
|
|
46
|
+
*/
|
|
47
|
+
constructor(callback: () => (any | Promise<any>), debounce?: number);
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* *[blank]/
|
|
51
|
+
* ```
|
|
52
|
+
* - a class for Queue;
|
|
53
|
+
* - function to auto queue callbacks that will be called `first in first out` style;
|
|
54
|
+
* ```js
|
|
55
|
+
* //
|
|
56
|
+
*/
|
|
57
|
+
export type queueFIFODetails = [callback: () => (any | Promise<any>), debounce?: (number)];
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @description
|
|
3
|
+
* - a class for Queue;
|
|
4
|
+
* > - different `uniqueID`: called `first in first out` style;
|
|
5
|
+
* > - same `uniqueID`: will be grouped, only the already running callback and the last callback will be called;
|
|
6
|
+
* ```js
|
|
7
|
+
* // @ts-check
|
|
8
|
+
* import { PingUnique } from 'vivth';
|
|
9
|
+
* const uniqueID = 'yourUniqueID'; // can be anything, even a reference to an object;
|
|
10
|
+
* const debounceMS = 0; // in miliseconds, optionals, default is 0;
|
|
11
|
+
* const handler = () =>{
|
|
12
|
+
* new PingUnique(uniqueID, async () => {
|
|
13
|
+
* // your code
|
|
14
|
+
* }, debounceMS);
|
|
15
|
+
* }
|
|
16
|
+
* ```
|
|
17
|
+
* - this class provides `QUnique.makeQClass`;
|
|
18
|
+
* >- this method will setup `QUnique` to use the inputed `queueMap`(as arg0) as centralized lookup for queue managed by `QUnique`;
|
|
19
|
+
* >- usefull to modify this class for browser runtime, since `vivth` cannot just refer to window, you can just add `window["someobject"]`: `Map<any, [()=>Promise<any>,number]>` as lookups;
|
|
20
|
+
*/
|
|
21
|
+
export class PingUnique {
|
|
22
|
+
/**
|
|
23
|
+
* @param {Map<any, [()=>Promise<void>,number]>} queueMap
|
|
24
|
+
* @returns {typeof PingUnique}
|
|
25
|
+
*/
|
|
26
|
+
static makeQClass: (queueMap: Map<any, [() => Promise<void>, number]>) => typeof PingUnique;
|
|
27
|
+
/**
|
|
28
|
+
* @type {Map<any, [()=>Promise<void>,number]>}
|
|
29
|
+
*/
|
|
30
|
+
static "__#4@#queue": Map<any, [() => Promise<void>, number]>;
|
|
31
|
+
/**
|
|
32
|
+
* @type {boolean}
|
|
33
|
+
*/
|
|
34
|
+
static "__#4@#isRunning": boolean;
|
|
35
|
+
/**
|
|
36
|
+
* @param {any} id
|
|
37
|
+
* @param {()=>Promise<void>} callback
|
|
38
|
+
* @param {number} debounceMS
|
|
39
|
+
*/
|
|
40
|
+
static "__#4@#push": (id: any, callback: () => Promise<void>, debounceMS: number) => void;
|
|
41
|
+
static "__#4@#run": () => Promise<void>;
|
|
42
|
+
/**
|
|
43
|
+
* @param {any} id
|
|
44
|
+
* @param {()=>Promise<void>} callback
|
|
45
|
+
* @param {number} [debounceMS]
|
|
46
|
+
*/
|
|
47
|
+
constructor(id: any, callback: () => Promise<void>, debounceMS?: number);
|
|
48
|
+
}
|
package/types/src/class/Q.d.mts
CHANGED
|
@@ -23,16 +23,23 @@
|
|
|
23
23
|
* - behaviour:
|
|
24
24
|
* > - `fifo`: call all queued callback `first in first out` style;
|
|
25
25
|
* > - `unique`: call all queued callback with the same `uniqueID` `first in first out` style, if the `uniqueID` is different it will be called in parallel;
|
|
26
|
+
* - this class provides `Q.makeQClass`;
|
|
27
|
+
* >- this method will setup `Q` to use the inputed `uniqueMap`(as arg0) as centralized lookup for queue managed by `Q`;
|
|
28
|
+
* >- usefull to modify this class for browser runtime, since `vivth` cannot just refer to window, you can just add `window["someobject"]`: `Array<Map<any, Promise<any>>>` as lookups;
|
|
26
29
|
*/
|
|
27
30
|
export class Q {
|
|
28
31
|
/**
|
|
29
|
-
* @
|
|
32
|
+
* @param {Map<any, Promise<any>>} uniqueMap
|
|
33
|
+
* @returns {typeof Q}
|
|
34
|
+
*/
|
|
35
|
+
static makeQClass: (uniqueMap: Map<any, Promise<any>>) => typeof Q;
|
|
36
|
+
/**
|
|
37
|
+
* @typedef {import('../types/AnyButUndefined.type.mjs').AnyButUndefined} anyButUndefined
|
|
30
38
|
*/
|
|
31
39
|
/**
|
|
32
|
-
* @private
|
|
33
40
|
* @type {Promise<void>}
|
|
34
41
|
*/
|
|
35
|
-
|
|
42
|
+
static "__#1@#fifo": Promise<void>;
|
|
36
43
|
/**
|
|
37
44
|
* Blocks execution for subsequent calls until the current one finishes.
|
|
38
45
|
* @returns {Promise<{resume:()=>void}>} Resolves when it's safe to proceed, returning a cleanup function
|
|
@@ -43,14 +50,14 @@ export class Q {
|
|
|
43
50
|
/**
|
|
44
51
|
* @type {Map<any, Promise<any>>}
|
|
45
52
|
*/
|
|
46
|
-
static
|
|
53
|
+
static "__#1@#unique": Map<any, Promise<any>>;
|
|
47
54
|
/**
|
|
48
55
|
* Ensures that each id has only one task running at a time.
|
|
49
56
|
* Calls with the same id will wait for the previous call to finish.
|
|
50
57
|
* @param {anyButUndefined} id
|
|
51
58
|
* @returns {Promise<{resume:()=>void}>} Resolves when it's safe to proceed for the given id, returning a cleanup function
|
|
52
59
|
*/
|
|
53
|
-
static unique: (id: import("../types/
|
|
60
|
+
static unique: (id: import("../types/AnyButUndefined.type.mjs").AnyButUndefined) => Promise<{
|
|
54
61
|
resume: () => void;
|
|
55
62
|
}>;
|
|
56
63
|
}
|
|
@@ -1,8 +1,19 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @description
|
|
3
3
|
* - a class for creating signal;
|
|
4
|
-
*
|
|
5
|
-
*
|
|
4
|
+
* ```js
|
|
5
|
+
* import { $, Derived, Signal } from 'vivth';
|
|
6
|
+
* const signal = new Signal(0);
|
|
7
|
+
* const derived = new Derived(async () =>{
|
|
8
|
+
* // runs everytime signal.value changes;
|
|
9
|
+
* return signal.value * 2;
|
|
10
|
+
* });
|
|
11
|
+
* const autosubscriber = new $(async ()=>{
|
|
12
|
+
* // runs everytime signal.value changes;
|
|
13
|
+
* console.log(signal.value);
|
|
14
|
+
* });
|
|
15
|
+
* signal.value = 1;
|
|
16
|
+
* ```
|
|
6
17
|
*/
|
|
7
18
|
/**
|
|
8
19
|
* @template Value
|
|
@@ -13,19 +24,13 @@ export class Signal<Value> {
|
|
|
13
24
|
*/
|
|
14
25
|
constructor(value: Value);
|
|
15
26
|
/**
|
|
16
|
-
* subscribed
|
|
17
27
|
* @protected
|
|
18
28
|
*/
|
|
19
|
-
protected get
|
|
29
|
+
protected get subscribed(): Set<$>;
|
|
20
30
|
/**
|
|
21
31
|
* destroy all props
|
|
22
32
|
*/
|
|
23
33
|
unRef: () => void;
|
|
24
|
-
/**
|
|
25
|
-
* @private
|
|
26
|
-
* @type {Value}
|
|
27
|
-
*/
|
|
28
|
-
private V;
|
|
29
34
|
/**
|
|
30
35
|
* remove all effects
|
|
31
36
|
* @return {void}
|
|
@@ -37,11 +42,6 @@ export class Signal<Value> {
|
|
|
37
42
|
* @return {void}
|
|
38
43
|
*/
|
|
39
44
|
remove$: ($_: $) => void;
|
|
40
|
-
/**
|
|
41
|
-
* @private
|
|
42
|
-
* @type {Value}
|
|
43
|
-
*/
|
|
44
|
-
private P;
|
|
45
45
|
get prev(): Value;
|
|
46
46
|
/**
|
|
47
47
|
* @type {Value}
|
|
@@ -59,5 +59,6 @@ export class Signal<Value> {
|
|
|
59
59
|
* @returns {void}
|
|
60
60
|
*/
|
|
61
61
|
call$: () => void;
|
|
62
|
+
#private;
|
|
62
63
|
}
|
|
63
64
|
import { $ } from './$.mjs';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export function NewQBlock(asyncCallaback: () => Promise<void>, objectReferenceID?: any): void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export function
|
|
1
|
+
export function TryAsync<ResultType>(asyncFunction_: () => Promise<ResultType>): Promise<[ResultType | undefined, Error | undefined]>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export function TrySync<ResultType>(function_: () => ResultType): [ResultType | undefined, Error | undefined];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type AnyButUndefined = {} | null | number | string | boolean | symbol | bigint | Function;
|
package/src/function/New$.mjs
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
// @ts-check
|
|
2
|
-
|
|
3
|
-
import { $ } from '../class/$.mjs';
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* @description
|
|
7
|
-
* - function to create `autosubscriber`;
|
|
8
|
-
* - syntatic sugar for [$](#$);
|
|
9
|
-
* ```js
|
|
10
|
-
* import { New$, NewDerived, NewSignal } from 'vivth';
|
|
11
|
-
* const signal = NewSignal(0);
|
|
12
|
-
* const derived = NewDerived(async () =>{
|
|
13
|
-
* // runs everytime signal.value changes;
|
|
14
|
-
* return signal.value * 2;
|
|
15
|
-
* });
|
|
16
|
-
* const autosubscriber = New$(async ()=>{
|
|
17
|
-
* // runs everytime signal.value changes;
|
|
18
|
-
* console.log(signal.value);
|
|
19
|
-
* // console.log(derived.value);
|
|
20
|
-
* });
|
|
21
|
-
* signal.value = 1;
|
|
22
|
-
* ```
|
|
23
|
-
*/
|
|
24
|
-
/**
|
|
25
|
-
* @param {()=>void} effect subscriber
|
|
26
|
-
* @returns {$} instance of `$`
|
|
27
|
-
*/
|
|
28
|
-
export const New$ = (effect) => new $(effect);
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
// @ts-check
|
|
2
|
-
|
|
3
|
-
import { Derived } from '../class/Derived.mjs';
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* @description
|
|
7
|
-
* - function to create `signal` that its value are derived from another `signal`;
|
|
8
|
-
* - syntatic sugar for [Derived](#derived);
|
|
9
|
-
* ```js
|
|
10
|
-
* import { New$, NewDerived, NewSignal } from 'vivth';
|
|
11
|
-
* const signal = NewSignal(0);
|
|
12
|
-
* const derived = NewDerived(async () =>{
|
|
13
|
-
* // runs everytime signal.value changes;
|
|
14
|
-
* return signal.value * 2;
|
|
15
|
-
* });
|
|
16
|
-
* const autosubscriber = New$(async ()=>{
|
|
17
|
-
* // runs everytime derived.value changes;
|
|
18
|
-
* console.log(derived.value);
|
|
19
|
-
* });
|
|
20
|
-
* signal.value = 1;
|
|
21
|
-
* ```
|
|
22
|
-
*/
|
|
23
|
-
/**
|
|
24
|
-
* @template V
|
|
25
|
-
* @param {()=>(V)} derivedFunction
|
|
26
|
-
* @returns {Derived<V>}
|
|
27
|
-
*/
|
|
28
|
-
export const NewDerived = (derivedFunction) => new Derived(derivedFunction);
|