vivth 0.11.1 → 1.0.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 (107) hide show
  1. package/.vivth/dist/init.mjs +24 -0
  2. package/README.md +2157 -69
  3. package/README.src.md +35 -0
  4. package/bun.lock +57 -3
  5. package/dev/index.mjs +24 -25
  6. package/index.mjs +51 -29
  7. package/package.json +11 -7
  8. package/src/bundler/CompileMJS.mjs +110 -0
  9. package/src/bundler/EsBundler.mjs +79 -0
  10. package/src/class/Console.mjs +62 -0
  11. package/src/class/Derived.mjs +37 -21
  12. package/src/class/Effect.mjs +106 -0
  13. package/src/class/EnvSignal.mjs +88 -0
  14. package/src/class/EventSignal.mjs +200 -0
  15. package/src/class/ListDerived.mjs +39 -0
  16. package/src/class/ListSignal.mjs +256 -0
  17. package/src/class/Paths.mjs +70 -0
  18. package/src/class/QChannel.mjs +184 -0
  19. package/src/class/SafeExit.mjs +131 -0
  20. package/src/class/Setup.mjs +73 -0
  21. package/src/class/Signal.mjs +152 -54
  22. package/src/class/WorkerMainThread.mjs +328 -0
  23. package/src/class/WorkerResult.mjs +30 -0
  24. package/src/class/WorkerThread.mjs +151 -0
  25. package/src/common/Base64URL.mjs +26 -0
  26. package/src/common/EventNameSpace.mjs +8 -0
  27. package/src/common/eventObjects.mjs +5 -0
  28. package/src/common/lazie.mjs +3 -0
  29. package/src/doc/JSautoDOC.mjs +386 -0
  30. package/src/doc/parsedFile.mjs +537 -0
  31. package/src/function/CreateImmutable.mjs +64 -0
  32. package/src/function/EventCheck.mjs +27 -0
  33. package/src/function/EventObject.mjs +21 -0
  34. package/src/function/IsAsync.mjs +23 -0
  35. package/src/function/LazyFactory.mjs +71 -0
  36. package/src/function/Timeout.mjs +23 -0
  37. package/src/function/Try.mjs +64 -0
  38. package/src/function/TryAsync.mjs +15 -4
  39. package/src/function/TrySync.mjs +9 -4
  40. package/src/function/TsToMjs.mjs +67 -0
  41. package/src/function/WriteFileSafe.mjs +37 -0
  42. package/src/types/{AnyButUndefined.type.mjs → AnyButUndefined.mjs} +1 -0
  43. package/src/types/ExtnameType.mjs +6 -0
  44. package/src/types/IsListSignal.mjs +6 -0
  45. package/src/types/ListArg.mjs +6 -0
  46. package/src/types/MutationType.mjs +8 -0
  47. package/src/types/QCBFIFOReturn.mjs +6 -0
  48. package/src/types/QCBReturn.mjs +6 -0
  49. package/tsconfig.json +3 -3
  50. package/types/dev/index.d.mts +1 -0
  51. package/types/index.d.mts +34 -8
  52. package/types/src/bundler/A.d.mts +1 -0
  53. package/types/src/bundler/CompileMJS.d.mts +8 -0
  54. package/types/src/bundler/EsBundler.d.mts +7 -0
  55. package/types/src/class/Console.d.mts +40 -0
  56. package/types/src/class/Derived.d.mts +21 -7
  57. package/types/src/class/Effect.d.mts +77 -0
  58. package/types/src/class/EnvSignal.d.mts +47 -0
  59. package/types/src/class/EventSignal.d.mts +145 -0
  60. package/types/src/class/ListDerived.d.mts +35 -0
  61. package/types/src/class/ListSignal.d.mts +150 -0
  62. package/types/src/class/Paths.d.mts +50 -0
  63. package/types/src/class/QChannel.d.mts +115 -0
  64. package/types/src/class/SafeExit.d.mts +76 -0
  65. package/types/src/class/Setup.d.mts +76 -0
  66. package/types/src/class/Signal.d.mts +105 -26
  67. package/types/src/class/WorkerMainThread.d.mts +149 -0
  68. package/types/src/class/WorkerResult.d.mts +25 -0
  69. package/types/src/class/WorkerThread.d.mts +70 -0
  70. package/types/src/common/Base64URL.d.mts +1 -0
  71. package/types/src/common/EventNameSpace.d.mts +6 -0
  72. package/types/src/common/eventObjects.d.mts +3 -0
  73. package/types/src/common/lazie.d.mts +1 -0
  74. package/types/src/doc/JSautoDOC.d.mts +76 -0
  75. package/types/src/doc/parsedFile.d.mts +154 -0
  76. package/types/src/function/CreateImmutable.d.mts +3 -0
  77. package/types/src/function/EventCheck.d.mts +2 -0
  78. package/types/src/function/EventObject.d.mts +4 -0
  79. package/types/src/function/IsAsync.d.mts +1 -0
  80. package/types/src/function/LazyFactory.d.mts +4 -0
  81. package/types/src/function/Timeout.d.mts +1 -0
  82. package/types/src/function/Try.d.mts +1 -0
  83. package/types/src/function/TsToMjs.d.mts +4 -0
  84. package/types/src/function/WriteFileSafe.d.mts +2 -0
  85. package/types/src/types/{AnyButUndefined.type.d.mts → AnyButUndefined.d.mts} +3 -0
  86. package/types/src/types/ExtnameType.d.mts +4 -0
  87. package/types/src/types/IsListSignal.d.mts +4 -0
  88. package/types/src/types/ListArg.d.mts +4 -0
  89. package/types/src/types/MutationType.d.mts +5 -0
  90. package/types/src/types/QCBFIFOReturn.d.mts +4 -0
  91. package/types/src/types/QCBReturn.d.mts +7 -0
  92. package/src/class/$.mjs +0 -68
  93. package/src/class/PingFIFO.mjs +0 -78
  94. package/src/class/PingUnique.mjs +0 -84
  95. package/src/class/Q.mjs +0 -98
  96. package/src/class/QFIFO.mjs +0 -66
  97. package/src/class/QUnique.mjs +0 -75
  98. package/src/common.mjs +0 -16
  99. package/src/function/NewQBlock.mjs +0 -39
  100. package/types/src/class/$.d.mts +0 -38
  101. package/types/src/class/PingFIFO.d.mts +0 -57
  102. package/types/src/class/PingUnique.d.mts +0 -48
  103. package/types/src/class/Q.d.mts +0 -63
  104. package/types/src/class/QFIFO.d.mts +0 -47
  105. package/types/src/class/QUnique.d.mts +0 -46
  106. package/types/src/common.d.mts +0 -2
  107. package/types/src/function/NewQBlock.d.mts +0 -1
