vivth 0.10.0 → 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.
Files changed (39) hide show
  1. package/README.md +20 -65
  2. package/dev/index.mjs +2 -0
  3. package/index.mjs +8 -10
  4. package/package.json +1 -1
  5. package/src/class/$.mjs +27 -13
  6. package/src/class/Derived.mjs +27 -11
  7. package/src/class/{QFIFO.mjs → PingFIFO.mjs} +29 -17
  8. package/src/class/PingUnique.mjs +84 -0
  9. package/src/class/Q.mjs +1 -1
  10. package/src/class/Signal.mjs +14 -3
  11. package/src/function/NewQBlock.mjs +39 -0
  12. package/src/function/{tryAsync.export.mjs → TryAsync.mjs} +1 -1
  13. package/src/function/{trySync.export.mjs → TrySync.mjs} +1 -1
  14. package/src/types/{anyButUndefined.type.mjs → AnyButUndefined.type.mjs} +1 -1
  15. package/types/index.d.mts +6 -10
  16. package/types/src/class/$.d.mts +22 -5
  17. package/types/src/class/Derived.d.mts +18 -4
  18. package/types/src/class/{QFIFO.d.mts → PingFIFO.d.mts} +25 -15
  19. package/types/src/class/PingUnique.d.mts +48 -0
  20. package/types/src/class/Q.d.mts +4 -4
  21. package/types/src/class/Signal.d.mts +13 -2
  22. package/types/src/function/NewQBlock.d.mts +1 -0
  23. package/types/src/function/{tryAsync.export.d.mts → TryAsync.d.mts} +1 -1
  24. package/types/src/function/TrySync.d.mts +1 -0
  25. package/types/src/types/AnyButUndefined.type.d.mts +1 -0
  26. package/src/class/QUnique.mjs +0 -75
  27. package/src/function/New$.mjs +0 -28
  28. package/src/function/NewDerived.mjs +0 -28
  29. package/src/function/NewPingFIFO.mjs +0 -24
  30. package/src/function/NewPingUnique.mjs +0 -29
  31. package/src/function/NewSignal.mjs +0 -28
  32. package/types/src/class/QUnique.d.mts +0 -46
  33. package/types/src/function/New$.d.mts +0 -2
  34. package/types/src/function/NewDerived.d.mts +0 -2
  35. package/types/src/function/NewPingFIFO.d.mts +0 -1
  36. package/types/src/function/NewPingUnique.d.mts +0 -1
  37. package/types/src/function/NewSignal.d.mts +0 -2
  38. package/types/src/function/trySync.export.d.mts +0 -1
  39. package/types/src/types/anyButUndefined.type.d.mts +0 -1
package/README.md CHANGED
@@ -14,93 +14,67 @@ 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
17
19
  ## exported-api-and-type-list
