@esportsplus/reactivity 0.1.10 → 0.1.12
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/build/index.d.ts +1 -1
- package/build/index.js +1 -1
- package/build/macro.d.ts +1 -3
- package/build/macro.js +2 -5
- package/build/reactive/array.d.ts +0 -1
- package/build/reactive/array.js +2 -6
- package/build/reactive/object.d.ts +0 -1
- package/build/reactive/object.js +3 -9
- package/build/resource.d.ts +0 -1
- package/build/resource.js +4 -9
- package/build/signal.d.ts +2 -7
- package/build/signal.js +8 -34
- package/build/types.d.ts +2 -2
- package/build/types.js +1 -2
- package/package.json +1 -1
- package/src/index.ts +1 -1
- package/src/macro.ts +3 -7
- package/src/reactive/array.ts +2 -6
- package/src/reactive/object.ts +3 -10
- package/src/resource.ts +5 -11
- package/src/signal.ts +11 -45
- package/src/types.ts +2 -2
- package/build/dispose.d.ts +0 -4
- package/build/dispose.js +0 -14
- package/build/reset.d.ts +0 -4
- package/build/reset.js +0 -14
package/build/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { default as macro } from './macro';
|
|
2
2
|
export { default as resource } from './resource';
|
|
3
3
|
export { default as reactive } from './reactive';
|
|
4
|
-
export { computed, dispose, effect,
|
|
4
|
+
export { computed, dispose, effect, root, signal } from './signal';
|
|
5
5
|
export * from './types';
|
package/build/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { default as macro } from './macro';
|
|
2
2
|
export { default as resource } from './resource';
|
|
3
3
|
export { default as reactive } from './reactive';
|
|
4
|
-
export { computed, dispose, effect,
|
|
4
|
+
export { computed, dispose, effect, root, signal } from './signal';
|
|
5
5
|
export * from './types';
|
package/build/macro.d.ts
CHANGED
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
import CustomFunction from '@esportsplus/custom-function';
|
|
2
|
-
import { Computed } from './
|
|
3
|
-
import { Options } from './types';
|
|
2
|
+
import { Computed, Options } from './types';
|
|
4
3
|
type Function<A extends unknown[], R> = Computed<(...args: A) => R>['fn'];
|
|
5
4
|
declare class Macro<A extends unknown[], R> extends CustomFunction {
|
|
6
5
|
#private;
|
|
7
6
|
constructor(fn: Function<A, R>, options?: Options);
|
|
8
7
|
dispose(): void;
|
|
9
|
-
reset(): void;
|
|
10
8
|
}
|
|
11
9
|
declare const _default: <A extends unknown[], R>(fn: () => (...args: A) => R, options?: Options) => Macro<A, R>;
|
|
12
10
|
export default _default;
|
package/build/macro.js
CHANGED
|
@@ -1,19 +1,16 @@
|
|
|
1
1
|
import CustomFunction from '@esportsplus/custom-function';
|
|
2
|
-
import {
|
|
2
|
+
import { computed } from './signal';
|
|
3
3
|
class Macro extends CustomFunction {
|
|
4
4
|
#factory;
|
|
5
5
|
constructor(fn, options = {}) {
|
|
6
6
|
super((...args) => {
|
|
7
7
|
return this.#factory.get()(...args);
|
|
8
8
|
});
|
|
9
|
-
this.#factory =
|
|
9
|
+
this.#factory = computed(fn, options);
|
|
10
10
|
}
|
|
11
11
|
dispose() {
|
|
12
12
|
this.#factory.dispose();
|
|
13
13
|
}
|
|
14
|
-
reset() {
|
|
15
|
-
this.#factory.reset();
|
|
16
|
-
}
|
|
17
14
|
}
|
|
18
15
|
export default (fn, options = {}) => {
|
|
19
16
|
return new Macro(fn, options);
|
|
@@ -37,7 +37,6 @@ declare class ReactiveArray<T> extends Array<T> {
|
|
|
37
37
|
once<E extends keyof Events<T>>(event: E, listener: Listener<Events<T>[E]>): void;
|
|
38
38
|
pop(): T | undefined;
|
|
39
39
|
push(...items: T[]): number;
|
|
40
|
-
reset(): void;
|
|
41
40
|
reverse(): this;
|
|
42
41
|
shift(): T | undefined;
|
|
43
42
|
sort(): this;
|
package/build/reactive/array.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { dispose } from '../signal';
|
|
2
|
-
import { Signal } from '../types';
|
|
1
|
+
import { dispose, signal } from '../signal';
|
|
3
2
|
import { ReactiveObject } from './object';
|
|
4
3
|
function factory(data, options = {}) {
|
|
5
4
|
let signals = [];
|
|
@@ -15,7 +14,7 @@ class ReactiveArray extends Array {
|
|
|
15
14
|
#signal;
|
|
16
15
|
constructor(data) {
|
|
17
16
|
super(...data);
|
|
18
|
-
this.#signal =
|
|
17
|
+
this.#signal = signal(false);
|
|
19
18
|
}
|
|
20
19
|
set length(n) {
|
|
21
20
|
if (n > this.length) {
|
|
@@ -58,9 +57,6 @@ class ReactiveArray extends Array {
|
|
|
58
57
|
this.trigger();
|
|
59
58
|
return n;
|
|
60
59
|
}
|
|
61
|
-
reset() {
|
|
62
|
-
this.#signal.reset();
|
|
63
|
-
}
|
|
64
60
|
reverse() {
|
|
65
61
|
super.reverse();
|
|
66
62
|
this.dispatch('reverse');
|
package/build/reactive/object.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { computed, signal } from '../signal';
|
|
2
2
|
import { defineProperty, isArray } from '../utilities';
|
|
3
3
|
import { ReactiveArray, ReactiveObjectArray } from './array';
|
|
4
4
|
class ReactiveObject {
|
|
@@ -8,7 +8,7 @@ class ReactiveObject {
|
|
|
8
8
|
for (let key in data) {
|
|
9
9
|
let input = data[key];
|
|
10
10
|
if (typeof input === 'function') {
|
|
11
|
-
let node = nodes[key] =
|
|
11
|
+
let node = nodes[key] = computed(input, options);
|
|
12
12
|
defineProperty(this, key, {
|
|
13
13
|
enumerable: true,
|
|
14
14
|
get() {
|
|
@@ -33,7 +33,7 @@ class ReactiveObject {
|
|
|
33
33
|
});
|
|
34
34
|
}
|
|
35
35
|
else {
|
|
36
|
-
let node = nodes[key] =
|
|
36
|
+
let node = nodes[key] = signal(input, options);
|
|
37
37
|
defineProperty(this, key, {
|
|
38
38
|
enumerable: true,
|
|
39
39
|
get() {
|
|
@@ -52,11 +52,5 @@ class ReactiveObject {
|
|
|
52
52
|
nodes[key].dispose();
|
|
53
53
|
}
|
|
54
54
|
}
|
|
55
|
-
reset() {
|
|
56
|
-
let nodes = this.nodes;
|
|
57
|
-
for (let key in nodes) {
|
|
58
|
-
nodes[key].reset();
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
55
|
}
|
|
62
56
|
export { ReactiveObject };
|
package/build/resource.d.ts
CHANGED
|
@@ -9,7 +9,6 @@ declare class Resource<A extends unknown[], R extends Promise<unknown>> extends
|
|
|
9
9
|
get input(): A | null;
|
|
10
10
|
get ok(): boolean | null;
|
|
11
11
|
dispose(): void;
|
|
12
|
-
reset(): void;
|
|
13
12
|
}
|
|
14
13
|
declare const _default: <A extends unknown[], R extends Promise<unknown>>(fn: Function<A, R>, options?: Options) => Resource<A, R>;
|
|
15
14
|
export default _default;
|
package/build/resource.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import CustomFunction from '@esportsplus/custom-function';
|
|
2
|
-
import {
|
|
2
|
+
import { signal } from './signal';
|
|
3
3
|
class Resource extends CustomFunction {
|
|
4
4
|
#data;
|
|
5
5
|
#input;
|
|
@@ -26,9 +26,9 @@ class Resource extends CustomFunction {
|
|
|
26
26
|
this.#ok.set(false);
|
|
27
27
|
});
|
|
28
28
|
});
|
|
29
|
-
this.#data =
|
|
30
|
-
this.#input =
|
|
31
|
-
this.#ok =
|
|
29
|
+
this.#data = signal(undefined, options);
|
|
30
|
+
this.#input = signal(null, options);
|
|
31
|
+
this.#ok = signal(null, options);
|
|
32
32
|
}
|
|
33
33
|
get data() {
|
|
34
34
|
return this.#data.get();
|
|
@@ -44,11 +44,6 @@ class Resource extends CustomFunction {
|
|
|
44
44
|
this.#input.dispose();
|
|
45
45
|
this.#ok.dispose();
|
|
46
46
|
}
|
|
47
|
-
reset() {
|
|
48
|
-
this.#data.reset();
|
|
49
|
-
this.#input.reset();
|
|
50
|
-
this.#ok.reset();
|
|
51
|
-
}
|
|
52
47
|
}
|
|
53
48
|
export default (fn, options = {}) => {
|
|
54
49
|
return new Resource(fn, options);
|
package/build/signal.d.ts
CHANGED
|
@@ -20,14 +20,12 @@ declare class Computed<T> extends Core<T> {
|
|
|
20
20
|
constructor(fn: Computed<T>['fn'], options?: Options);
|
|
21
21
|
get type(): Type;
|
|
22
22
|
get(): T;
|
|
23
|
-
reset(): void;
|
|
24
23
|
}
|
|
25
24
|
declare class Effect extends Core<null> {
|
|
26
25
|
fn: NeverAsync<(node: Effect) => void>;
|
|
27
26
|
task: Function;
|
|
28
27
|
constructor(fn: Effect['fn']);
|
|
29
28
|
get type(): Type;
|
|
30
|
-
reset(): void;
|
|
31
29
|
}
|
|
32
30
|
declare class Root extends Core<null> {
|
|
33
31
|
scheduler: (fn: Function) => unknown;
|
|
@@ -40,7 +38,6 @@ declare class Signal<T> extends Core<T> {
|
|
|
40
38
|
constructor(data: T, options?: Options);
|
|
41
39
|
get type(): Type;
|
|
42
40
|
get(): T;
|
|
43
|
-
reset(): void;
|
|
44
41
|
set(value: T): T;
|
|
45
42
|
}
|
|
46
43
|
declare const computed: <T>(fn: () => T extends unknown ? T : NeverAsync<T>, options?: Options) => Computed<T>;
|
|
@@ -48,9 +45,7 @@ declare const dispose: <T extends {
|
|
|
48
45
|
dispose: VoidFunction;
|
|
49
46
|
}>(dispose?: T | T[] | null | undefined) => T | T[] | null | undefined;
|
|
50
47
|
declare const effect: (fn: Effect['fn']) => Effect;
|
|
51
|
-
declare const reset: <T extends {
|
|
52
|
-
reset: VoidFunction;
|
|
53
|
-
}>(reset?: T | T[] | null | undefined) => T | T[] | null | undefined;
|
|
54
48
|
declare const root: <T>(fn: (root: Root) => T, scheduler?: Root['scheduler']) => T;
|
|
55
49
|
declare const signal: <T>(value: T, options?: Options) => Signal<T>;
|
|
56
|
-
export { computed, dispose, effect,
|
|
50
|
+
export { computed, dispose, effect, root, signal };
|
|
51
|
+
export { Computed, Effect, Root, Signal };
|
package/build/signal.js
CHANGED
|
@@ -62,7 +62,12 @@ class Core {
|
|
|
62
62
|
if (this.state === DISPOSED) {
|
|
63
63
|
return;
|
|
64
64
|
}
|
|
65
|
-
|
|
65
|
+
this.dispatch('dispose', this);
|
|
66
|
+
removeSourceObservers(this, 0);
|
|
67
|
+
this.listeners = null;
|
|
68
|
+
this.observers = null;
|
|
69
|
+
this.sources = null;
|
|
70
|
+
this.state = DISPOSED;
|
|
66
71
|
}
|
|
67
72
|
on(event, listener) {
|
|
68
73
|
if (this.updating) {
|
|
@@ -106,9 +111,6 @@ class Computed extends Core {
|
|
|
106
111
|
get() {
|
|
107
112
|
return read(this);
|
|
108
113
|
}
|
|
109
|
-
reset() {
|
|
110
|
-
flush('reset', this, DIRTY, undefined);
|
|
111
|
-
}
|
|
112
114
|
}
|
|
113
115
|
class Effect extends Core {
|
|
114
116
|
fn;
|
|
@@ -122,10 +124,6 @@ class Effect extends Core {
|
|
|
122
124
|
get type() {
|
|
123
125
|
return EFFECT;
|
|
124
126
|
}
|
|
125
|
-
reset() {
|
|
126
|
-
flush('reset', this, DIRTY, null);
|
|
127
|
-
update(this);
|
|
128
|
-
}
|
|
129
127
|
}
|
|
130
128
|
class Root extends Core {
|
|
131
129
|
scheduler;
|
|
@@ -151,9 +149,6 @@ class Signal extends Core {
|
|
|
151
149
|
get() {
|
|
152
150
|
return read(this);
|
|
153
151
|
}
|
|
154
|
-
reset() {
|
|
155
|
-
flush('reset', this, CLEAN, this.value);
|
|
156
|
-
}
|
|
157
152
|
set(value) {
|
|
158
153
|
return write(this, value);
|
|
159
154
|
}
|
|
@@ -161,15 +156,6 @@ class Signal extends Core {
|
|
|
161
156
|
function changed(a, b) {
|
|
162
157
|
return a !== b;
|
|
163
158
|
}
|
|
164
|
-
function flush(event, node, state, value) {
|
|
165
|
-
node.dispatch(event, node);
|
|
166
|
-
removeSourceObservers(node, 0);
|
|
167
|
-
node.listeners = null;
|
|
168
|
-
node.observers = null;
|
|
169
|
-
node.sources = null;
|
|
170
|
-
node.state = state;
|
|
171
|
-
node.value = value;
|
|
172
|
-
}
|
|
173
159
|
function notify(nodes, state) {
|
|
174
160
|
if (nodes === null) {
|
|
175
161
|
return;
|
|
@@ -313,19 +299,6 @@ const dispose = (dispose) => {
|
|
|
313
299
|
const effect = (fn) => {
|
|
314
300
|
return new Effect(fn);
|
|
315
301
|
};
|
|
316
|
-
const reset = (reset) => {
|
|
317
|
-
if (reset == null) {
|
|
318
|
-
}
|
|
319
|
-
else if (isArray(reset)) {
|
|
320
|
-
for (let i = 0, n = reset.length; i < n; i++) {
|
|
321
|
-
reset[i].reset();
|
|
322
|
-
}
|
|
323
|
-
}
|
|
324
|
-
else {
|
|
325
|
-
reset.reset();
|
|
326
|
-
}
|
|
327
|
-
return reset;
|
|
328
|
-
};
|
|
329
302
|
const root = (fn, scheduler) => {
|
|
330
303
|
let o = observer, s = scope;
|
|
331
304
|
if (scheduler === undefined) {
|
|
@@ -344,4 +317,5 @@ const root = (fn, scheduler) => {
|
|
|
344
317
|
const signal = (value, options) => {
|
|
345
318
|
return new Signal(value, options);
|
|
346
319
|
};
|
|
347
|
-
export { computed, dispose, effect,
|
|
320
|
+
export { computed, dispose, effect, root, signal };
|
|
321
|
+
export { Computed, Effect, Root, Signal };
|
package/build/types.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Function, NeverAsync, Prettify } from '@esportsplus/typescript';
|
|
2
2
|
import { CHECK, CLEAN, COMPUTED, DIRTY, DISPOSED, EFFECT, ROOT, SIGNAL } from './constants';
|
|
3
|
-
import { Computed, Effect, Signal } from './signal';
|
|
3
|
+
import { Computed, Effect, Root, Signal } from './signal';
|
|
4
4
|
type Changed = (a: unknown, b: unknown) => boolean;
|
|
5
5
|
type Event = string;
|
|
6
6
|
type Listener<D> = {
|
|
@@ -16,4 +16,4 @@ type Options = {
|
|
|
16
16
|
};
|
|
17
17
|
type State = typeof CHECK | typeof CLEAN | typeof DIRTY | typeof DISPOSED;
|
|
18
18
|
type Type = typeof COMPUTED | typeof EFFECT | typeof ROOT | typeof SIGNAL;
|
|
19
|
-
export { Changed, Computed, Effect, Event, Function, Listener, Object, Options, NeverAsync, Prettify, Signal, State, Type };
|
|
19
|
+
export type { Changed, Computed, Effect, Event, Function, Listener, Object, Options, NeverAsync, Prettify, Root, Signal, State, Type };
|
package/build/types.js
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
export { Computed, Effect, Signal };
|
|
1
|
+
export {};
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { default as macro } from './macro';
|
|
2
2
|
export { default as resource } from './resource';
|
|
3
3
|
export { default as reactive } from './reactive';
|
|
4
|
-
export { computed, dispose, effect,
|
|
4
|
+
export { computed, dispose, effect, root, signal } from './signal';
|
|
5
5
|
export * from './types';
|
package/src/macro.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import CustomFunction from '@esportsplus/custom-function';
|
|
2
|
-
import {
|
|
3
|
-
import { Options } from './types';
|
|
2
|
+
import { computed } from './signal';
|
|
3
|
+
import { Computed, Options } from './types';
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
type Function<A extends unknown[], R> = Computed<(...args: A) => R>['fn'];
|
|
@@ -14,17 +14,13 @@ class Macro<A extends unknown[], R> extends CustomFunction {
|
|
|
14
14
|
super((...args: A) => {
|
|
15
15
|
return this.#factory.get()(...args);
|
|
16
16
|
});
|
|
17
|
-
this.#factory =
|
|
17
|
+
this.#factory = computed(fn, options);
|
|
18
18
|
}
|
|
19
19
|
|
|
20
20
|
|
|
21
21
|
dispose() {
|
|
22
22
|
this.#factory.dispose();
|
|
23
23
|
}
|
|
24
|
-
|
|
25
|
-
reset() {
|
|
26
|
-
this.#factory.reset();
|
|
27
|
-
}
|
|
28
24
|
}
|
|
29
25
|
|
|
30
26
|
|
package/src/reactive/array.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { dispose } from '~/signal';
|
|
1
|
+
import { dispose, signal } from '~/signal';
|
|
2
2
|
import { Listener, Object, Options, Signal } from '~/types';
|
|
3
3
|
import { ReactiveObject } from './object';
|
|
4
4
|
|
|
@@ -40,7 +40,7 @@ class ReactiveArray<T> extends Array<T> {
|
|
|
40
40
|
|
|
41
41
|
constructor(data: T[]) {
|
|
42
42
|
super(...data);
|
|
43
|
-
this.#signal =
|
|
43
|
+
this.#signal = signal(false);
|
|
44
44
|
}
|
|
45
45
|
|
|
46
46
|
|
|
@@ -103,10 +103,6 @@ class ReactiveArray<T> extends Array<T> {
|
|
|
103
103
|
return n;
|
|
104
104
|
}
|
|
105
105
|
|
|
106
|
-
reset() {
|
|
107
|
-
this.#signal.reset();
|
|
108
|
-
}
|
|
109
|
-
|
|
110
106
|
reverse() {
|
|
111
107
|
super.reverse();
|
|
112
108
|
|
package/src/reactive/object.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { computed, signal } from '~/signal';
|
|
1
2
|
import { Computed, Object, Options, Signal } from '~/types';
|
|
2
3
|
import { defineProperty, isArray } from '~/utilities';
|
|
3
4
|
import { ReactiveArray, ReactiveObjectArray } from './array';
|
|
@@ -17,7 +18,7 @@ class ReactiveObject<T extends Object> {
|
|
|
17
18
|
let input = data[key];
|
|
18
19
|
|
|
19
20
|
if (typeof input === 'function') {
|
|
20
|
-
let node = nodes[key] =
|
|
21
|
+
let node = nodes[key] = computed(input as Computed<T>['fn'], options);
|
|
21
22
|
|
|
22
23
|
defineProperty(this, key, {
|
|
23
24
|
enumerable: true,
|
|
@@ -47,7 +48,7 @@ class ReactiveObject<T extends Object> {
|
|
|
47
48
|
});
|
|
48
49
|
}
|
|
49
50
|
else {
|
|
50
|
-
let node = nodes[key] =
|
|
51
|
+
let node = nodes[key] = signal(input, options);
|
|
51
52
|
|
|
52
53
|
defineProperty(this, key, {
|
|
53
54
|
enumerable: true,
|
|
@@ -70,14 +71,6 @@ class ReactiveObject<T extends Object> {
|
|
|
70
71
|
nodes[key].dispose();
|
|
71
72
|
}
|
|
72
73
|
}
|
|
73
|
-
|
|
74
|
-
reset() {
|
|
75
|
-
let nodes = this.nodes;
|
|
76
|
-
|
|
77
|
-
for (let key in nodes) {
|
|
78
|
-
nodes[key].reset();
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
74
|
}
|
|
82
75
|
|
|
83
76
|
|
package/src/resource.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import CustomFunction from '@esportsplus/custom-function';
|
|
2
|
-
import {
|
|
3
|
-
import { Options } from './types';
|
|
2
|
+
import { signal } from './signal';
|
|
3
|
+
import { Options, Signal } from './types';
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
type Function<A extends unknown[], R extends Promise<unknown>> = (...args: A) => R;
|
|
@@ -39,9 +39,9 @@ class Resource<A extends unknown[], R extends Promise<unknown>> extends CustomFu
|
|
|
39
39
|
this.#ok.set(false);
|
|
40
40
|
});
|
|
41
41
|
});
|
|
42
|
-
this.#data =
|
|
43
|
-
this.#input =
|
|
44
|
-
this.#ok =
|
|
42
|
+
this.#data = signal(undefined as Awaited<R>, options);
|
|
43
|
+
this.#input = signal<A | null>(null, options);
|
|
44
|
+
this.#ok = signal<boolean | null>(null, options);
|
|
45
45
|
}
|
|
46
46
|
|
|
47
47
|
|
|
@@ -63,12 +63,6 @@ class Resource<A extends unknown[], R extends Promise<unknown>> extends CustomFu
|
|
|
63
63
|
this.#input.dispose();
|
|
64
64
|
this.#ok.dispose();
|
|
65
65
|
}
|
|
66
|
-
|
|
67
|
-
reset() {
|
|
68
|
-
this.#data.reset();
|
|
69
|
-
this.#input.reset();
|
|
70
|
-
this.#ok.reset();
|
|
71
|
-
}
|
|
72
66
|
}
|
|
73
67
|
|
|
74
68
|
|
package/src/signal.ts
CHANGED
|
@@ -87,7 +87,14 @@ class Core<T> {
|
|
|
87
87
|
return;
|
|
88
88
|
}
|
|
89
89
|
|
|
90
|
-
|
|
90
|
+
this.dispatch('dispose', this);
|
|
91
|
+
|
|
92
|
+
removeSourceObservers(this, 0);
|
|
93
|
+
|
|
94
|
+
this.listeners = null;
|
|
95
|
+
this.observers = null;
|
|
96
|
+
this.sources = null;
|
|
97
|
+
this.state = DISPOSED;
|
|
91
98
|
}
|
|
92
99
|
|
|
93
100
|
on<T>(event: Event, listener: Listener<T>) {
|
|
@@ -143,10 +150,6 @@ class Computed<T> extends Core<T> {
|
|
|
143
150
|
get() {
|
|
144
151
|
return read(this);
|
|
145
152
|
}
|
|
146
|
-
|
|
147
|
-
reset() {
|
|
148
|
-
flush('reset', this, DIRTY, undefined as T);
|
|
149
|
-
}
|
|
150
153
|
}
|
|
151
154
|
|
|
152
155
|
class Effect extends Core<null> {
|
|
@@ -166,12 +169,6 @@ class Effect extends Core<null> {
|
|
|
166
169
|
get type(): Type {
|
|
167
170
|
return EFFECT;
|
|
168
171
|
}
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
reset() {
|
|
172
|
-
flush('reset', this, DIRTY, null);
|
|
173
|
-
update(this);
|
|
174
|
-
}
|
|
175
172
|
}
|
|
176
173
|
|
|
177
174
|
class Root extends Core<null> {
|
|
@@ -210,10 +207,6 @@ class Signal<T> extends Core<T> {
|
|
|
210
207
|
return read(this);
|
|
211
208
|
}
|
|
212
209
|
|
|
213
|
-
reset() {
|
|
214
|
-
flush('reset', this, CLEAN, this.value);
|
|
215
|
-
}
|
|
216
|
-
|
|
217
210
|
set(value: T): T {
|
|
218
211
|
return write(this, value);
|
|
219
212
|
}
|
|
@@ -224,18 +217,6 @@ function changed(a: unknown, b: unknown) {
|
|
|
224
217
|
return a !== b;
|
|
225
218
|
}
|
|
226
219
|
|
|
227
|
-
function flush<T>(event: Event, node: Core<T>, state: State, value: T) {
|
|
228
|
-
node.dispatch(event, node);
|
|
229
|
-
|
|
230
|
-
removeSourceObservers(node, 0);
|
|
231
|
-
|
|
232
|
-
node.listeners = null;
|
|
233
|
-
node.observers = null;
|
|
234
|
-
node.sources = null;
|
|
235
|
-
node.state = state;
|
|
236
|
-
node.value = value;
|
|
237
|
-
}
|
|
238
|
-
|
|
239
220
|
function notify<T>(nodes: Core<T>[] | null, state: typeof CHECK | typeof DIRTY) {
|
|
240
221
|
if (nodes === null) {
|
|
241
222
|
return;
|
|
@@ -313,8 +294,7 @@ function sync<T>(node: Core<T>) {
|
|
|
313
294
|
}
|
|
314
295
|
|
|
315
296
|
if (node.state === DIRTY) {
|
|
316
|
-
|
|
317
|
-
update(node);
|
|
297
|
+
update(node as Computed<T> | Effect);
|
|
318
298
|
}
|
|
319
299
|
else {
|
|
320
300
|
node.state = CLEAN;
|
|
@@ -420,21 +400,6 @@ const effect = (fn: Effect['fn']) => {
|
|
|
420
400
|
return new Effect(fn);
|
|
421
401
|
};
|
|
422
402
|
|
|
423
|
-
const reset = <T extends { reset: VoidFunction }>(reset?: T[] | T | null) => {
|
|
424
|
-
if (reset == null) {
|
|
425
|
-
}
|
|
426
|
-
else if (isArray(reset)) {
|
|
427
|
-
for (let i = 0, n = reset.length; i < n; i++) {
|
|
428
|
-
reset[i].reset();
|
|
429
|
-
}
|
|
430
|
-
}
|
|
431
|
-
else {
|
|
432
|
-
reset.reset();
|
|
433
|
-
}
|
|
434
|
-
|
|
435
|
-
return reset;
|
|
436
|
-
};
|
|
437
|
-
|
|
438
403
|
const root = <T>(fn: NeverAsync<(root: Root) => T>, scheduler?: Root['scheduler']) => {
|
|
439
404
|
let o = observer,
|
|
440
405
|
s = scope;
|
|
@@ -463,4 +428,5 @@ const signal = <T>(value: T, options?: Options) => {
|
|
|
463
428
|
};
|
|
464
429
|
|
|
465
430
|
|
|
466
|
-
export { computed, dispose, effect,
|
|
431
|
+
export { computed, dispose, effect, root, signal };
|
|
432
|
+
export { Computed, Effect, Root, Signal };
|
package/src/types.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Function, NeverAsync, Prettify } from '@esportsplus/typescript'
|
|
2
2
|
import { CHECK, CLEAN, COMPUTED, DIRTY, DISPOSED, EFFECT, ROOT, SIGNAL } from './constants';
|
|
3
|
-
import { Computed, Effect, Signal } from './signal';
|
|
3
|
+
import { Computed, Effect, Root, Signal } from './signal';
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
type Changed = (a: unknown, b: unknown) => boolean;
|
|
@@ -24,4 +24,4 @@ type State = typeof CHECK | typeof CLEAN | typeof DIRTY | typeof DISPOSED;
|
|
|
24
24
|
type Type = typeof COMPUTED | typeof EFFECT | typeof ROOT | typeof SIGNAL;
|
|
25
25
|
|
|
26
26
|
|
|
27
|
-
export { Changed, Computed, Effect, Event, Function, Listener, Object, Options, NeverAsync, Prettify, Signal, State, Type };
|
|
27
|
+
export type { Changed, Computed, Effect, Event, Function, Listener, Object, Options, NeverAsync, Prettify, Root, Signal, State, Type };
|
package/build/dispose.d.ts
DELETED
package/build/dispose.js
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { isArray } from './utilities';
|
|
2
|
-
export default (dispose) => {
|
|
3
|
-
if (dispose == null) {
|
|
4
|
-
}
|
|
5
|
-
else if (isArray(dispose)) {
|
|
6
|
-
for (let i = 0, n = dispose.length; i < n; i++) {
|
|
7
|
-
dispose[i].dispose();
|
|
8
|
-
}
|
|
9
|
-
}
|
|
10
|
-
else {
|
|
11
|
-
dispose.dispose();
|
|
12
|
-
}
|
|
13
|
-
return dispose;
|
|
14
|
-
};
|
package/build/reset.d.ts
DELETED
package/build/reset.js
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { isArray } from './utilities';
|
|
2
|
-
export default (reset) => {
|
|
3
|
-
if (reset == null) {
|
|
4
|
-
}
|
|
5
|
-
else if (isArray(reset)) {
|
|
6
|
-
for (let i = 0, n = reset.length; i < n; i++) {
|
|
7
|
-
reset[i].reset();
|
|
8
|
-
}
|
|
9
|
-
}
|
|
10
|
-
else {
|
|
11
|
-
reset.reset();
|
|
12
|
-
}
|
|
13
|
-
return reset;
|
|
14
|
-
};
|