@@ -0,0 +1,4 @@
1
+ export function TsToMjs(path_: string, { overrideDir, encoding }?: {
2
+ overrideDir?: string;
3
+ encoding?: BufferEncoding;
4
+ }): Promise<void>;
@@ -0,0 +1,2 @@
1
+ export function WriteFileSafe(outFile: string, content: string, options: import("node:fs").WriteFileOptions): Promise<ReturnType<typeof TryAsync<void>>>;
2
+ import { TryAsync } from './TryAsync.mjs';
@@ -1 +1,4 @@
1
+ /**
2
+ * - type helper for ID or objects;
3
+ */
1
4
  export type AnyButUndefined = {} | null | number | string | boolean | symbol | bigint | Function;
@@ -0,0 +1,4 @@
1
+ /**
2
+ * - jsRuntime extention naming convention;
3
+ */
4
+ export type ExtnameType = `.${string}`;
@@ -0,0 +1,4 @@
1
+ /**
2
+ * - `EnvSignal.get` argument whether signal need to be a list or not;
3
+ */
4
+ export type IsListSignal = boolean;
@@ -0,0 +1,4 @@
1
+ /**
2
+ * - ListSignal argument type;
3
+ */
4
+ export type ListArg = Record<string, string>;
@@ -0,0 +1,5 @@
1
+ /**
2
+ * - instance method: serves as helper to mutate, and notify for `effects`;
3
+ * > - `slice` uses `splice` in the background, you don't need to manually reindex when using it;
4
+ */
5
+ export type MutationType = "push" | "unshift" | "splice" | "swap" | "modify" | "shift" | "remove";
@@ -0,0 +1,4 @@
1
+ /**
2
+ * - return type of Q callback fifo;
3
+ */
4
+ export type QCBFIFOReturn = Omit<import("./QCBReturn.mjs").QCBReturn, "isLastOnQ">;
@@ -0,0 +1,7 @@
1
+ /**
2
+ * - return type of Q callback;
3
+ */
4
+ export type QCBReturn = {
5
+ resume: () => void;
6
+ isLastOnQ: boolean;
7
+ };
package/src/class/$.mjs DELETED
@@ -1,68 +0,0 @@
1
- // @ts-check
2
-
3
- import { PingFIFO } from './PingFIFO.mjs';
4
- import { isAsync } from '../common.mjs';
5
-
6
- /**
7
- * @description
8
- * - a class to `autosubscribe` to an signal changes (`Derived` and `Signal` alike);
9
- * - for minimal total bundle size use `function` [New$](#new$) instead;
10
- */
11
- export class $ {
12
- /**
13
- * @typedef {import('../class/Signal.mjs').Signal} Signal
14
- */
15
- /**
16
- * @type {Map<$, Set<Signal>>}
17
- */
18
- static effects = new Map();
19
- /**
20
- * @type {Map<Signal, Set<$>>}
21
- */
22
- static mappedSignals = new Map();
23
- /**
24
- * @type {Set<Signal>}
25
- */
26
- static activeSignal = new Set();
27
- /**
28
- * @type {boolean}
29
- */
30
- static isRegistering = false;
31
- /**
32
- * @returns {void}
33
- */
34
- remove$ = () => {
35
- $.effects.get(this)?.forEach((signalInstance) => {
36
- $.mappedSignals.get(signalInstance).delete(this);
37
- });
38
- $.effects.set(this, new Set());
39
- };
40
- /**
41
- * @type {()=>void}
42
- */
43
- effect;
44
- /**
45
- * @param {$["effect"]} effect
46
- */
47
- constructor(effect) {
48
- this.effect = effect;
49
- new PingFIFO(async () => {
50
- $.isRegistering = true;
51
- if (isAsync(effect)) {
52
- await effect();
53
- } else {
54
- effect();
55
- }
56
- $.isRegistering = false;
57
- const signalInstances = $.activeSignal;
58
- $.effects.set(this, $.activeSignal);
59
- signalInstances.forEach((signal) => {
60
- if (!$.mappedSignals.has(signal)) {
61
- $.mappedSignals.set(signal, new Set());
62
- }
63
- $.mappedSignals.get(signal).add(this);
64
- });
65
- $.activeSignal = new Set();
66
- });
67
- }
68
- }
@@ -1,78 +0,0 @@
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
- }
@@ -1,84 +0,0 @@
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 DELETED
@@ -1,98 +0,0 @@
1
- // @ts-check
2
-
3
- /**
4
- * @description
5
- * - class that containts static methods to generate Promise based `awaiter` inside async function, to prevent race condition, including but not limited to:
6
- * > - modifying the same `Map`, `Set`(etc.) `Object`/`Instance` inside a `Promise.all`/any code that might fired simultanously;
7
- * ```js
8
- * import { Q } from 'vivth';
9
- *
10
- * const handler = async () => {
11
- * // your code;
12
- * const { resume } = await Q.fifo() // or await Q.unique(uniqueID);
13
- * // your code that modifies and/or access same `Map`;
14
- * resume();
15
- * // the rest of your code;
16
- * return;
17
- * }
18
- *
19
- * const runtime = async () => {
20
- * // await Promise.all(handler1, handler2, ..., handlern);
21
- * }
22
- *
23
- * runtime();
24
- * ```
25
- * - behaviour:
26
- * > - `fifo`: call all queued callback `first in first out` style;
27
- * > - `unique`: call all queued callback with the same `uniqueID` `first in first out` style, if the `uniqueID` is different it will be called in parallel;
28
- * - this class provides `Q.makeQClass`;
29
- * >- this method will setup `Q` to use the inputed `uniqueMap`(as arg0) as centralized lookup for queue managed by `Q`;
30
- * >- usefull to modify this class for browser runtime, since `vivth` cannot just refer to window, you can just add `window["someobject"]`: `Array<Map<any, Promise<any>>>` as lookups;
31
- */
32
- export class Q {
33
- /**
34
- * @param {Map<any, Promise<any>>} uniqueMap
35
- * @returns {typeof Q}
36
- */
37
- static makeQClass = (uniqueMap) => {
38
- Q.#unique = uniqueMap;
39
- return Q;
40
- };
41
- /**
42
- * @typedef {import('../types/AnyButUndefined.type.mjs').AnyButUndefined} anyButUndefined
43
- */
44
- /**
45
- * @type {Promise<void>}
46
- */
47
- static #fifo = Promise.resolve();
48
- /**
49
- * Blocks execution for subsequent calls until the current one finishes.
50
- * @returns {Promise<{resume:()=>void}>} Resolves when it's safe to proceed, returning a cleanup function
51
- */
52
- static fifo = async () => {
53
- let resolveFn;
54
- const next = new Promise((resolve) => {
55
- resolveFn = resolve;
56
- });
57
- const prev = Q.#fifo;
58
- Q.#fifo = next;
59
- await prev;
60
- return {
61
- resume: () => {
62
- resolveFn(); // Resolve the current task
63
- },
64
- };
65
- };
66
- /**
67
- * @type {Map<any, Promise<any>>}
68
- */
69
- static #unique = new Map();
70
- /**
71
- * Ensures that each id has only one task running at a time.
72
- * Calls with the same id will wait for the previous call to finish.
73
- * @param {anyButUndefined} id
74
- * @returns {Promise<{resume:()=>void}>} Resolves when it's safe to proceed for the given id, returning a cleanup function
75
- */
76
- static unique = async (id) => {
77
- if (!Q.#unique.has(id)) {
78
- Q.#unique.set(id, Promise.resolve());
79
- let resolveFn;
80
- const next = new Promise((resolve) => {
81
- resolveFn = resolve;
82
- });
83
- const prev = Q.#unique.get(id);
84
- Q.#unique.set(id, next);
85
- await prev;
86
- return {
87
- resume: () => {
88
- resolveFn();
89
- Q.#unique.delete(id);
90
- },
91
- };
92
- } else {
93
- const prev = Q.#unique.get(id);
94
- await prev;
95
- return await Q.unique(id);
96
- }
97
- };
98
- }
@@ -1,66 +0,0 @@
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
- }
@@ -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
- }
package/src/common.mjs DELETED
@@ -1,16 +0,0 @@
1
- // @ts-check
2
-
3
- /**
4
- * @param {number} ms
5
- * @returns {Promise<void>}
6
- */
7
- export const timeout = (ms) =>
8
- new Promise((resolve) => {
9
- setTimeout(resolve, ms);
10
- });
11
-
12
- /**
13
- * @param {(...any:any)=>(any|Promise<any>)} fn
14
- * @returns {boolean}
15
- */
16
- export const isAsync = (fn) => fn.constructor.name === 'AsyncFunction';
@@ -1,39 +0,0 @@
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
- };
@@ -1,38 +0,0 @@
1
- /**
2
- * @description
3
- * - a class to `autosubscribe` to an signal changes (`Derived` and `Signal` alike);
4
- * - for minimal total bundle size use `function` [New$](#new$) instead;
5
- */
6
- export class $ {
7
- /**
8
- * @typedef {import('../class/Signal.mjs').Signal} Signal
9
- */
10
- /**
11
- * @type {Map<$, Set<Signal>>}
12
- */
13
- static effects: Map<$, Set<import("../class/Signal.mjs").Signal<any>>>;
14
- /**
15
- * @type {Map<Signal, Set<$>>}
16
- */
17
- static mappedSignals: Map<import("../class/Signal.mjs").Signal<any>, Set<$>>;
18
- /**
19
- * @type {Set<Signal>}
20
- */
21
- static activeSignal: Set<import("../class/Signal.mjs").Signal<any>>;
22
- /**
23
- * @type {boolean}
24
- */
25
- static isRegistering: boolean;
26
- /**
27
- * @param {$["effect"]} effect
28
- */
29
- constructor(effect: $["effect"]);
30
- /**
31
- * @returns {void}
32
- */
33
- remove$: () => void;
34
- /**
35
- * @type {()=>void}
36
- */
37
- effect: () => void;
38
- }
@@ -1,57 +0,0 @@
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)];