vivth 0.11.0 → 0.11.2
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 +17 -15
- package/dev/index.mjs +0 -2
- package/index.mjs +2 -2
- package/package.json +1 -1
- package/src/class/$.mjs +13 -27
- package/src/class/Derived.mjs +6 -17
- package/src/class/QFIFO.mjs +66 -0
- package/src/class/QUnique.mjs +75 -0
- package/src/class/Signal.mjs +2 -13
- package/types/index.d.mts +2 -0
- package/types/src/class/$.d.mts +6 -21
- package/types/src/class/Derived.d.mts +5 -17
- package/types/src/class/PingFIFO.d.mts +4 -4
- package/types/src/class/PingUnique.d.mts +4 -4
- package/types/src/class/Q.d.mts +2 -2
- package/types/src/class/QFIFO.d.mts +47 -0
- package/types/src/class/QUnique.d.mts +46 -0
- package/types/src/class/Signal.d.mts +2 -13
package/README.md
CHANGED
|
@@ -14,27 +14,27 @@ bun i vivth
|
|
|
14
14
|
- `vivth` technically can run in any `js runtime`, since it uses non platform specific api;
|
|
15
15
|
- it is written specifically to be used as a primitives for javascript library or runtime, so there are no complex abstraction is, nor will be, added in `vivth` it self;
|
|
16
16
|
|
|
17
|
-
### version
|
|
18
|
-
- 0.11.x: drop function wrapper for all classes, for better runtime performance
|
|
19
17
|
## exported-api-and-type-list
|
|
20
18
|
- [$](#$)
|
|
21
19
|
- [Derived](#derived)
|
|
22
20
|
- [PingFIFO](#pingfifo)
|
|
23
21
|
- [PingUnique](#pingunique)
|
|
24
22
|
- [Q](#q)
|
|
23
|
+
- [QFIFO](#qfifo)
|
|
24
|
+
- [QUnique](#qunique)
|
|
25
25
|
- [Signal](#signal)
|
|
26
26
|
- [NewQBlock](#newqblock)
|
|
27
27
|
- [TryAsync](#tryasync)
|
|
28
28
|
- [TrySync](#trysync)
|
|
29
29
|
<h2 id="$">$</h2>
|
|
30
30
|
|
|
31
|
-
- a class to `autosubscribe` to an signal changes (`Derived` and `Signal` alike);
|
|
32
31
|
// runs everytime signal.value changes;
|
|
33
32
|
return signal.value * 2;
|
|
34
33
|
// runs everytime signal.value changes;
|
|
35
34
|
console.log(signal.value);
|
|
36
35
|
// console.log(derived.value);
|
|
36
|
+
- a class to `autosubscribe` to an signal changes (`Derived` and `Signal` alike);
|
|
37
|
-
for minimal total bundle size use `function` [New$](#new$) instead;
|
|
38
37
|
|
|
39
38
|
*) <sub>[go to exported list](#exported-api-and-type-list)</sub>
|
|
40
39
|
|
|
41
40
|
<h2 id="derived">Derived</h2>
|
|
42
41
|
|
|
43
|
-
- a class for creating signal which its value are derived from other signal (`Derived` and `Signal` alike);
|
|
44
42
|
// runs everytime signal.value changes;
|
|
45
43
|
return signal.value * 2;
|
|
46
44
|
// runs everytime derived.value changes;
|
|
47
45
|
console.log(derived.value);
|
|
46
|
+
- a class for creating signal which its value are derived from other signal (`Derived` and `Signal` alike);
|
|
48
|
-
can be subscribed by using [New$](#new$);
|
|
49
|
-
for minimal total bundle size use `function` [NewDerived](#newderived) instead;
|
|
50
47
|
|
|
51
48
|
*) <sub>[go to exported list](#exported-api-and-type-list)</sub>
|
|
52
49
|
|
|
@@ -56,9 +56,21 @@ bun i vivth
|
|
|
56
56
|
|
|
57
57
|
*) <sub>[go to exported list](#exported-api-and-type-list)</sub>
|
|
58
58
|
|
|
59
|
+
<h2 id="qfifo">QFIFO</h2>
|
|
60
|
+
|
|
61
|
+
```js
|
|
59
62
|
* @typedef {[callback:()=>(any|Promise<any>),debounce?:(number)]} queueFIFODetails
|
|
60
63
|
*/
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
+
|
|
65
|
+
*) <sub>[go to exported list](#exported-api-and-type-list)</sub>
|
|
66
|
+
|
|
67
|
+
<h2 id="qunique">QUnique</h2>
|
|
68
|
+
|
|
69
|
+
- a class for Queue;
|
|
64
|
-
|
|
65
|
-
|
|
70
|
+
|
|
71
|
+
*) <sub>[go to exported list](#exported-api-and-type-list)</sub>
|
|
72
|
+
|
|
66
73
|
<h2 id="signal">Signal</h2>
|
|
67
74
|
|
|
68
|
-
- a class for creating signal;
|
|
69
75
|
// runs everytime signal.value changes;
|
|
70
76
|
return signal.value * 2;
|
|
71
77
|
// runs everytime signal.value changes;
|
|
72
78
|
console.log(signal.value);
|
|
79
|
+
- a class for creating signal;
|
|
73
|
-
can be subscribed by using [New$](#new$) or [NewDerived](#newderived);
|
|
74
|
-
for minimal total bundle size use `function` [NewSignal](#newSignal) instead;
|
|
75
80
|
|
|
76
81
|
*) <sub>[go to exported list](#exported-api-and-type-list)</sub>
|
|
77
82
|
|
package/dev/index.mjs
CHANGED
|
@@ -24,7 +24,5 @@ new __JSDev({
|
|
|
24
24
|
'- `vivth` technically can run in any `js runtime`, since it uses non platform specific api;',
|
|
25
25
|
'- it is written specifically to be used as a primitives for javascript library or runtime, so there are no complex abstraction is, nor will be, added in `vivth` it self;',
|
|
26
26
|
'',
|
|
27
|
-
'### version',
|
|
28
|
-
'- 0.11.x: drop function wrapper for all classes, for better runtime performance',
|
|
29
27
|
],
|
|
30
28
|
}).run();
|
package/index.mjs
CHANGED
|
@@ -21,14 +21,14 @@
|
|
|
21
21
|
* - `vivth` technically can run in any `js runtime`, since it uses non platform specific api;
|
|
22
22
|
* - it is written specifically to be used as a primitives for javascript library or runtime, so there are no complex abstraction is, nor will be, added in `vivth` it self;
|
|
23
23
|
*
|
|
24
|
-
* ### version
|
|
25
|
-
* - 0.11.x: drop function wrapper for all classes, for better runtime performance
|
|
26
24
|
*/
|
|
27
25
|
export { $ } from './src/class/$.mjs';
|
|
28
26
|
export { Derived } from './src/class/Derived.mjs';
|
|
29
27
|
export { PingFIFO } from './src/class/PingFIFO.mjs';
|
|
30
28
|
export { PingUnique } from './src/class/PingUnique.mjs';
|
|
31
29
|
export { Q } from './src/class/Q.mjs';
|
|
30
|
+
export { QFIFO } from './src/class/QFIFO.mjs';
|
|
31
|
+
export { QUnique } from './src/class/QUnique.mjs';
|
|
32
32
|
export { Signal } from './src/class/Signal.mjs';
|
|
33
33
|
export { NewQBlock } from './src/function/NewQBlock.mjs';
|
|
34
34
|
export { TryAsync } from './src/function/TryAsync.mjs';
|
package/package.json
CHANGED
package/src/class/$.mjs
CHANGED
|
@@ -1,25 +1,12 @@
|
|
|
1
1
|
// @ts-check
|
|
2
2
|
|
|
3
|
+
import { PingFIFO } from './PingFIFO.mjs';
|
|
3
4
|
import { isAsync } from '../common.mjs';
|
|
4
|
-
import { NewQBlock } from '../function/NewQBlock.mjs';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* @description
|
|
8
8
|
* - a class to `autosubscribe` to an signal changes (`Derived` and `Signal` alike);
|
|
9
|
-
*
|
|
10
|
-
* import { $, Derived, Signal } from 'vivth';
|
|
11
|
-
* const signal = new Signal(0);
|
|
12
|
-
* const derived = new Derived(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
|
-
* ```
|
|
9
|
+
* - for minimal total bundle size use `function` [New$](#new$) instead;
|
|
23
10
|
*/
|
|
24
11
|
export class $ {
|
|
25
12
|
/**
|
|
@@ -45,27 +32,26 @@ export class $ {
|
|
|
45
32
|
* @returns {void}
|
|
46
33
|
*/
|
|
47
34
|
remove$ = () => {
|
|
48
|
-
|
|
49
|
-
$.
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
$.effects.set(this, new Set());
|
|
53
|
-
}, $);
|
|
35
|
+
$.effects.get(this)?.forEach((signalInstance) => {
|
|
36
|
+
$.mappedSignals.get(signalInstance).delete(this);
|
|
37
|
+
});
|
|
38
|
+
$.effects.set(this, new Set());
|
|
54
39
|
};
|
|
55
40
|
/**
|
|
56
|
-
* @type {(
|
|
41
|
+
* @type {(arg0:{remove$:()=>void})=>void}
|
|
57
42
|
*/
|
|
58
43
|
effect;
|
|
59
44
|
/**
|
|
60
|
-
* @param {
|
|
45
|
+
* @param {$["effect"]} effect
|
|
61
46
|
*/
|
|
62
47
|
constructor(effect) {
|
|
63
48
|
this.effect = effect;
|
|
64
|
-
|
|
49
|
+
new PingFIFO(async () => {
|
|
65
50
|
$.isRegistering = true;
|
|
66
|
-
const check = this.effect({ remove$: this.remove$ });
|
|
67
51
|
if (isAsync(effect)) {
|
|
68
|
-
await
|
|
52
|
+
await effect({ remove$: this.remove$ });
|
|
53
|
+
} else {
|
|
54
|
+
effect({ remove$: this.remove$ });
|
|
69
55
|
}
|
|
70
56
|
$.isRegistering = false;
|
|
71
57
|
const signalInstances = $.activeSignal;
|
|
@@ -77,6 +63,6 @@ export class $ {
|
|
|
77
63
|
$.mappedSignals.get(signal).add(this);
|
|
78
64
|
});
|
|
79
65
|
$.activeSignal = new Set();
|
|
80
|
-
}
|
|
66
|
+
});
|
|
81
67
|
}
|
|
82
68
|
}
|
package/src/class/Derived.mjs
CHANGED
|
@@ -1,25 +1,14 @@
|
|
|
1
1
|
// @ts-check
|
|
2
2
|
|
|
3
3
|
import { Signal } from './Signal.mjs';
|
|
4
|
-
import { isAsync } from '../common.mjs';
|
|
5
4
|
import { $ } from './$.mjs';
|
|
5
|
+
import { isAsync } from '../common.mjs';
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* @description
|
|
9
9
|
* - a class for creating signal which its value are derived from other signal (`Derived` and `Signal` alike);
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
* const signal = new Signal(0);
|
|
13
|
-
* const derived = new Derived(async () =>{
|
|
14
|
-
* // runs everytime signal.value changes;
|
|
15
|
-
* return signal.value * 2;
|
|
16
|
-
* });
|
|
17
|
-
* const autosubscriber = new $(async ()=>{
|
|
18
|
-
* // runs everytime derived.value changes;
|
|
19
|
-
* console.log(derived.value);
|
|
20
|
-
* });
|
|
21
|
-
* signal.value = 1;
|
|
22
|
-
* ```
|
|
10
|
+
* - can be subscribed by using [New$](#new$);
|
|
11
|
+
* - for minimal total bundle size use `function` [NewDerived](#newderived) instead;
|
|
23
12
|
*/
|
|
24
13
|
/**
|
|
25
14
|
* @template V
|
|
@@ -27,19 +16,19 @@ import { $ } from './$.mjs';
|
|
|
27
16
|
*/
|
|
28
17
|
export class Derived extends Signal {
|
|
29
18
|
/**
|
|
30
|
-
* @param {(
|
|
19
|
+
* @param {(arg0:{remove$:()=>void})=>V} derivedFunction
|
|
31
20
|
*/
|
|
32
21
|
constructor(derivedFunction) {
|
|
33
22
|
super(undefined);
|
|
34
23
|
const real = isAsync(derivedFunction)
|
|
35
24
|
? /**
|
|
36
|
-
* @param {{remove
|
|
25
|
+
* @param {{remove$:()=>void}} options
|
|
37
26
|
*/
|
|
38
27
|
async (options) => {
|
|
39
28
|
super.value = await derivedFunction(options);
|
|
40
29
|
}
|
|
41
30
|
: /**
|
|
42
|
-
* @param {{remove
|
|
31
|
+
* @param {{remove$:()=>void}} options
|
|
43
32
|
*/
|
|
44
33
|
(options) => {
|
|
45
34
|
super.value = derivedFunction(options);
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
|
|
3
|
+
import { timeout } from '../common.mjs';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @description
|
|
7
|
+
* ```js
|
|
8
|
+
* /**
|
|
9
|
+
* * @typedef {[callback:()=>(any|Promise<any>),debounce?:(number)]} queueFIFODetails
|
|
10
|
+
* *[blank]/
|
|
11
|
+
* ```
|
|
12
|
+
* - a class for Queue;
|
|
13
|
+
* - for minimal total bundle size use `function` [NewPingFIFO](#newpingfifo) instead;
|
|
14
|
+
* - this class provides `QFIFO.makeQClass`;
|
|
15
|
+
* >- this method will setup `QFIFO` to use the inputed `queueArray`(as arg0) as centralized lookup for queue managed by `QFIFO`;
|
|
16
|
+
* >- 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;
|
|
17
|
+
*/
|
|
18
|
+
export class QFIFO {
|
|
19
|
+
/**
|
|
20
|
+
* @param {queueFIFODetails[]} queueArray
|
|
21
|
+
* @returns {typeof QFIFO}
|
|
22
|
+
*/
|
|
23
|
+
static makeQClass = (queueArray) => {
|
|
24
|
+
QFIFO.#queue = queueArray;
|
|
25
|
+
return QFIFO;
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* @type {queueFIFODetails[]}
|
|
29
|
+
*/
|
|
30
|
+
static #queue = [];
|
|
31
|
+
/**
|
|
32
|
+
* @type {boolean}
|
|
33
|
+
*/
|
|
34
|
+
static #isRunning = false;
|
|
35
|
+
/**
|
|
36
|
+
* @type {(...queueFIFODetails:queueFIFODetails)=>void}
|
|
37
|
+
*/
|
|
38
|
+
static assign = (..._queue) => {
|
|
39
|
+
QFIFO.#push(_queue);
|
|
40
|
+
if (!QFIFO.#isRunning) {
|
|
41
|
+
QFIFO.#run();
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
/**
|
|
45
|
+
* @param {queueFIFODetails} _queue
|
|
46
|
+
*/
|
|
47
|
+
static #push = (_queue) => {
|
|
48
|
+
QFIFO.#queue.push(_queue);
|
|
49
|
+
};
|
|
50
|
+
static #run = async () => {
|
|
51
|
+
QFIFO.#isRunning = true;
|
|
52
|
+
while (QFIFO.#queue.length !== 0) {
|
|
53
|
+
const [callback, debounceMs = 0] = QFIFO.#queue[0];
|
|
54
|
+
QFIFO.#queue.shift();
|
|
55
|
+
await callback();
|
|
56
|
+
/**
|
|
57
|
+
* conditional debounce;
|
|
58
|
+
* queue FIFO messing up when have debouncer while `debounceMS` are set to 0;
|
|
59
|
+
*/
|
|
60
|
+
// if (debounceMs) {
|
|
61
|
+
await timeout(debounceMs);
|
|
62
|
+
// }
|
|
63
|
+
}
|
|
64
|
+
QFIFO.#isRunning = false;
|
|
65
|
+
};
|
|
66
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
|
|
3
|
+
import { timeout } from '../common.mjs';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @description
|
|
7
|
+
* - a class for Queue;
|
|
8
|
+
* - for minimal total bundle size use `function` [NewPingUnique](#newpingunique) instead;
|
|
9
|
+
* - this class provides `QUnique.makeQClass`;
|
|
10
|
+
* >- this method will setup `QUnique` to use the inputed `queueMap`(as arg0) as centralized lookup for queue managed by `QUnique`;
|
|
11
|
+
* >- 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;
|
|
12
|
+
*/
|
|
13
|
+
export class QUnique {
|
|
14
|
+
/**
|
|
15
|
+
* @param {Map<any, [()=>Promise<any>,number]>} queueMap
|
|
16
|
+
* @returns {typeof QUnique}
|
|
17
|
+
*/
|
|
18
|
+
static makeQClass = (queueMap) => {
|
|
19
|
+
QUnique.#queue = queueMap;
|
|
20
|
+
return QUnique;
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* @typedef {Object} queueUniqueObject
|
|
24
|
+
* @property {any} i
|
|
25
|
+
* @property {()=>(any|Promise<any>)} c
|
|
26
|
+
* @property {number} [d]
|
|
27
|
+
*/
|
|
28
|
+
/**
|
|
29
|
+
* @type {Map<any, [()=>Promise<any>,number]>}
|
|
30
|
+
*/
|
|
31
|
+
static #queue = new Map();
|
|
32
|
+
/**
|
|
33
|
+
* @type {boolean}
|
|
34
|
+
*/
|
|
35
|
+
static #isRunning = false;
|
|
36
|
+
/**
|
|
37
|
+
* @type {(queueUniqueObject:queueUniqueObject)=>void}
|
|
38
|
+
*/
|
|
39
|
+
static assign = (_queue) => {
|
|
40
|
+
QUnique.#push(_queue);
|
|
41
|
+
if (!QUnique.#isRunning) {
|
|
42
|
+
QUnique.#run();
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
/**
|
|
46
|
+
* @param {queueUniqueObject} _queue
|
|
47
|
+
*/
|
|
48
|
+
static #push = (_queue) => {
|
|
49
|
+
const { i, c, d } = _queue;
|
|
50
|
+
QUnique.#queue.set(i, [c, d ? d : 0]);
|
|
51
|
+
};
|
|
52
|
+
static #run = async () => {
|
|
53
|
+
QUnique.#isRunning = true;
|
|
54
|
+
const keysIterator = QUnique.#queue.keys();
|
|
55
|
+
let keys = keysIterator.next();
|
|
56
|
+
while (!keys.done) {
|
|
57
|
+
const key = keys.value;
|
|
58
|
+
const q = QUnique.#queue.get(key);
|
|
59
|
+
if (!q) {
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
const [callback, debounce] = q;
|
|
63
|
+
QUnique.#queue.delete(key);
|
|
64
|
+
/**
|
|
65
|
+
* debounce anyway;
|
|
66
|
+
* queue with unique id have characteristic of messing up when have no debouncer;
|
|
67
|
+
* especially when request comes too fast;
|
|
68
|
+
*/
|
|
69
|
+
await timeout(debounce);
|
|
70
|
+
await callback();
|
|
71
|
+
keys = keysIterator.next();
|
|
72
|
+
}
|
|
73
|
+
QUnique.#isRunning = false;
|
|
74
|
+
};
|
|
75
|
+
}
|
package/src/class/Signal.mjs
CHANGED
|
@@ -5,19 +5,8 @@ import { $ } from './$.mjs';
|
|
|
5
5
|
/**
|
|
6
6
|
* @description
|
|
7
7
|
* - a class for creating signal;
|
|
8
|
-
*
|
|
9
|
-
*
|
|
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
|
-
* ```
|
|
8
|
+
* - can be subscribed by using [New$](#new$) or [NewDerived](#newderived);
|
|
9
|
+
* - for minimal total bundle size use `function` [NewSignal](#newSignal) instead;
|
|
21
10
|
*/
|
|
22
11
|
/**
|
|
23
12
|
* @template Value
|
package/types/index.d.mts
CHANGED
|
@@ -3,6 +3,8 @@ export { Derived } from "./src/class/Derived.mjs";
|
|
|
3
3
|
export { PingFIFO } from "./src/class/PingFIFO.mjs";
|
|
4
4
|
export { PingUnique } from "./src/class/PingUnique.mjs";
|
|
5
5
|
export { Q } from "./src/class/Q.mjs";
|
|
6
|
+
export { QFIFO } from "./src/class/QFIFO.mjs";
|
|
7
|
+
export { QUnique } from "./src/class/QUnique.mjs";
|
|
6
8
|
export { Signal } from "./src/class/Signal.mjs";
|
|
7
9
|
export { NewQBlock } from "./src/function/NewQBlock.mjs";
|
|
8
10
|
export { TryAsync } from "./src/function/TryAsync.mjs";
|
package/types/src/class/$.d.mts
CHANGED
|
@@ -1,20 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @description
|
|
3
3
|
* - a class to `autosubscribe` to an signal changes (`Derived` and `Signal` alike);
|
|
4
|
-
*
|
|
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
|
-
* ```
|
|
4
|
+
* - for minimal total bundle size use `function` [New$](#new$) instead;
|
|
18
5
|
*/
|
|
19
6
|
export class $ {
|
|
20
7
|
/**
|
|
@@ -37,19 +24,17 @@ export class $ {
|
|
|
37
24
|
*/
|
|
38
25
|
static isRegistering: boolean;
|
|
39
26
|
/**
|
|
40
|
-
* @param {
|
|
27
|
+
* @param {$["effect"]} effect
|
|
41
28
|
*/
|
|
42
|
-
constructor(effect:
|
|
43
|
-
remove$: $["remove$"];
|
|
44
|
-
}) => void);
|
|
29
|
+
constructor(effect: $["effect"]);
|
|
45
30
|
/**
|
|
46
31
|
* @returns {void}
|
|
47
32
|
*/
|
|
48
33
|
remove$: () => void;
|
|
49
34
|
/**
|
|
50
|
-
* @type {(
|
|
35
|
+
* @type {(arg0:{remove$:()=>void})=>void}
|
|
51
36
|
*/
|
|
52
|
-
effect: (
|
|
53
|
-
remove$:
|
|
37
|
+
effect: (arg0: {
|
|
38
|
+
remove$: () => void;
|
|
54
39
|
}) => void;
|
|
55
40
|
}
|
|
@@ -1,19 +1,8 @@
|
|
|
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
|
-
*
|
|
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
|
-
* ```
|
|
4
|
+
* - can be subscribed by using [New$](#new$);
|
|
5
|
+
* - for minimal total bundle size use `function` [NewDerived](#newderived) instead;
|
|
17
6
|
*/
|
|
18
7
|
/**
|
|
19
8
|
* @template V
|
|
@@ -21,11 +10,10 @@
|
|
|
21
10
|
*/
|
|
22
11
|
export class Derived<V> extends Signal<V> {
|
|
23
12
|
/**
|
|
24
|
-
* @param {(
|
|
13
|
+
* @param {(arg0:{remove$:()=>void})=>V} derivedFunction
|
|
25
14
|
*/
|
|
26
|
-
constructor(derivedFunction: (
|
|
27
|
-
remove$:
|
|
15
|
+
constructor(derivedFunction: (arg0: {
|
|
16
|
+
remove$: () => void;
|
|
28
17
|
}) => V);
|
|
29
18
|
}
|
|
30
19
|
import { Signal } from './Signal.mjs';
|
|
31
|
-
import { $ } from './$.mjs';
|
|
@@ -30,16 +30,16 @@ export class PingFIFO {
|
|
|
30
30
|
/**
|
|
31
31
|
* @type {queueFIFODetails[]}
|
|
32
32
|
*/
|
|
33
|
-
static "__#
|
|
33
|
+
static "__#1@#queue": queueFIFODetails[];
|
|
34
34
|
/**
|
|
35
35
|
* @type {boolean}
|
|
36
36
|
*/
|
|
37
|
-
static "__#
|
|
37
|
+
static "__#1@#isRunning": boolean;
|
|
38
38
|
/**
|
|
39
39
|
* @param {queueFIFODetails} _queue
|
|
40
40
|
*/
|
|
41
|
-
static "__#
|
|
42
|
-
static "__#
|
|
41
|
+
static "__#1@#push": (_queue: queueFIFODetails) => void;
|
|
42
|
+
static "__#1@#run": () => Promise<void>;
|
|
43
43
|
/**
|
|
44
44
|
* @param {()=>(any|Promise<any>)} callback
|
|
45
45
|
* @param {number} [debounce]
|
|
@@ -27,18 +27,18 @@ export class PingUnique {
|
|
|
27
27
|
/**
|
|
28
28
|
* @type {Map<any, [()=>Promise<void>,number]>}
|
|
29
29
|
*/
|
|
30
|
-
static "__#
|
|
30
|
+
static "__#3@#queue": Map<any, [() => Promise<void>, number]>;
|
|
31
31
|
/**
|
|
32
32
|
* @type {boolean}
|
|
33
33
|
*/
|
|
34
|
-
static "__#
|
|
34
|
+
static "__#3@#isRunning": boolean;
|
|
35
35
|
/**
|
|
36
36
|
* @param {any} id
|
|
37
37
|
* @param {()=>Promise<void>} callback
|
|
38
38
|
* @param {number} debounceMS
|
|
39
39
|
*/
|
|
40
|
-
static "__#
|
|
41
|
-
static "__#
|
|
40
|
+
static "__#3@#push": (id: any, callback: () => Promise<void>, debounceMS: number) => void;
|
|
41
|
+
static "__#3@#run": () => Promise<void>;
|
|
42
42
|
/**
|
|
43
43
|
* @param {any} id
|
|
44
44
|
* @param {()=>Promise<void>} callback
|
package/types/src/class/Q.d.mts
CHANGED
|
@@ -39,7 +39,7 @@ export class Q {
|
|
|
39
39
|
/**
|
|
40
40
|
* @type {Promise<void>}
|
|
41
41
|
*/
|
|
42
|
-
static "__#
|
|
42
|
+
static "__#4@#fifo": Promise<void>;
|
|
43
43
|
/**
|
|
44
44
|
* Blocks execution for subsequent calls until the current one finishes.
|
|
45
45
|
* @returns {Promise<{resume:()=>void}>} Resolves when it's safe to proceed, returning a cleanup function
|
|
@@ -50,7 +50,7 @@ export class Q {
|
|
|
50
50
|
/**
|
|
51
51
|
* @type {Map<any, Promise<any>>}
|
|
52
52
|
*/
|
|
53
|
-
static "__#
|
|
53
|
+
static "__#4@#unique": Map<any, Promise<any>>;
|
|
54
54
|
/**
|
|
55
55
|
* Ensures that each id has only one task running at a time.
|
|
56
56
|
* Calls with the same id will wait for the previous call to finish.
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @description
|
|
3
|
+
* ```js
|
|
4
|
+
* /**
|
|
5
|
+
* * @typedef {[callback:()=>(any|Promise<any>),debounce?:(number)]} queueFIFODetails
|
|
6
|
+
* *[blank]/
|
|
7
|
+
* ```
|
|
8
|
+
* - a class for Queue;
|
|
9
|
+
* - for minimal total bundle size use `function` [NewPingFIFO](#newpingfifo) instead;
|
|
10
|
+
* - this class provides `QFIFO.makeQClass`;
|
|
11
|
+
* >- this method will setup `QFIFO` to use the inputed `queueArray`(as arg0) as centralized lookup for queue managed by `QFIFO`;
|
|
12
|
+
* >- 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;
|
|
13
|
+
*/
|
|
14
|
+
export class QFIFO {
|
|
15
|
+
/**
|
|
16
|
+
* @param {queueFIFODetails[]} queueArray
|
|
17
|
+
* @returns {typeof QFIFO}
|
|
18
|
+
*/
|
|
19
|
+
static makeQClass: (queueArray: queueFIFODetails[]) => typeof QFIFO;
|
|
20
|
+
/**
|
|
21
|
+
* @type {queueFIFODetails[]}
|
|
22
|
+
*/
|
|
23
|
+
static "__#5@#queue": queueFIFODetails[];
|
|
24
|
+
/**
|
|
25
|
+
* @type {boolean}
|
|
26
|
+
*/
|
|
27
|
+
static "__#5@#isRunning": boolean;
|
|
28
|
+
/**
|
|
29
|
+
* @type {(...queueFIFODetails:queueFIFODetails)=>void}
|
|
30
|
+
*/
|
|
31
|
+
static assign: (...queueFIFODetails: queueFIFODetails) => void;
|
|
32
|
+
/**
|
|
33
|
+
* @param {queueFIFODetails} _queue
|
|
34
|
+
*/
|
|
35
|
+
static "__#5@#push": (_queue: queueFIFODetails) => void;
|
|
36
|
+
static "__#5@#run": () => Promise<void>;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* *[blank]/
|
|
40
|
+
* ```
|
|
41
|
+
* - a class for Queue;
|
|
42
|
+
* - for minimal total bundle size use `function` [NewPingFIFO](#newpingfifo) instead;
|
|
43
|
+
* - this class provides `QFIFO.makeQClass`;
|
|
44
|
+
* >- this method will setup `QFIFO` to use the inputed `queueArray`(as arg0) as centralized lookup for queue managed by `QFIFO`;
|
|
45
|
+
* >- 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;
|
|
46
|
+
*/
|
|
47
|
+
export type queueFIFODetails = [callback: () => (any | Promise<any>), debounce?: (number)];
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @description
|
|
3
|
+
* - a class for Queue;
|
|
4
|
+
* - for minimal total bundle size use `function` [NewPingUnique](#newpingunique) instead;
|
|
5
|
+
* - this class provides `QUnique.makeQClass`;
|
|
6
|
+
* >- this method will setup `QUnique` to use the inputed `queueMap`(as arg0) as centralized lookup for queue managed by `QUnique`;
|
|
7
|
+
* >- 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;
|
|
8
|
+
*/
|
|
9
|
+
export class QUnique {
|
|
10
|
+
/**
|
|
11
|
+
* @param {Map<any, [()=>Promise<any>,number]>} queueMap
|
|
12
|
+
* @returns {typeof QUnique}
|
|
13
|
+
*/
|
|
14
|
+
static makeQClass: (queueMap: Map<any, [() => Promise<any>, number]>) => typeof QUnique;
|
|
15
|
+
/**
|
|
16
|
+
* @typedef {Object} queueUniqueObject
|
|
17
|
+
* @property {any} i
|
|
18
|
+
* @property {()=>(any|Promise<any>)} c
|
|
19
|
+
* @property {number} [d]
|
|
20
|
+
*/
|
|
21
|
+
/**
|
|
22
|
+
* @type {Map<any, [()=>Promise<any>,number]>}
|
|
23
|
+
*/
|
|
24
|
+
static "__#6@#queue": Map<any, [() => Promise<any>, number]>;
|
|
25
|
+
/**
|
|
26
|
+
* @type {boolean}
|
|
27
|
+
*/
|
|
28
|
+
static "__#6@#isRunning": boolean;
|
|
29
|
+
/**
|
|
30
|
+
* @type {(queueUniqueObject:queueUniqueObject)=>void}
|
|
31
|
+
*/
|
|
32
|
+
static assign: (queueUniqueObject: {
|
|
33
|
+
i: any;
|
|
34
|
+
c: () => (any | Promise<any>);
|
|
35
|
+
d?: number;
|
|
36
|
+
}) => void;
|
|
37
|
+
/**
|
|
38
|
+
* @param {queueUniqueObject} _queue
|
|
39
|
+
*/
|
|
40
|
+
static "__#6@#push": (_queue: {
|
|
41
|
+
i: any;
|
|
42
|
+
c: () => (any | Promise<any>);
|
|
43
|
+
d?: number;
|
|
44
|
+
}) => void;
|
|
45
|
+
static "__#6@#run": () => Promise<void>;
|
|
46
|
+
}
|
|
@@ -1,19 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @description
|
|
3
3
|
* - a class for creating signal;
|
|
4
|
-
*
|
|
5
|
-
*
|
|
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
|
-
* ```
|
|
4
|
+
* - can be subscribed by using [New$](#new$) or [NewDerived](#newderived);
|
|
5
|
+
* - for minimal total bundle size use `function` [NewSignal](#newSignal) instead;
|
|
17
6
|
*/
|
|
18
7
|
/**
|
|
19
8
|
* @template Value
|