vivth 1.1.2 → 1.2.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.
- package/README.md +1215 -433
- package/README.src.md +5 -2
- package/bun.lock +228 -0
- package/index.mjs +17 -4
- package/package.json +6 -3
- package/src/bundler/CompileJS.mjs +258 -0
- package/src/bundler/CreateESPlugin.mjs +24 -0
- package/src/bundler/EsBundler.mjs +27 -13
- package/src/bundler/FSInline.mjs +57 -0
- package/src/bundler/FSInlineAnalyzer.mjs +197 -0
- package/src/bundler/FSInlineBundled.mjs +34 -0
- package/src/bundler/adds/ToBundledJSPlugin.mjs +77 -0
- package/src/bundler/adds/externals.mjs +8 -0
- package/src/bundler/adds/pluginVivthBundle.mjs +5 -0
- package/src/class/Console.mjs +48 -27
- package/src/class/Derived.mjs +55 -7
- package/src/class/Effect.mjs +100 -39
- package/src/class/EnvSignal.mjs +5 -5
- package/src/class/EventSignal.mjs +55 -5
- package/src/class/FileSafe.mjs +124 -0
- package/src/class/ListDerived.mjs +6 -3
- package/src/class/ListSignal.mjs +11 -11
- package/src/class/LitExp.mjs +405 -0
- package/src/class/Paths.mjs +27 -1
- package/src/class/QChannel.mjs +79 -28
- package/src/class/SafeExit.mjs +31 -11
- package/src/class/Setup.mjs +5 -2
- package/src/class/Signal.mjs +26 -24
- package/src/class/WorkerMainThread.mjs +100 -133
- package/src/class/WorkerMainThreadBundled.mjs +216 -0
- package/src/class/WorkerThread.mjs +38 -32
- package/src/common/Base64URL.mjs +10 -5
- package/src/common/Base64URLFromFile.mjs +24 -0
- package/src/common/keys.mjs +3 -0
- package/src/doc/JSautoDOC.mjs +32 -56
- package/src/doc/parsedFile.mjs +37 -36
- package/src/function/CreateImmutable.mjs +9 -9
- package/src/function/EventCheck.mjs +2 -2
- package/src/function/EventObject.mjs +5 -5
- package/src/function/GetRuntime.mjs +38 -0
- package/src/function/IsAsync.mjs +2 -2
- package/src/function/LazyFactory.mjs +13 -13
- package/src/function/Timeout.mjs +2 -2
- package/src/function/Try.mjs +17 -12
- package/src/function/TryAsync.mjs +5 -5
- package/src/function/TrySync.mjs +5 -5
- package/src/function/TsToMjs.mjs +5 -4
- package/src/types/LitExpKeyType.mjs +5 -0
- package/src/types/QCBReturn.mjs +1 -1
- package/src/types/Runtime.mjs +7 -0
- package/types/dev/fsInline.d.mts +1 -0
- package/types/dev/test.d.mts +1 -0
- package/types/dev/testWorker.d.mts +7 -0
- package/types/dev/testbundle.d.mts +1 -0
- package/types/dev/workerThreadClass.d.mts +13 -0
- package/types/index.d.mts +13 -4
- package/types/src/bundler/CompileJS.d.mts +78 -0
- package/types/src/bundler/CreateESPlugin.d.mts +17 -0
- package/types/src/bundler/EsBundler.d.mts +33 -4
- package/types/src/bundler/FSInline.d.mts +43 -0
- package/types/src/bundler/FSInlineAnalyzer.d.mts +36 -0
- package/types/src/bundler/FSInlineBundled.d.mts +22 -0
- package/types/src/bundler/adds/ToBundledJSPlugin.d.mts +16 -0
- package/types/src/bundler/adds/externals.d.mts +1 -0
- package/types/src/bundler/adds/pluginVivthBundle.d.mts +1 -0
- package/types/src/class/Console.d.mts +36 -5
- package/types/src/class/Derived.d.mts +132 -5
- package/types/src/class/Effect.d.mts +106 -7
- package/types/src/class/EnvSignal.d.mts +8 -8
- package/types/src/class/EventSignal.d.mts +151 -7
- package/types/src/class/FileSafe.d.mts +90 -0
- package/types/src/class/ListDerived.d.mts +8 -5
- package/types/src/class/ListSignal.d.mts +123 -18
- package/types/src/class/LitExp.d.mts +361 -0
- package/types/src/class/Paths.d.mts +18 -1
- package/types/src/class/QChannel.d.mts +69 -22
- package/types/src/class/SafeExit.d.mts +24 -9
- package/types/src/class/Setup.d.mts +6 -5
- package/types/src/class/Signal.d.mts +73 -17
- package/types/src/class/WorkerMainThread.d.mts +39 -37
- package/types/src/class/WorkerMainThreadBundled.d.mts +85 -0
- package/types/src/class/WorkerThread.d.mts +32 -27
- package/types/src/common/Base64URL.d.mts +22 -1
- package/types/src/common/Base64URLFromFile.d.mts +16 -0
- package/types/src/common/keys.d.mts +1 -0
- package/types/src/doc/JSautoDOC.d.mts +3 -19
- package/types/src/doc/parsedFile.d.mts +72 -13
- package/types/src/function/CreateImmutable.d.mts +27 -2
- package/types/src/function/EventCheck.d.mts +15 -0
- package/types/src/function/EventObject.d.mts +17 -2
- package/types/src/function/GetRuntime.d.mts +2 -0
- package/types/src/function/IsAsync.d.mts +18 -0
- package/types/src/function/LazyFactory.d.mts +35 -2
- package/types/src/function/Timeout.d.mts +16 -0
- package/types/src/function/Try.d.mts +52 -1
- package/types/src/function/TryAsync.d.mts +22 -1
- package/types/src/function/TrySync.d.mts +16 -1
- package/types/src/function/TsToMjs.d.mts +19 -0
- package/types/src/types/LitExpKeyType.d.mts +1 -0
- package/types/src/types/QCBReturn.d.mts +1 -1
- package/types/src/types/Runtime.d.mts +1 -0
- package/dev/index.mjs +0 -28
- package/src/bundler/CompileMJS.mjs +0 -110
- package/src/function/WriteFileSafe.mjs +0 -37
- package/types/src/bundler/A.d.mts +0 -1
- package/types/src/bundler/CompileMJS.d.mts +0 -8
- package/types/src/function/WriteFileSafe.d.mts +0 -2
|
@@ -1,40 +1,71 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @description
|
|
3
|
-
* - class with static methods to print to standard console with
|
|
3
|
+
* - class with static methods to print to standard console with bare minimum ANSI styles;
|
|
4
4
|
*/
|
|
5
5
|
export class Console {
|
|
6
|
+
static #ansi: {
|
|
7
|
+
reset: string;
|
|
8
|
+
bold: string;
|
|
9
|
+
colors: {
|
|
10
|
+
log: string;
|
|
11
|
+
info: string;
|
|
12
|
+
warn: string;
|
|
13
|
+
error: string;
|
|
14
|
+
};
|
|
15
|
+
};
|
|
6
16
|
/**
|
|
7
17
|
* @param {string} prefix
|
|
8
18
|
* @param {'log'|'info'|'error'|'warn'} mode
|
|
9
|
-
* - Console method to use
|
|
10
19
|
* @param {any} data
|
|
11
|
-
* @param {string} color
|
|
12
|
-
* @param {string} bgcolor
|
|
13
20
|
* @returns {void}
|
|
14
21
|
*/
|
|
15
|
-
static #call: (prefix: string, mode: "log" | "info" | "error" | "warn", data: any
|
|
22
|
+
static #call: (prefix: string, mode: "log" | "info" | "error" | "warn", data: any) => void;
|
|
16
23
|
/**
|
|
17
24
|
* @description
|
|
18
25
|
* @param {any} data
|
|
19
26
|
* @returns {void}
|
|
27
|
+
* @example
|
|
28
|
+
* import { Console } from 'vivth';
|
|
29
|
+
*
|
|
30
|
+
* Console.log({
|
|
31
|
+
* hello: 'world!!',
|
|
32
|
+
* });
|
|
20
33
|
*/
|
|
21
34
|
static log: (data: any) => void;
|
|
22
35
|
/**
|
|
23
36
|
* @description
|
|
24
37
|
* @param {any} data
|
|
25
38
|
* @returns {void}
|
|
39
|
+
* @example
|
|
40
|
+
* import { Console } from 'vivth';
|
|
41
|
+
*
|
|
42
|
+
* Console.info({
|
|
43
|
+
* hello: 'world!!',
|
|
44
|
+
* });
|
|
26
45
|
*/
|
|
27
46
|
static info: (data: any) => void;
|
|
28
47
|
/**
|
|
29
48
|
* @description
|
|
30
49
|
* @param {any} data
|
|
31
50
|
* @returns {void}
|
|
51
|
+
* @example
|
|
52
|
+
* import { Console } from 'vivth';
|
|
53
|
+
*
|
|
54
|
+
* Console.warn({
|
|
55
|
+
* hello: 'world!!',
|
|
56
|
+
* });
|
|
32
57
|
*/
|
|
33
58
|
static warn: (data: any) => void;
|
|
34
59
|
/**
|
|
35
60
|
* @description
|
|
36
61
|
* @param {any} data
|
|
37
62
|
* @returns {void}
|
|
63
|
+
* @example
|
|
64
|
+
* import { Console } from 'vivth';
|
|
65
|
+
*
|
|
66
|
+
* Console.error({
|
|
67
|
+
* hello: 'world!!',
|
|
68
|
+
* });
|
|
38
69
|
*/
|
|
39
70
|
static error: (data: any) => void;
|
|
40
71
|
}
|
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @description
|
|
3
3
|
* - a class for creating derived version of [Signal](#signal);
|
|
4
|
-
* @template
|
|
5
|
-
* @extends Signal<
|
|
4
|
+
* @template VALUE
|
|
5
|
+
* @extends Signal<VALUE>
|
|
6
6
|
*/
|
|
7
|
-
export class Derived<
|
|
7
|
+
export class Derived<VALUE> extends Signal<VALUE> {
|
|
8
8
|
/**
|
|
9
9
|
* @description
|
|
10
10
|
* - Derived used [Signal](#signal) and [Effect](#effect) under the hood;
|
|
11
|
-
* @param {(effectInstanceOptions:Effect["options"]
|
|
11
|
+
* @param {(effectInstanceOptions:Omit<Effect["options"] &
|
|
12
|
+
* Derived["options"], unwrapLazy>) =>
|
|
13
|
+
* Promise<VALUE>} derivedFunction
|
|
12
14
|
* @example
|
|
13
15
|
* import { Signal, Derived } from 'vivth';
|
|
14
16
|
*
|
|
@@ -25,7 +27,132 @@ export class Derived<V> extends Signal<V> {
|
|
|
25
27
|
*
|
|
26
28
|
* count.value++;
|
|
27
29
|
*/
|
|
28
|
-
constructor(derivedFunction: (effectInstanceOptions: Effect["options"]
|
|
30
|
+
constructor(derivedFunction: (effectInstanceOptions: Omit<Effect["options"] & ({
|
|
31
|
+
/**
|
|
32
|
+
* @instance options
|
|
33
|
+
* @description
|
|
34
|
+
* - return this value tandem with `isLastCalled`, to not to update the value of this instance, even when returning early;
|
|
35
|
+
* @type {Object}
|
|
36
|
+
* @example
|
|
37
|
+
* import { Signal, Derived } from 'vivth';
|
|
38
|
+
*
|
|
39
|
+
* const count = new Signal(0);
|
|
40
|
+
* const double = new Derived(async({
|
|
41
|
+
* subscribe,
|
|
42
|
+
* dontUpdate,
|
|
43
|
+
* isLastCalled,
|
|
44
|
+
* }) => {
|
|
45
|
+
* const currentValue = subscribe(count).value;
|
|
46
|
+
* if (!(await isLastCalled(10))) {
|
|
47
|
+
* return dontUpdate;
|
|
48
|
+
* }
|
|
49
|
+
* const res = await fetch(`some/path/${curentValue.toString()}`);
|
|
50
|
+
* if (!(await isLastCalled())) {
|
|
51
|
+
* return dontUpdate; // this will prevent race condition, even if the earlier fetch return late;
|
|
52
|
+
* }
|
|
53
|
+
* return res;
|
|
54
|
+
* });
|
|
55
|
+
*
|
|
56
|
+
* count.value++;
|
|
57
|
+
*/
|
|
58
|
+
dontUpdate: any;
|
|
59
|
+
} & {
|
|
60
|
+
"vivth:unwrapLazy;": () => {
|
|
61
|
+
/**
|
|
62
|
+
* @instance options
|
|
63
|
+
* @description
|
|
64
|
+
* - return this value tandem with `isLastCalled`, to not to update the value of this instance, even when returning early;
|
|
65
|
+
* @type {Object}
|
|
66
|
+
* @example
|
|
67
|
+
* import { Signal, Derived } from 'vivth';
|
|
68
|
+
*
|
|
69
|
+
* const count = new Signal(0);
|
|
70
|
+
* const double = new Derived(async({
|
|
71
|
+
* subscribe,
|
|
72
|
+
* dontUpdate,
|
|
73
|
+
* isLastCalled,
|
|
74
|
+
* }) => {
|
|
75
|
+
* const currentValue = subscribe(count).value;
|
|
76
|
+
* if (!(await isLastCalled(10))) {
|
|
77
|
+
* return dontUpdate;
|
|
78
|
+
* }
|
|
79
|
+
* const res = await fetch(`some/path/${curentValue.toString()}`);
|
|
80
|
+
* if (!(await isLastCalled())) {
|
|
81
|
+
* return dontUpdate; // this will prevent race condition, even if the earlier fetch return late;
|
|
82
|
+
* }
|
|
83
|
+
* return res;
|
|
84
|
+
* });
|
|
85
|
+
*
|
|
86
|
+
* count.value++;
|
|
87
|
+
*/
|
|
88
|
+
dontUpdate: any;
|
|
89
|
+
};
|
|
90
|
+
}), "vivth:unwrapLazy;">) => Promise<VALUE>);
|
|
91
|
+
/**
|
|
92
|
+
* @description
|
|
93
|
+
* - additional helper to be accessed on effect;
|
|
94
|
+
*/
|
|
95
|
+
options: {
|
|
96
|
+
/**
|
|
97
|
+
* @instance options
|
|
98
|
+
* @description
|
|
99
|
+
* - return this value tandem with `isLastCalled`, to not to update the value of this instance, even when returning early;
|
|
100
|
+
* @type {Object}
|
|
101
|
+
* @example
|
|
102
|
+
* import { Signal, Derived } from 'vivth';
|
|
103
|
+
*
|
|
104
|
+
* const count = new Signal(0);
|
|
105
|
+
* const double = new Derived(async({
|
|
106
|
+
* subscribe,
|
|
107
|
+
* dontUpdate,
|
|
108
|
+
* isLastCalled,
|
|
109
|
+
* }) => {
|
|
110
|
+
* const currentValue = subscribe(count).value;
|
|
111
|
+
* if (!(await isLastCalled(10))) {
|
|
112
|
+
* return dontUpdate;
|
|
113
|
+
* }
|
|
114
|
+
* const res = await fetch(`some/path/${curentValue.toString()}`);
|
|
115
|
+
* if (!(await isLastCalled())) {
|
|
116
|
+
* return dontUpdate; // this will prevent race condition, even if the earlier fetch return late;
|
|
117
|
+
* }
|
|
118
|
+
* return res;
|
|
119
|
+
* });
|
|
120
|
+
*
|
|
121
|
+
* count.value++;
|
|
122
|
+
*/
|
|
123
|
+
dontUpdate: any;
|
|
124
|
+
} & {
|
|
125
|
+
"vivth:unwrapLazy;": () => {
|
|
126
|
+
/**
|
|
127
|
+
* @instance options
|
|
128
|
+
* @description
|
|
129
|
+
* - return this value tandem with `isLastCalled`, to not to update the value of this instance, even when returning early;
|
|
130
|
+
* @type {Object}
|
|
131
|
+
* @example
|
|
132
|
+
* import { Signal, Derived } from 'vivth';
|
|
133
|
+
*
|
|
134
|
+
* const count = new Signal(0);
|
|
135
|
+
* const double = new Derived(async({
|
|
136
|
+
* subscribe,
|
|
137
|
+
* dontUpdate,
|
|
138
|
+
* isLastCalled,
|
|
139
|
+
* }) => {
|
|
140
|
+
* const currentValue = subscribe(count).value;
|
|
141
|
+
* if (!(await isLastCalled(10))) {
|
|
142
|
+
* return dontUpdate;
|
|
143
|
+
* }
|
|
144
|
+
* const res = await fetch(`some/path/${curentValue.toString()}`);
|
|
145
|
+
* if (!(await isLastCalled())) {
|
|
146
|
+
* return dontUpdate; // this will prevent race condition, even if the earlier fetch return late;
|
|
147
|
+
* }
|
|
148
|
+
* return res;
|
|
149
|
+
* });
|
|
150
|
+
*
|
|
151
|
+
* count.value++;
|
|
152
|
+
*/
|
|
153
|
+
dontUpdate: any;
|
|
154
|
+
};
|
|
155
|
+
};
|
|
29
156
|
}
|
|
30
157
|
import { Signal } from './Signal.mjs';
|
|
31
158
|
import { Effect } from './Effect.mjs';
|
|
@@ -14,7 +14,10 @@ export const setOfEffects: Set<Effect>;
|
|
|
14
14
|
export class Effect {
|
|
15
15
|
/**
|
|
16
16
|
* @description
|
|
17
|
-
* @param {(arg0:
|
|
17
|
+
* @param {( arg0:
|
|
18
|
+
* Omit<Effect["options"], typeof unwrapLazy>
|
|
19
|
+
* ) =>
|
|
20
|
+
* Promise<void>} effect
|
|
18
21
|
* @example
|
|
19
22
|
* import { Signal, Derived, Effect, Console } from 'vivth';
|
|
20
23
|
*
|
|
@@ -23,6 +26,7 @@ export class Effect {
|
|
|
23
26
|
* new Effect(async ({
|
|
24
27
|
* subscribe, // : registrar callback for this effect instance, immediately return the signal instance
|
|
25
28
|
* removeEffect, // : disable this effect instance from reacting to dependency changes;
|
|
29
|
+
* isLastCalled, // : check whether this callback run is this instant last called effect;
|
|
26
30
|
* }) => {
|
|
27
31
|
* Console.log(subscribe(double).value); // effect listen to double changes
|
|
28
32
|
* const a = double.value; // no need to wrap double twice with $
|
|
@@ -30,28 +34,63 @@ export class Effect {
|
|
|
30
34
|
*
|
|
31
35
|
* count.value++;
|
|
32
36
|
*/
|
|
33
|
-
constructor(effect: (arg0: Effect["options"]) => Promise<void>);
|
|
37
|
+
constructor(effect: (arg0: Omit<Effect["options"], typeof unwrapLazy>) => Promise<void>);
|
|
38
|
+
/**
|
|
39
|
+
* @typedef {import('../common/lazie.mjs').unwrapLazy} unwrapLazy
|
|
40
|
+
*/
|
|
41
|
+
/**
|
|
42
|
+
* @description
|
|
43
|
+
* - collections of lazy methods to handle effect calls of this instance;
|
|
44
|
+
*/
|
|
34
45
|
options: {
|
|
46
|
+
/**
|
|
47
|
+
* @instance options
|
|
48
|
+
* @description
|
|
49
|
+
* @returns {(timeoutMS?:number)=>Promise<boolean>}
|
|
50
|
+
* - timeoutMS only necessary if the operation doesn't naturally await;
|
|
51
|
+
* - if it's operation such as `fetch`, you can just leave it blank;
|
|
52
|
+
* @example
|
|
53
|
+
*
|
|
54
|
+
* import { Effect } from 'vivth';
|
|
55
|
+
*
|
|
56
|
+
* const effect = new Effect(async ({ isLastCalled }) => {
|
|
57
|
+
* if (!(await isLastCalled(100))) {
|
|
58
|
+
* return;
|
|
59
|
+
* }
|
|
60
|
+
* // OR
|
|
61
|
+
* const res = await fetch('some/path');
|
|
62
|
+
* if (!(await isLastCalled(
|
|
63
|
+
* // no need to add timeoutMS argument, as fetch are naturally add delay;
|
|
64
|
+
* ))) {
|
|
65
|
+
* return;
|
|
66
|
+
* }
|
|
67
|
+
* })
|
|
68
|
+
*/
|
|
69
|
+
readonly isLastCalled: (timeoutMS?: number) => Promise<boolean>;
|
|
35
70
|
/**
|
|
36
71
|
* @instance options
|
|
37
72
|
* @description
|
|
38
73
|
* - normally it's passed as argument to constructor, however it is also accessible from `options` property;
|
|
39
|
-
* @template {Signal}
|
|
40
|
-
* @param {
|
|
41
|
-
* @returns {
|
|
74
|
+
* @template {Signal} SIGNAL
|
|
75
|
+
* @param {SIGNAL} signal
|
|
76
|
+
* @returns {SIGNAL}
|
|
42
77
|
* @example
|
|
78
|
+
* import { Effect } from 'vivth';
|
|
79
|
+
*
|
|
43
80
|
* const effect = new Effect(async () => {
|
|
44
81
|
* // code
|
|
45
82
|
* })
|
|
46
83
|
* effect.options.subscribe(signalInstance);
|
|
47
84
|
*/
|
|
48
|
-
subscribe: <
|
|
85
|
+
subscribe: <SIGNAL extends Signal<any>>(signal: SIGNAL) => SIGNAL;
|
|
49
86
|
/**
|
|
50
87
|
* @instance options
|
|
51
88
|
* @description
|
|
52
89
|
* - normally it's passed as argument to constructor, however it is also accessible from `options` property;
|
|
53
90
|
* @type {()=>void}
|
|
54
91
|
* @example
|
|
92
|
+
* import { Effect } from 'vivth';
|
|
93
|
+
*
|
|
55
94
|
* const effect = new Effect(async () => {
|
|
56
95
|
* // code
|
|
57
96
|
* })
|
|
@@ -59,13 +98,70 @@ export class Effect {
|
|
|
59
98
|
*/
|
|
60
99
|
removeEffect: () => void;
|
|
61
100
|
} & {
|
|
62
|
-
"vivth:unwrapLazy;":
|
|
101
|
+
"vivth:unwrapLazy;": () => {
|
|
102
|
+
/**
|
|
103
|
+
* @instance options
|
|
104
|
+
* @description
|
|
105
|
+
* @returns {(timeoutMS?:number)=>Promise<boolean>}
|
|
106
|
+
* - timeoutMS only necessary if the operation doesn't naturally await;
|
|
107
|
+
* - if it's operation such as `fetch`, you can just leave it blank;
|
|
108
|
+
* @example
|
|
109
|
+
*
|
|
110
|
+
* import { Effect } from 'vivth';
|
|
111
|
+
*
|
|
112
|
+
* const effect = new Effect(async ({ isLastCalled }) => {
|
|
113
|
+
* if (!(await isLastCalled(100))) {
|
|
114
|
+
* return;
|
|
115
|
+
* }
|
|
116
|
+
* // OR
|
|
117
|
+
* const res = await fetch('some/path');
|
|
118
|
+
* if (!(await isLastCalled(
|
|
119
|
+
* // no need to add timeoutMS argument, as fetch are naturally add delay;
|
|
120
|
+
* ))) {
|
|
121
|
+
* return;
|
|
122
|
+
* }
|
|
123
|
+
* })
|
|
124
|
+
*/
|
|
125
|
+
readonly isLastCalled: (timeoutMS?: number) => Promise<boolean>;
|
|
126
|
+
/**
|
|
127
|
+
* @instance options
|
|
128
|
+
* @description
|
|
129
|
+
* - normally it's passed as argument to constructor, however it is also accessible from `options` property;
|
|
130
|
+
* @template {Signal} SIGNAL
|
|
131
|
+
* @param {SIGNAL} signal
|
|
132
|
+
* @returns {SIGNAL}
|
|
133
|
+
* @example
|
|
134
|
+
* import { Effect } from 'vivth';
|
|
135
|
+
*
|
|
136
|
+
* const effect = new Effect(async () => {
|
|
137
|
+
* // code
|
|
138
|
+
* })
|
|
139
|
+
* effect.options.subscribe(signalInstance);
|
|
140
|
+
*/
|
|
141
|
+
subscribe: <SIGNAL extends Signal<any>>(signal: SIGNAL) => SIGNAL;
|
|
142
|
+
/**
|
|
143
|
+
* @instance options
|
|
144
|
+
* @description
|
|
145
|
+
* - normally it's passed as argument to constructor, however it is also accessible from `options` property;
|
|
146
|
+
* @type {()=>void}
|
|
147
|
+
* @example
|
|
148
|
+
* import { Effect } from 'vivth';
|
|
149
|
+
*
|
|
150
|
+
* const effect = new Effect(async () => {
|
|
151
|
+
* // code
|
|
152
|
+
* })
|
|
153
|
+
* effect.options.removeEffect();
|
|
154
|
+
*/
|
|
155
|
+
removeEffect: () => void;
|
|
156
|
+
};
|
|
63
157
|
};
|
|
64
158
|
/**
|
|
65
159
|
* @description
|
|
66
160
|
* - normally is to let to be automatically run when dependency signals changes, however it's also accessible as instance method;
|
|
67
161
|
* @returns {void}
|
|
68
162
|
* @example
|
|
163
|
+
* import { Effect } from 'vivth';
|
|
164
|
+
*
|
|
69
165
|
* const effect = new Effect(async ()=>{
|
|
70
166
|
* // code
|
|
71
167
|
* })
|
|
@@ -75,3 +171,6 @@ export class Effect {
|
|
|
75
171
|
#private;
|
|
76
172
|
}
|
|
77
173
|
import { Signal } from './Signal.mjs';
|
|
174
|
+
type unwrapLazy = "vivth:unwrapLazy;";
|
|
175
|
+
import { unwrapLazy } from '../common/lazie.mjs';
|
|
176
|
+
export {};
|
|
@@ -2,19 +2,19 @@
|
|
|
2
2
|
* @description
|
|
3
3
|
* - non browser API;
|
|
4
4
|
* - uses [Signal](#signal) and [Derived](#derived) under the hood;
|
|
5
|
-
* @template
|
|
5
|
+
* @template VALUE
|
|
6
6
|
*/
|
|
7
|
-
export class EnvSignal<
|
|
7
|
+
export class EnvSignal<VALUE> {
|
|
8
8
|
/**
|
|
9
9
|
* @description
|
|
10
10
|
* - create `EnvSignal` instance;
|
|
11
|
-
* @param {
|
|
11
|
+
* @param {VALUE} initialValue
|
|
12
12
|
*/
|
|
13
|
-
constructor(initialValue:
|
|
13
|
+
constructor(initialValue: VALUE);
|
|
14
14
|
/**
|
|
15
15
|
* @description
|
|
16
16
|
* - exposed property to listen to;
|
|
17
|
-
* @type {Derived<
|
|
17
|
+
* @type {Derived<VALUE>}
|
|
18
18
|
* @example
|
|
19
19
|
* import { EnvSignal, Effect } from 'vivth';
|
|
20
20
|
*
|
|
@@ -24,12 +24,12 @@ export class EnvSignal<V> {
|
|
|
24
24
|
* // code
|
|
25
25
|
* })
|
|
26
26
|
*/
|
|
27
|
-
env: Derived<
|
|
27
|
+
env: Derived<VALUE>;
|
|
28
28
|
/**
|
|
29
29
|
* @description
|
|
30
30
|
* - call to correct the value of previously declared value;
|
|
31
31
|
* - can only be called once;
|
|
32
|
-
* @param {
|
|
32
|
+
* @param {VALUE} correctedValue
|
|
33
33
|
* @returns {void}
|
|
34
34
|
* @example
|
|
35
35
|
* import { EnvSignal } from 'vivth';
|
|
@@ -41,7 +41,7 @@ export class EnvSignal<V> {
|
|
|
41
41
|
*
|
|
42
42
|
* myEnv.correction(false); // this will notify all subscribers;
|
|
43
43
|
*/
|
|
44
|
-
correction: (correctedValue:
|
|
44
|
+
correction: (correctedValue: VALUE) => void;
|
|
45
45
|
#private;
|
|
46
46
|
}
|
|
47
47
|
import { Derived } from './Derived.mjs';
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @description
|
|
3
3
|
* - Signal implementation for `CustomEvent`, to dispatch and listen;
|
|
4
|
-
*
|
|
4
|
+
* - it's based on string as key, so it can be listened/dispatched even without direct instance reference;
|
|
5
|
+
* @template {IsListSignal} ISLIST
|
|
5
6
|
* - boolean;
|
|
6
7
|
*/
|
|
7
|
-
export class EventSignal<
|
|
8
|
+
export class EventSignal<ISLIST extends boolean> {
|
|
8
9
|
/**
|
|
9
10
|
* @typedef {import('../types/IsListSignal.mjs').IsListSignal} IsListSignal
|
|
10
11
|
*/
|
|
@@ -48,7 +49,7 @@ export class EventSignal<isList extends boolean> {
|
|
|
48
49
|
* @example
|
|
49
50
|
* import { EventSignal } from 'vivth';
|
|
50
51
|
*
|
|
51
|
-
* EventSignal.remove.subscriber('yourEventSignalName',
|
|
52
|
+
* EventSignal.remove.subscriber('yourEventSignalName', myEffectInstance);
|
|
52
53
|
*/
|
|
53
54
|
subscriber: (name: string, effect: import("./Effect.mjs").Effect) => void;
|
|
54
55
|
/**
|
|
@@ -76,12 +77,50 @@ export class EventSignal<isList extends boolean> {
|
|
|
76
77
|
*/
|
|
77
78
|
refs: (name: string) => void;
|
|
78
79
|
} & {
|
|
79
|
-
"vivth:unwrapLazy;":
|
|
80
|
+
"vivth:unwrapLazy;": () => {
|
|
81
|
+
/**
|
|
82
|
+
* @static remove
|
|
83
|
+
* @description
|
|
84
|
+
* - remove subscriber from the named `EventSignal_instance`;
|
|
85
|
+
* @param {string} name
|
|
86
|
+
* @param {import('./Effect.mjs').Effect} effect
|
|
87
|
+
* @returns {void}
|
|
88
|
+
* @example
|
|
89
|
+
* import { EventSignal } from 'vivth';
|
|
90
|
+
*
|
|
91
|
+
* EventSignal.remove.subscriber('yourEventSignalName', myEffectInstance);
|
|
92
|
+
*/
|
|
93
|
+
subscriber: (name: string, effect: import("./Effect.mjs").Effect) => void;
|
|
94
|
+
/**
|
|
95
|
+
* @static remove
|
|
96
|
+
* @description
|
|
97
|
+
* - remove all subscribers from the named `EventSignal_instance`;
|
|
98
|
+
* @param {string} name
|
|
99
|
+
* @returns {void}
|
|
100
|
+
* @example
|
|
101
|
+
* import { EventSignal } from 'vivth';
|
|
102
|
+
*
|
|
103
|
+
* EventSignal.remove.allSubscribers('yourEventSignalName');
|
|
104
|
+
*/
|
|
105
|
+
allSubscribers: (name: string) => void;
|
|
106
|
+
/**
|
|
107
|
+
* @static remove
|
|
108
|
+
* @description
|
|
109
|
+
* - remove reference of the `proxySignals` of the named `EventSignal_instance`;
|
|
110
|
+
* @param {string} name
|
|
111
|
+
* @returns {void}
|
|
112
|
+
* @example
|
|
113
|
+
* import { EventSignal } from 'vivth';
|
|
114
|
+
*
|
|
115
|
+
* EventSignal.remove.refs('yourEventSignalName');
|
|
116
|
+
*/
|
|
117
|
+
refs: (name: string) => void;
|
|
118
|
+
};
|
|
80
119
|
};
|
|
81
120
|
/**
|
|
82
121
|
* @private
|
|
83
122
|
* @param {string} name
|
|
84
|
-
* @param {
|
|
123
|
+
* @param {ISLIST} [isList]
|
|
85
124
|
*/
|
|
86
125
|
private constructor();
|
|
87
126
|
/**
|
|
@@ -94,6 +133,17 @@ export class EventSignal<isList extends boolean> {
|
|
|
94
133
|
* - if needed to pass along the messages, it can be used as `dispatcher` and `listener` at the same time;
|
|
95
134
|
* - is `lazily` created;
|
|
96
135
|
* @type {Signal|ListSignal}
|
|
136
|
+
* @example
|
|
137
|
+
* import { EventSignal, Effect, Console } from 'vivth';
|
|
138
|
+
*
|
|
139
|
+
* const myEventSignal = await EventSignal.get('dataEvent', false);
|
|
140
|
+
*
|
|
141
|
+
* new Effect(({ subscribe })=>{
|
|
142
|
+
* const listenValue = subscribe(myEventSignal.dispatch).value;
|
|
143
|
+
* // dispatch can be used as two way communication;
|
|
144
|
+
* Console.log({ listenValue });
|
|
145
|
+
* })
|
|
146
|
+
* myEventSignal.dispatch.value = 'hey';
|
|
97
147
|
*/
|
|
98
148
|
dispatch: Signal<any> | ListSignal<any>;
|
|
99
149
|
/**
|
|
@@ -102,6 +152,17 @@ export class EventSignal<isList extends boolean> {
|
|
|
102
152
|
* - can be used as listener when passed down value shouldn't be modified manually;
|
|
103
153
|
* - is `lazily` created along with `dispatch`, if `listen` is accessed first, then `dispatch` will also be created automatically;
|
|
104
154
|
* @type {Derived|ListDerived}
|
|
155
|
+
* @example
|
|
156
|
+
* import { EventSignal, Effect, Console } from 'vivth';
|
|
157
|
+
*
|
|
158
|
+
* const myEventSignal = await EventSignal.get('dataEvent', false);
|
|
159
|
+
*
|
|
160
|
+
* new Effect(({ subscribe })=>{
|
|
161
|
+
* const listenValue = subscribe(myEventSignal.listen).value;
|
|
162
|
+
* // listen can be used only as listener for one way communication;
|
|
163
|
+
* Console.log({ listenValue });
|
|
164
|
+
* })
|
|
165
|
+
* myEventSignal.dispatch.value = 'hey';
|
|
105
166
|
*/
|
|
106
167
|
listen: Derived<any> | ListDerived<any>;
|
|
107
168
|
remove: {
|
|
@@ -112,7 +173,16 @@ export class EventSignal<isList extends boolean> {
|
|
|
112
173
|
* @param {import('./Effect.mjs').Effect} effect
|
|
113
174
|
* @returns {void}
|
|
114
175
|
* @example
|
|
115
|
-
*
|
|
176
|
+
* import { EventSignal, Effect, Console } from 'vivth';
|
|
177
|
+
*
|
|
178
|
+
* const myEventSignal = await EventSignal.get('dataEvent', false);
|
|
179
|
+
*
|
|
180
|
+
* const myEffectInstance = new Effect(({ subscribe })=>{
|
|
181
|
+
* const listenValue = subscribe(myEventSignal.dispatch).value;
|
|
182
|
+
* Console.log({ listenValue });
|
|
183
|
+
* })
|
|
184
|
+
* myEventSignal.dispatch.value = 'hey';
|
|
185
|
+
* eventSignal_instance.remove.subscriber(myEffectInstance);
|
|
116
186
|
*/
|
|
117
187
|
subscriber: (effect: import("./Effect.mjs").Effect) => void;
|
|
118
188
|
/**
|
|
@@ -121,6 +191,15 @@ export class EventSignal<isList extends boolean> {
|
|
|
121
191
|
* - remove allSubscribers from the `EventSignal_instance`;
|
|
122
192
|
* @type {()=>void}
|
|
123
193
|
* @example
|
|
194
|
+
* import { EventSignal, Effect, Console } from 'vivth';
|
|
195
|
+
*
|
|
196
|
+
* const myEventSignal = await EventSignal.get('dataEvent', false);
|
|
197
|
+
*
|
|
198
|
+
* const myEffectInstance = new Effect(({ subscribe })=>{
|
|
199
|
+
* const listenValue = subscribe(myEventSignal.dispatch).value;
|
|
200
|
+
* Console.log({ listenValue });
|
|
201
|
+
* })
|
|
202
|
+
* myEventSignal.dispatch.value = 'hey';
|
|
124
203
|
* eventSignal_instance.remove.allSubscribers();
|
|
125
204
|
*/
|
|
126
205
|
allSubscribers: () => void;
|
|
@@ -130,11 +209,76 @@ export class EventSignal<isList extends boolean> {
|
|
|
130
209
|
* - remove reference of the `proxySignals` of the `EventSignal_instance`;
|
|
131
210
|
* @type {()=>void}
|
|
132
211
|
* @example
|
|
212
|
+
* import { EventSignal, Effect, Console } from 'vivth';
|
|
213
|
+
*
|
|
214
|
+
* const myEventSignal = await EventSignal.get('dataEvent', false);
|
|
215
|
+
*
|
|
216
|
+
* const myEffectInstance = new Effect(({ subscribe })=>{
|
|
217
|
+
* const listenValue = subscribe(myEventSignal.dispatch).value;
|
|
218
|
+
* Console.log({ listenValue });
|
|
219
|
+
* });
|
|
220
|
+
*
|
|
133
221
|
* eventSignal_instance.remove.ref();
|
|
134
222
|
*/
|
|
135
223
|
ref: () => void;
|
|
136
224
|
} & {
|
|
137
|
-
"vivth:unwrapLazy;":
|
|
225
|
+
"vivth:unwrapLazy;": () => {
|
|
226
|
+
/**
|
|
227
|
+
* @instance remove
|
|
228
|
+
* @description
|
|
229
|
+
* - remove subscriber from the `EventSignal_instance`;
|
|
230
|
+
* @param {import('./Effect.mjs').Effect} effect
|
|
231
|
+
* @returns {void}
|
|
232
|
+
* @example
|
|
233
|
+
* import { EventSignal, Effect, Console } from 'vivth';
|
|
234
|
+
*
|
|
235
|
+
* const myEventSignal = await EventSignal.get('dataEvent', false);
|
|
236
|
+
*
|
|
237
|
+
* const myEffectInstance = new Effect(({ subscribe })=>{
|
|
238
|
+
* const listenValue = subscribe(myEventSignal.dispatch).value;
|
|
239
|
+
* Console.log({ listenValue });
|
|
240
|
+
* })
|
|
241
|
+
* myEventSignal.dispatch.value = 'hey';
|
|
242
|
+
* eventSignal_instance.remove.subscriber(myEffectInstance);
|
|
243
|
+
*/
|
|
244
|
+
subscriber: (effect: import("./Effect.mjs").Effect) => void;
|
|
245
|
+
/**
|
|
246
|
+
* @instance remove
|
|
247
|
+
* @description
|
|
248
|
+
* - remove allSubscribers from the `EventSignal_instance`;
|
|
249
|
+
* @type {()=>void}
|
|
250
|
+
* @example
|
|
251
|
+
* import { EventSignal, Effect, Console } from 'vivth';
|
|
252
|
+
*
|
|
253
|
+
* const myEventSignal = await EventSignal.get('dataEvent', false);
|
|
254
|
+
*
|
|
255
|
+
* const myEffectInstance = new Effect(({ subscribe })=>{
|
|
256
|
+
* const listenValue = subscribe(myEventSignal.dispatch).value;
|
|
257
|
+
* Console.log({ listenValue });
|
|
258
|
+
* })
|
|
259
|
+
* myEventSignal.dispatch.value = 'hey';
|
|
260
|
+
* eventSignal_instance.remove.allSubscribers();
|
|
261
|
+
*/
|
|
262
|
+
allSubscribers: () => void;
|
|
263
|
+
/**
|
|
264
|
+
* @instance remove
|
|
265
|
+
* @description
|
|
266
|
+
* - remove reference of the `proxySignals` of the `EventSignal_instance`;
|
|
267
|
+
* @type {()=>void}
|
|
268
|
+
* @example
|
|
269
|
+
* import { EventSignal, Effect, Console } from 'vivth';
|
|
270
|
+
*
|
|
271
|
+
* const myEventSignal = await EventSignal.get('dataEvent', false);
|
|
272
|
+
*
|
|
273
|
+
* const myEffectInstance = new Effect(({ subscribe })=>{
|
|
274
|
+
* const listenValue = subscribe(myEventSignal.dispatch).value;
|
|
275
|
+
* Console.log({ listenValue });
|
|
276
|
+
* });
|
|
277
|
+
*
|
|
278
|
+
* eventSignal_instance.remove.ref();
|
|
279
|
+
*/
|
|
280
|
+
ref: () => void;
|
|
281
|
+
};
|
|
138
282
|
};
|
|
139
283
|
#private;
|
|
140
284
|
}
|