vivth 0.10.0 → 0.11.1

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