18
20
  - [$](#$)
19
21
  - [Derived](#derived)
22
+ - [PingFIFO](#pingfifo)
23
+ - [PingUnique](#pingunique)
20
24
  - [Q](#q)
21
- - [QFIFO](#qfifo)
22
- - [QUnique](#qunique)
23
25
  - [Signal](#signal)
24
- - [New$](#new$)
25
- - [NewDerived](#newderived)
26
- - [NewPingFIFO](#newpingfifo)
27
- - [NewPingUnique](#newpingunique)
28
- - [NewSignal](#newsignal)
29
- - [tryAsync](#tryasync)
30
- - [trySync](#trysync)
26
+ - [NewQBlock](#newqblock)
27
+ - [TryAsync](#tryasync)
28
+ - [TrySync](#trysync)
31
29
  <h2 id="$">$</h2>
32
30
 
33
- - a class to `autosubscribe` to an signal changes (`Derived` and `Signal` alike);
34
- for minimal total bundle size use `function` [New$](#new$) instead;
31
+ - a class to `autosubscribe` to an signal changes (`Derived` and `Signal` alike);
35
32
  // runs everytime signal.value changes;
36
33
  return signal.value * 2;
37
34
  // runs everytime signal.value changes;
38
35
  console.log(signal.value);
39
36
  // console.log(derived.value);
40
37
 
41
38
  *) <sub>[go to exported list](#exported-api-and-type-list)</sub>
42
39
 
43
40
  <h2 id="derived">Derived</h2>
44
41
 
45
- - a class for creating signal which its value are derived from other signal (`Derived` and `Signal` alike);
46
- can be subscribed by using [New$](#new$);
47
- for minimal total bundle size use `function` [NewDerived](#newderived) instead;
42
+ - a class for creating signal which its value are derived from other signal (`Derived` and `Signal` alike);
48
43
  // runs everytime signal.value changes;
49
44
  return signal.value * 2;
50
45
  // runs everytime derived.value changes;
51
46
  console.log(derived.value);
52
47
 
53
48
  *) <sub>[go to exported list](#exported-api-and-type-list)</sub>
54
49
 
55
- <h2 id="q">Q</h2>
50
+ <h2 id="pingfifo">PingFIFO</h2>
56
51
 
57
- - class that containts static methods to generate Promise based `awaiter` inside async function, to prevent race condition, including but not limited to:
58
- behaviour:
59
- this class provides `Q.makeQClass`;
52
+ ```js
60
53
  * @typedef {[callback:()=>(any|Promise<any>),debounce?:(number)]} queueFIFODetails
61
54
  */
62
- a class for Queue;
63
- function to auto queue callbacks that will be called `first in first out` style;
64
- this class provides `QFIFO.makeQClass`;
65
55
 
66
56
  *) <sub>[go to exported list](#exported-api-and-type-list)</sub>
67
57
 
68
- <h2 id="qfifo">QFIFO</h2>
58
+ <h2 id="pingunique">PingUnique</h2>
69
59
 
70
- ```js
71
60
  * @typedef {[callback:()=>(any|Promise<any>),debounce?:(number)]} queueFIFODetails
72
61
  */
73
- a class for Queue;
74
- for minimal total bundle size use `function` [NewPingFIFO](#newpingfifo) instead;
75
- this class provides `QFIFO.makeQClass`;
62
+ - a class for Queue;
76
63
  new PingUnique(uniqueID, async () => {
77
- this class provides `QUnique.makeQClass`;
78
64
 
79
65
  *) <sub>[go to exported list](#exported-api-and-type-list)</sub>
80
66
 
81
- <h2 id="qunique">QUnique</h2>
67
+ <h2 id="q">Q</h2>
82
68
 
83
- - a class for Queue;
84
- for minimal total bundle size use `function` [NewPingUnique](#newpingunique) instead;
85
- this class provides `QUnique.makeQClass`;
69
+ - class that containts static methods to generate Promise based `awaiter` inside async function, to prevent race condition, including but not limited to:
86
- behaviour:
87
- this class provides `Q.makeQClass`;
88
70
 
89
71
  *) <sub>[go to exported list](#exported-api-and-type-list)</sub>
90
72
 
91
73
  <h2 id="signal">Signal</h2>
92
74
 
93
- - a class for creating signal;
94
- can be subscribed by using [New$](#new$) or [NewDerived](#newderived);
95
- for minimal total bundle size use `function` [NewSignal](#newSignal) instead;
96
-
97
- *) <sub>[go to exported list](#exported-api-and-type-list)</sub>
98
-
99
- <h2 id="new$">New$</h2>
100
-
101
- - function to create `autosubscriber`;
102
75
  - syntatic sugar for [$](#$);
103
76
  // runs everytime signal.value changes;
104
77
  return signal.value * 2;
105
78
  // runs everytime signal.value changes;
106
79
  console.log(signal.value);
107
80
  // console.log(derived.value);
108
-
109
- *) <sub>[go to exported list](#exported-api-and-type-list)</sub>
110
-
111
- <h2 id="newderived">NewDerived</h2>
112
-
113
- - function to create `signal` that its value are derived from another `signal`;
114
81
  - syntatic sugar for [Derived](#derived);
115
82
  // runs everytime signal.value changes;
116
83
  return signal.value * 2;
117
84
  // runs everytime derived.value changes;
118
85
  console.log(derived.value);
119
-
120
- *) <sub>[go to exported list](#exported-api-and-type-list)</sub>
121
-
122
- <h2 id="newpingfifo">NewPingFIFO</h2>
123
-
124
- - function to auto queue callbacks that will be called `first in first out` style;
125
-
126
- *) <sub>[go to exported list](#exported-api-and-type-list)</sub>
127
-
128
- <h2 id="newpingunique">NewPingUnique</h2>
129
-
130
- - function to auto queue callbacks:
86
+ - a class for creating signal;
131
87
  // runs everytime signal.value changes;
132
88
  return signal.value * 2;
133
89
  // runs everytime signal.value changes;
134
90
  console.log(signal.value);
135
91
 
136
92
  *) <sub>[go to exported list](#exported-api-and-type-list)</sub>
137
93
 
138
- <h2 id="newsignal">NewSignal</h2>
94
+ <h2 id="newqblock">NewQBlock</h2>
139
95
 
140
- - function to create `signal`;
141
96
  - syntatic sugar for [Signal](#signal);
142
97
  // runs everytime signal.value changes;
143
98
  return signal.value * 2;
144
99
  // runs everytime signal.value changes;
145
100
  console.log(signal.value);
101
+ - a function for Queue;
146
- will wait next execution of the same `arg1`:`objectReferenceID`, without blocking other calls;
147
102
  const objectReferenceID = 'yourUniqueID'; // can be anything, reference to object is preferable;
148
103
  );
149
104
 
150
105
  *) <sub>[go to exported list](#exported-api-and-type-list)</sub>
151
106
 
152
- <h2 id="tryasync">tryAsync</h2>
107
+ <h2 id="tryasync">TryAsync</h2>
153
108
 
154
109
  - error as value for asynchronous operation
155
110
 
156
111
  *) <sub>[go to exported list](#exported-api-and-type-list)</sub>
157
112
 
158
- <h2 id="trysync">trySync</h2>
113
+ <h2 id="trysync">TrySync</h2>
159
114
 
160
115
  - error as value for synchronous operation
161
116
 
package/dev/index.mjs CHANGED
@@ -24,5 +24,7 @@ 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',
27
29
  ],
28
30
  }).run();
package/index.mjs CHANGED
@@ -21,20 +21,18 @@
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
24
26
  */
25
27
  export { $ } from './src/class/$.mjs';
26
28
  export { Derived } from './src/class/Derived.mjs';
29
+ export { PingFIFO } from './src/class/PingFIFO.mjs';
30
+ export { PingUnique } from './src/class/PingUnique.mjs';
27
31
  export { Q } from './src/class/Q.mjs';
28
- export { QFIFO } from './src/class/QFIFO.mjs';
29
- export { QUnique } from './src/class/QUnique.mjs';
30
32
  export { Signal } from './src/class/Signal.mjs';
31
- export { New$ } from './src/function/New$.mjs';
32
- export { NewDerived } from './src/function/NewDerived.mjs';
33
- export { NewPingFIFO } from './src/function/NewPingFIFO.mjs';
34
- export { NewPingUnique } from './src/function/NewPingUnique.mjs';
35
- export { NewSignal } from './src/function/NewSignal.mjs';
36
- export { tryAsync } from './src/function/tryAsync.export.mjs';
37
- export { trySync } from './src/function/trySync.export.mjs';
33
+ export { NewQBlock } from './src/function/NewQBlock.mjs';
34
+ export { TryAsync } from './src/function/TryAsync.mjs';
35
+ export { TrySync } from './src/function/TrySync.mjs';
38
36
  /**
39
- * @typedef {{}|null|number|string|boolean|symbol|bigint|function} anyButUndefined
37
+ * @typedef {{}|null|number|string|boolean|symbol|bigint|function} AnyButUndefined
40
38
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vivth",
3
- "version": "0.10.0",
3
+ "version": "0.11.0",
4
4
  "description": "extremely simple signal as library primitives",
5
5
  "main": "index.mjs",
6
6
  "types": "./types/index.d.mts",
package/src/class/$.mjs CHANGED
@@ -1,12 +1,25 @@
1
1
  // @ts-check
2
2
 
3
- import { NewPingFIFO } from '../function/NewPingFIFO.mjs';
4
3
  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
- * - for minimal total bundle size use `function` [New$](#new$) instead;
9
+ * ```js
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
+ * ```
10
23
  */
11
24
  export class $ {
12
25
  /**
@@ -32,26 +45,27 @@ export class $ {
32
45
  * @returns {void}
33
46
  */
34
47
  remove$ = () => {
35
- $.effects.get(this)?.forEach((signalInstance) => {
36
- $.mappedSignals.get(signalInstance).delete(this);
37
- });
38
- $.effects.set(this, new Set());
48
+ NewQBlock(async () => {
49
+ $.effects.get(this)?.forEach((signalInstance) => {
50
+ $.mappedSignals.get(signalInstance).delete(this);
51
+ });
52
+ $.effects.set(this, new Set());
53
+ }, $);
39
54
  };
40
55
  /**
41
- * @type {()=>void}
56
+ * @type {(arg:{remove$:$["remove$"]})=>void};
42
57
  */
43
58
  effect;
44
59
  /**
45
- * @param {$["effect"]} effect
60
+ * @param {(arg:{remove$:$["remove$"]})=>void} effect
46
61
  */
47
62
  constructor(effect) {
48
63
  this.effect = effect;
49
- NewPingFIFO(async () => {
64
+ NewQBlock(async () => {
50
65
  $.isRegistering = true;
66
+ const check = this.effect({ remove$: this.remove$ });
51
67
  if (isAsync(effect)) {
52
- await effect();
53
- } else {
54
- effect();
68
+ await check;
55
69
  }
56
70
  $.isRegistering = false;
57
71
  const signalInstances = $.activeSignal;
@@ -63,6 +77,6 @@ export class $ {
63
77
  $.mappedSignals.get(signal).add(this);
64
78
  });
65
79
  $.activeSignal = new Set();
66
- });
80
+ }, $);
67
81
  }
68
82
  }
@@ -1,14 +1,25 @@
1
1
  // @ts-check
2
2
 
3
3
  import { Signal } from './Signal.mjs';
4
- import { New$ } from '../function//New$.mjs';
5
4
  import { isAsync } from '../common.mjs';
5
+ import { $ } from './$.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
- * - can be subscribed by using [New$](#new$);
11
- * - for minimal total bundle size use `function` [NewDerived](#newderived) instead;
10
+ * ```js
11
+ * import { $, Derived, Signal } from 'vivth';
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
+ * ```
12
23
  */
13
24
  /**
14
25
  * @template V
@@ -16,19 +27,24 @@ import { isAsync } from '../common.mjs';
16
27
  */
17
28
  export class Derived extends Signal {
18
29
  /**
19
- * @param {()=>V} derivedFunction
30
+ * @param {(arg:{remove$:$["remove$"]})=>V} derivedFunction
20
31
  */
21
32
  constructor(derivedFunction) {
22
- // @ts-expect-error
23
- super(0);
33
+ super(undefined);
24
34
  const real = isAsync(derivedFunction)
25
- ? async () => {
26
- super.value = await derivedFunction();
35
+ ? /**
36
+ * @param {{remove$:$["remove$"]}} options
37
+ */
38
+ async (options) => {
39
+ super.value = await derivedFunction(options);
27
40
  }
28
- : () => {
29
- super.value = derivedFunction();
41
+ : /**
42
+ * @param {{remove$:$["remove$"]}} options
43
+ */
44
+ (options) => {
45
+ super.value = derivedFunction(options);
30
46
  };
31
- New$(real);
47
+ new $(real);
32
48
  }
33
49
  /**
34
50
  * @type {V}
@@ -10,19 +10,29 @@ import { timeout } from '../common.mjs';
10
10
  * *[blank]/
11
11
  * ```
12
12
  * - a class for Queue;
13
- * - for minimal total bundle size use `function` [NewPingFIFO](#newpingfifo) instead;
13
+ * - function to auto queue callbacks that will be called `first in first out` style;
14
+ * ```js
15
+ * // @ts-check
16
+ * import { PingFIFO } from 'vivth';
17
+ * const debounceMS = 0; // in miliseconds, optionals, default is 0;
18
+ * const handler = () =>{
19
+ * new PingFIFO(async () => {
20
+ * // your code
21
+ * }, debounceMS);
22
+ * }
23
+ * ```
14
24
  * - this class provides `QFIFO.makeQClass`;
15
25
  * >- this method will setup `QFIFO` to use the inputed `queueArray`(as arg0) as centralized lookup for queue managed by `QFIFO`;
16
26
  * >- 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
27
  */
18
- export class QFIFO {
28
+ export class PingFIFO {
19
29
  /**
20
30
  * @param {queueFIFODetails[]} queueArray
21
- * @returns {typeof QFIFO}
31
+ * @returns {typeof PingFIFO}
22
32
  */
23
33
  static makeQClass = (queueArray) => {
24
- QFIFO.#queue = queueArray;
25
- return QFIFO;
34
+ PingFIFO.#queue = queueArray;
35
+ return PingFIFO;
26
36
  };
27
37
  /**
28
38
  * @type {queueFIFODetails[]}
@@ -33,25 +43,27 @@ export class QFIFO {
33
43
  */
34
44
  static #isRunning = false;
35
45
  /**
36
- * @type {(...queueFIFODetails:queueFIFODetails)=>void}
46
+ * @param {()=>(any|Promise<any>)} callback
47
+ * @param {number} [debounce]
37
48
  */
38
- static assign = (..._queue) => {
39
- QFIFO.#push(_queue);
40
- if (!QFIFO.#isRunning) {
41
- QFIFO.#run();
49
+ constructor(callback, debounce = 0) {
50
+ PingFIFO.#push([callback, debounce]);
51
+ if (PingFIFO.#isRunning) {
52
+ return;
42
53
  }
43
- };
54
+ PingFIFO.#run();
55
+ }
44
56
  /**
45
57
  * @param {queueFIFODetails} _queue
46
58
  */
47
59
  static #push = (_queue) => {
48
- QFIFO.#queue.push(_queue);
60
+ PingFIFO.#queue.push(_queue);
49
61
  };
50
62
  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();
63
+ PingFIFO.#isRunning = true;
64
+ while (PingFIFO.#queue.length !== 0) {
65
+ const [callback, debounceMs = 0] = PingFIFO.#queue[0];
66
+ PingFIFO.#queue.shift();
55
67
  await callback();
56
68
  /**
57
69
  * conditional debounce;
@@ -61,6 +73,6 @@ export class QFIFO {
61
73
  await timeout(debounceMs);
62
74
  // }
63
75
  }
64
- QFIFO.#isRunning = false;
76
+ PingFIFO.#isRunning = false;
65
77
  };
66
78
  }
@@ -0,0 +1,84 @@
1
+ // @ts-check
2
+
3
+ import { timeout } from '../common.mjs';
4
+
5
+ /**
6
+ * @description
7
+ * - a class for Queue;
8
+ * > - different `uniqueID`: called `first in first out` style;
9
+ * > - same `uniqueID`: will be grouped, only the already running callback and the last callback will be called;
10
+ * ```js
11
+ * // @ts-check
12
+ * import { PingUnique } from 'vivth';
13
+ * const uniqueID = 'yourUniqueID'; // can be anything, even a reference to an object;
14
+ * const debounceMS = 0; // in miliseconds, optionals, default is 0;
15
+ * const handler = () =>{
16
+ * new PingUnique(uniqueID, async () => {
17
+ * // your code
18
+ * }, debounceMS);
19
+ * }
20
+ * ```
21
+ * - this class provides `QUnique.makeQClass`;
22
+ * >- this method will setup `QUnique` to use the inputed `queueMap`(as arg0) as centralized lookup for queue managed by `QUnique`;
23
+ * >- 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;
24
+ */
25
+ export class PingUnique {
26
+ /**
27
+ * @param {Map<any, [()=>Promise<void>,number]>} queueMap
28
+ * @returns {typeof PingUnique}
29
+ */
30
+ static makeQClass = (queueMap) => {
31
+ PingUnique.#queue = queueMap;
32
+ return PingUnique;
33
+ };
34
+ /**
35
+ * @type {Map<any, [()=>Promise<void>,number]>}
36
+ */
37
+ static #queue = new Map();
38
+ /**
39
+ * @type {boolean}
40
+ */
41
+ static #isRunning = false;
42
+ /**
43
+ * @param {any} id
44
+ * @param {()=>Promise<void>} callback
45
+ * @param {number} [debounceMS]
46
+ */
47
+ constructor(id, callback, debounceMS = 0) {
48
+ PingUnique.#push(id, callback, debounceMS);
49
+ if (!PingUnique.#isRunning) {
50
+ PingUnique.#run();
51
+ }
52
+ }
53
+ /**
54
+ * @param {any} id
55
+ * @param {()=>Promise<void>} callback
56
+ * @param {number} debounceMS
57
+ */
58
+ static #push = (id, callback, debounceMS) => {
59
+ PingUnique.#queue.set(id, [callback, debounceMS ? debounceMS : 0]);
60
+ };
61
+ static #run = async () => {
62
+ PingUnique.#isRunning = true;
63
+ const keysIterator = PingUnique.#queue.keys();
64
+ let keys = keysIterator.next();
65
+ while (!keys.done) {
66
+ const key = keys.value;
67
+ const q = PingUnique.#queue.get(key);
68
+ if (!q) {
69
+ return;
70
+ }
71
+ const [callback, debounce] = q;
72
+ PingUnique.#queue.delete(key);
73
+ /**
74
+ * debounce anyway;
75
+ * queue with unique id have characteristic of messing up when have no debouncer;
76
+ * especially when request comes too fast;
77
+ */
78
+ await timeout(debounce);
79
+ await callback();
80
+ keys = keysIterator.next();
81
+ }
82
+ PingUnique.#isRunning = false;
83
+ };
84
+ }
package/src/class/Q.mjs CHANGED
@@ -39,7 +39,7 @@ export class Q {
39
39
  return Q;
40
40
  };
41
41
  /**
42
- * @typedef {import('../types/anyButUndefined.type.mjs').anyButUndefined} anyButUndefined
42
+ * @typedef {import('../types/AnyButUndefined.type.mjs').AnyButUndefined} anyButUndefined
43
43
  */
44
44
  /**
45
45
  * @type {Promise<void>}
@@ -5,8 +5,19 @@ import { $ } from './$.mjs';
5
5
  /**
6
6
  * @description
7
7
  * - a class for creating signal;
8
- * - can be subscribed by using [New$](#new$) or [NewDerived](#newderived);
9
- * - for minimal total bundle size use `function` [NewSignal](#newSignal) instead;
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
@@ -94,6 +105,6 @@ export class Signal {
94
105
  if (!this.subscribed) {
95
106
  return;
96
107
  }
97
- this.subscribed.forEach(($_) => $_.effect());
108
+ this.subscribed.forEach(($_) => $_.effect({ remove$: $_.remove$ }));
98
109
  };
99
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 tryAsync = async (asyncFunction_) => {
13
+ export const TryAsync = async (asyncFunction_) => {
14
14
  try {
15
15
  const result = await asyncFunction_();
16
16
  return [result, undefined];
@@ -10,7 +10,7 @@
10
10
  * @param {()=>ResultType} function_
11
11
  * @returns {[ResultType|undefined, Error|undefined]}
12
12
  */
13
- export const trySync = (function_) => {
13
+ export const TrySync = (function_) => {
14
14
  try {
15
15
  const result = function_();
16
16
  return [result, undefined];
@@ -1,5 +1,5 @@
1
1
  // @ts-check
2
2
 
3
3
  /**
4
- * @typedef {{}|null|number|string|boolean|symbol|bigint|function} anyButUndefined
4
+ * @typedef {{}|null|number|string|boolean|symbol|bigint|function} AnyButUndefined
5
5
  */
package/types/index.d.mts CHANGED
@@ -1,14 +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
- export { QFIFO } from "./src/class/QFIFO.mjs";
5
- export { QUnique } from "./src/class/QUnique.mjs";
6
6
  export { Signal } from "./src/class/Signal.mjs";
7
- export { New$ } from "./src/function/New$.mjs";
8
- export { NewDerived } from "./src/function/NewDerived.mjs";
9
- export { NewPingFIFO } from "./src/function/NewPingFIFO.mjs";
10
- export { NewPingUnique } from "./src/function/NewPingUnique.mjs";
11
- export { NewSignal } from "./src/function/NewSignal.mjs";
12
- export { tryAsync } from "./src/function/tryAsync.export.mjs";
13
- export { trySync } from "./src/function/trySync.export.mjs";
14
- 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;
@@ -1,7 +1,20 @@
1
1
  /**
2
2
  * @description
3
3
  * - a class to `autosubscribe` to an signal changes (`Derived` and `Signal` alike);
4
- * - for minimal total bundle size use `function` [New$](#new$) instead;
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
  /**
@@ -24,15 +37,19 @@ export class $ {
24
37
  */
25
38
  static isRegistering: boolean;
26
39
  /**
27
- * @param {$["effect"]} effect
40
+ * @param {(arg:{remove$:$["remove$"]})=>void} effect
28
41
  */
29
- constructor(effect: $["effect"]);
42
+ constructor(effect: (arg: {
43
+ remove$: $["remove$"];
44
+ }) => void);
30
45
  /**
31
46
  * @returns {void}
32
47
  */
33
48
  remove$: () => void;
34
49
  /**
35
- * @type {()=>void}
50
+ * @type {(arg:{remove$:$["remove$"]})=>void};
36
51
  */
37
- effect: () => void;
52
+ effect: (arg: {
53
+ remove$: $["remove$"];
54
+ }) => void;
38
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
- * - can be subscribed by using [New$](#new$);
5
- * - for minimal total bundle size use `function` [NewDerived](#newderived) instead;
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: () => V);
26
+ constructor(derivedFunction: (arg: {
27
+ remove$: $["remove$"];
28
+ }) => V);
16
29
  }
17
30
  import { Signal } from './Signal.mjs';
31
+ import { $ } from './$.mjs';
@@ -6,42 +6,52 @@
6
6
  * *[blank]/
7
7
  * ```
8
8
  * - a class for Queue;
9
- * - for minimal total bundle size use `function` [NewPingFIFO](#newpingfifo) instead;
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
+ * ```
10
20
  * - this class provides `QFIFO.makeQClass`;
11
21
  * >- this method will setup `QFIFO` to use the inputed `queueArray`(as arg0) as centralized lookup for queue managed by `QFIFO`;
12
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;
13
23
  */
14
- export class QFIFO {
24
+ export class PingFIFO {
15
25
  /**
16
26
  * @param {queueFIFODetails[]} queueArray
17
- * @returns {typeof QFIFO}
27
+ * @returns {typeof PingFIFO}
18
28
  */
19
- static makeQClass: (queueArray: queueFIFODetails[]) => typeof QFIFO;
29
+ static makeQClass: (queueArray: queueFIFODetails[]) => typeof PingFIFO;
20
30
  /**
21
31
  * @type {queueFIFODetails[]}
22
32
  */
23
- static "__#1@#queue": queueFIFODetails[];
33
+ static "__#3@#queue": queueFIFODetails[];
24
34
  /**
25
35
  * @type {boolean}
26
36
  */
27
- static "__#1@#isRunning": boolean;
37
+ static "__#3@#isRunning": boolean;
28
38
  /**
29
- * @type {(...queueFIFODetails:queueFIFODetails)=>void}
39
+ * @param {queueFIFODetails} _queue
30
40
  */
31
- static assign: (...queueFIFODetails: queueFIFODetails) => void;
41
+ static "__#3@#push": (_queue: queueFIFODetails) => void;
42
+ static "__#3@#run": () => Promise<void>;
32
43
  /**
33
- * @param {queueFIFODetails} _queue
44
+ * @param {()=>(any|Promise<any>)} callback
45
+ * @param {number} [debounce]
34
46
  */
35
- static "__#1@#push": (_queue: queueFIFODetails) => void;
36
- static "__#1@#run": () => Promise<void>;
47
+ constructor(callback: () => (any | Promise<any>), debounce?: number);
37
48
  }
38
49
  /**
39
50
  * *[blank]/
40
51
  * ```
41
52
  * - 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;
53
+ * - function to auto queue callbacks that will be called `first in first out` style;
54
+ * ```js
55
+ * //
46
56
  */
47
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
+ }
@@ -34,12 +34,12 @@ export class Q {
34
34
  */
35
35
  static makeQClass: (uniqueMap: Map<any, Promise<any>>) => typeof Q;
36
36
  /**
37
- * @typedef {import('../types/anyButUndefined.type.mjs').anyButUndefined} anyButUndefined
37
+ * @typedef {import('../types/AnyButUndefined.type.mjs').AnyButUndefined} anyButUndefined
38
38
  */
39
39
  /**
40
40
  * @type {Promise<void>}
41
41
  */
42
- static "__#3@#fifo": Promise<void>;
42
+ static "__#1@#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,14 +50,14 @@ export class Q {
50
50
  /**
51
51
  * @type {Map<any, Promise<any>>}
52
52
  */
53
- static "__#3@#unique": Map<any, Promise<any>>;
53
+ static "__#1@#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.
57
57
  * @param {anyButUndefined} id
58
58
  * @returns {Promise<{resume:()=>void}>} Resolves when it's safe to proceed for the given id, returning a cleanup function
59
59
  */
60
- static unique: (id: import("../types/anyButUndefined.type.mjs").anyButUndefined) => Promise<{
60
+ static unique: (id: import("../types/AnyButUndefined.type.mjs").AnyButUndefined) => Promise<{
61
61
  resume: () => void;
62
62
  }>;
63
63
  }
@@ -1,8 +1,19 @@
1
1
  /**
2
2
  * @description
3
3
  * - a class for creating signal;
4
- * - can be subscribed by using [New$](#new$) or [NewDerived](#newderived);
5
- * - for minimal total bundle size use `function` [NewSignal](#newSignal) instead;
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
@@ -0,0 +1 @@
1
+ export function NewQBlock(asyncCallaback: () => Promise<void>, objectReferenceID?: any): void;
@@ -1 +1 @@
1
- export function tryAsync<ResultType>(asyncFunction_: () => Promise<ResultType>): Promise<[ResultType | undefined, Error | undefined]>;
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;
@@ -1,75 +0,0 @@
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
- }
@@ -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);
@@ -1,24 +0,0 @@
1
- // @ts-check
2
-
3
- import { QFIFO } from '../class/QFIFO.mjs';
4
-
5
- /**
6
- * @description
7
- * - function to auto queue callbacks that will be called `first in first out` style;
8
- * ```js
9
- * // @ts-check
10
- * import { NewPingFIFO } from 'vivth';
11
- * const debounceMS = 0; // in miliseconds, optionals, default is 0;
12
- * const handler = () =>{
13
- * NewPingFIFO(async () => {
14
- * // your code
15
- * }, debounceMS);
16
- * }
17
- * ```
18
- */
19
- /**
20
- * @param {()=>(any|Promise<any>)} callback
21
- * @param {number} debounce
22
- * @returns
23
- */
24
- export const NewPingFIFO = (callback, debounce = 0) => QFIFO.assign(callback, debounce);
@@ -1,29 +0,0 @@
1
- // @ts-check
2
-
3
- import { QUnique } from '../../index.mjs';
4
-
5
- /**
6
- * @description
7
- * - function to auto queue callbacks:
8
- * > - different `uniqueID`: called `first in first out` style;
9
- * > - same `uniqueID`: will be grouped, only the already running callback and the last callback will be called;
10
- * ```js
11
- * // @ts-check
12
- * import { NewPingUnique } from 'vivth';
13
- * const uniqueID = 'yourUniqueID'; // can be anything, even a reference to an object;
14
- * const debounceMS = 0; // in miliseconds, optionals, default is 0;
15
- * const handler = () =>{
16
- * NewPingUnique(uniqueID, async () => {
17
- * // your code
18
- * }, debounceMS);
19
- * }
20
- * ```
21
- */
22
- /**
23
- * @param {import('../../index.mjs').anyButUndefined} uniqueID
24
- * @param {()=>(any|Promise<any>)} callback
25
- * @param {number} debounce
26
- * @returns
27
- */
28
- export const NewPingUnique = (uniqueID, callback, debounce = 0) =>
29
- QUnique.assign({ i: uniqueID, c: callback, d: debounce });
@@ -1,28 +0,0 @@
1
- // @ts-check
2
-
3
- import { Signal } from '../class/Signal.mjs';
4
-
5
- /**
6
- * @description
7
- * - function to create `signal`;
8
- * - syntatic sugar for [Signal](#signal);
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
- * });
20
- * signal.value = 1;
21
- * ```
22
- */
23
- /**
24
- * @template Value
25
- * @param {Value} value
26
- * @returns {Signal<Value>}
27
- */
28
- export const NewSignal = (value) => new Signal(value);
@@ -1,46 +0,0 @@
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 "__#4@#queue": Map<any, [() => Promise<any>, number]>;
25
- /**
26
- * @type {boolean}
27
- */
28
- static "__#4@#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 "__#4@#push": (_queue: {
41
- i: any;
42
- c: () => (any | Promise<any>);
43
- d?: number;
44
- }) => void;
45
- static "__#4@#run": () => Promise<void>;
46
- }
@@ -1,2 +0,0 @@
1
- export function New$(effect: () => void): $;
2
- import { $ } from '../class/$.mjs';
@@ -1,2 +0,0 @@
1
- export function NewDerived<V>(derivedFunction: () => (V)): Derived<V>;
2
- import { Derived } from '../class/Derived.mjs';
@@ -1 +0,0 @@
1
- export function NewPingFIFO(callback: () => (any | Promise<any>), debounce?: number): void;
@@ -1 +0,0 @@
1
- export function NewPingUnique(uniqueID: import("../../index.mjs").anyButUndefined, callback: () => (any | Promise<any>), debounce?: number): void;
@@ -1,2 +0,0 @@
1
- export function NewSignal<Value>(value: Value): Signal<Value>;
2
- import { Signal } from '../class/Signal.mjs';
@@ -1 +0,0 @@
1
- export function trySync<ResultType>(function_: () => ResultType): [ResultType | undefined, Error | undefined];
@@ -1 +0,0 @@
1
- export type anyButUndefined = {} | null | number | string | boolean | symbol | bigint | Function;