@esportsplus/reactivity 0.1.9 → 0.1.11
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/constants.d.ts +3 -2
- package/build/constants.js +3 -2
- package/build/index.d.ts +1 -2
- package/build/index.js +1 -2
- package/build/macro.d.ts +1 -2
- package/build/macro.js +2 -5
- package/build/reactive/array.d.ts +1 -2
- package/build/reactive/array.js +3 -6
- package/build/reactive/index.js +1 -1
- package/build/reactive/object.d.ts +0 -1
- package/build/reactive/object.js +4 -10
- package/build/resource.d.ts +0 -1
- package/build/resource.js +13 -18
- package/build/signal.d.ts +43 -26
- package/build/signal.js +146 -121
- package/build/types.d.ts +4 -18
- package/build/types.js +2 -2
- package/package.json +2 -2
- package/src/constants.ts +4 -2
- package/src/index.ts +1 -2
- package/src/macro.ts +2 -6
- package/src/reactive/array.ts +3 -7
- package/src/reactive/index.ts +1 -1
- package/src/reactive/object.ts +6 -14
- package/src/resource.ts +13 -19
- package/src/signal.ts +195 -152
- package/src/types.ts +4 -22
package/build/constants.d.ts
CHANGED
|
@@ -4,5 +4,6 @@ declare const DIRTY = 2;
|
|
|
4
4
|
declare const DISPOSED = 3;
|
|
5
5
|
declare const COMPUTED = 0;
|
|
6
6
|
declare const EFFECT = 1;
|
|
7
|
-
declare const
|
|
8
|
-
|
|
7
|
+
declare const ROOT = 2;
|
|
8
|
+
declare const SIGNAL = 3;
|
|
9
|
+
export { CHECK, CLEAN, COMPUTED, DIRTY, DISPOSED, EFFECT, ROOT, SIGNAL };
|
package/build/constants.js
CHANGED
|
@@ -4,5 +4,6 @@ const DIRTY = 2;
|
|
|
4
4
|
const DISPOSED = 3;
|
|
5
5
|
const COMPUTED = 0;
|
|
6
6
|
const EFFECT = 1;
|
|
7
|
-
const
|
|
8
|
-
|
|
7
|
+
const ROOT = 2;
|
|
8
|
+
const SIGNAL = 3;
|
|
9
|
+
export { CHECK, CLEAN, COMPUTED, DIRTY, DISPOSED, EFFECT, ROOT, SIGNAL };
|
package/build/index.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
export { default as macro } from './macro';
|
|
2
2
|
export { default as resource } from './resource';
|
|
3
|
-
export * as core from './signal';
|
|
4
|
-
export { effect, root } from './signal';
|
|
5
3
|
export { default as reactive } from './reactive';
|
|
4
|
+
export { computed, dispose, effect, root, signal } from './signal';
|
|
6
5
|
export * from './types';
|
package/build/index.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
export { default as macro } from './macro';
|
|
2
2
|
export { default as resource } from './resource';
|
|
3
|
-
export * as core from './signal';
|
|
4
|
-
export { effect, root } from './signal';
|
|
5
3
|
export { default as reactive } from './reactive';
|
|
4
|
+
export { computed, dispose, effect, root, signal } from './signal';
|
|
6
5
|
export * from './types';
|
package/build/macro.d.ts
CHANGED
|
@@ -5,7 +5,6 @@ declare class Macro<A extends unknown[], R> extends CustomFunction {
|
|
|
5
5
|
#private;
|
|
6
6
|
constructor(fn: Function<A, R>, options?: Options);
|
|
7
7
|
dispose(): void;
|
|
8
|
-
reset(): void;
|
|
9
8
|
}
|
|
10
|
-
declare const _default: <A extends unknown[], R>(fn: (
|
|
9
|
+
declare const _default: <A extends unknown[], R>(fn: () => (...args: A) => R, options?: Options) => Macro<A, R>;
|
|
11
10
|
export default _default;
|
package/build/macro.js
CHANGED
|
@@ -1,19 +1,16 @@
|
|
|
1
1
|
import CustomFunction from '@esportsplus/custom-function';
|
|
2
|
-
import { computed
|
|
2
|
+
import { computed } from './signal';
|
|
3
3
|
class Macro extends CustomFunction {
|
|
4
4
|
#factory;
|
|
5
5
|
constructor(fn, options = {}) {
|
|
6
6
|
super((...args) => {
|
|
7
|
-
return
|
|
7
|
+
return this.#factory.get()(...args);
|
|
8
8
|
});
|
|
9
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;
|
|
@@ -54,7 +53,7 @@ declare class ReactiveObjectArray<T extends Object> extends ReactiveArray<Node<T
|
|
|
54
53
|
push(...values: T[]): number;
|
|
55
54
|
shift(): Node<T> | undefined;
|
|
56
55
|
sort(): never;
|
|
57
|
-
splice(start: number, deleteCount?: number, ...values: T[]): Node<T> | Node<T>[] | undefined;
|
|
56
|
+
splice(start: number, deleteCount?: number, ...values: T[]): Node<T> | Node<T>[] | null | undefined;
|
|
58
57
|
unshift(...values: T[]): number;
|
|
59
58
|
}
|
|
60
59
|
export { ReactiveArray, ReactiveObjectArray };
|
package/build/reactive/array.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { dispose,
|
|
1
|
+
import { dispose, signal } from '../signal';
|
|
2
2
|
import { ReactiveObject } from './object';
|
|
3
3
|
function factory(data, options = {}) {
|
|
4
4
|
let signals = [];
|
|
@@ -23,7 +23,7 @@ class ReactiveArray extends Array {
|
|
|
23
23
|
this.splice(n);
|
|
24
24
|
}
|
|
25
25
|
trigger() {
|
|
26
|
-
|
|
26
|
+
this.#signal.set(!this.#signal.value);
|
|
27
27
|
}
|
|
28
28
|
dispatch(event, data) {
|
|
29
29
|
this.#signal.dispatch(event, data);
|
|
@@ -57,9 +57,6 @@ class ReactiveArray extends Array {
|
|
|
57
57
|
this.trigger();
|
|
58
58
|
return n;
|
|
59
59
|
}
|
|
60
|
-
reset() {
|
|
61
|
-
this.#signal.reset();
|
|
62
|
-
}
|
|
63
60
|
reverse() {
|
|
64
61
|
super.reverse();
|
|
65
62
|
this.dispatch('reverse');
|
|
@@ -93,7 +90,7 @@ class ReactiveArray extends Array {
|
|
|
93
90
|
return removed;
|
|
94
91
|
}
|
|
95
92
|
track() {
|
|
96
|
-
|
|
93
|
+
this.#signal.get();
|
|
97
94
|
}
|
|
98
95
|
unshift(...items) {
|
|
99
96
|
let length = super.unshift(...items);
|
package/build/reactive/index.js
CHANGED
package/build/reactive/object.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { computed,
|
|
1
|
+
import { computed, signal } from '../signal';
|
|
2
2
|
import { defineProperty, isArray } from '../utilities';
|
|
3
3
|
import { ReactiveArray, ReactiveObjectArray } from './array';
|
|
4
4
|
class ReactiveObject {
|
|
@@ -12,7 +12,7 @@ class ReactiveObject {
|
|
|
12
12
|
defineProperty(this, key, {
|
|
13
13
|
enumerable: true,
|
|
14
14
|
get() {
|
|
15
|
-
return
|
|
15
|
+
return node.get();
|
|
16
16
|
}
|
|
17
17
|
});
|
|
18
18
|
}
|
|
@@ -37,10 +37,10 @@ class ReactiveObject {
|
|
|
37
37
|
defineProperty(this, key, {
|
|
38
38
|
enumerable: true,
|
|
39
39
|
get() {
|
|
40
|
-
return
|
|
40
|
+
return node.get();
|
|
41
41
|
},
|
|
42
42
|
set(value) {
|
|
43
|
-
|
|
43
|
+
node.set(value);
|
|
44
44
|
}
|
|
45
45
|
});
|
|
46
46
|
}
|
|
@@ -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;
|
|
@@ -8,47 +8,42 @@ class Resource extends CustomFunction {
|
|
|
8
8
|
constructor(fn, options = {}) {
|
|
9
9
|
super((...args) => {
|
|
10
10
|
this.stop = null;
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
this.#input.set(args);
|
|
12
|
+
this.#ok.set(null);
|
|
13
13
|
fn(...args)
|
|
14
14
|
.then((value) => {
|
|
15
15
|
if (this.stop === true) {
|
|
16
16
|
return;
|
|
17
17
|
}
|
|
18
|
-
|
|
19
|
-
|
|
18
|
+
this.#data.set(value);
|
|
19
|
+
this.#ok.set(true);
|
|
20
20
|
})
|
|
21
21
|
.catch(() => {
|
|
22
22
|
if (this.stop === true) {
|
|
23
23
|
return;
|
|
24
24
|
}
|
|
25
|
-
|
|
26
|
-
|
|
25
|
+
this.#data.set(undefined);
|
|
26
|
+
this.#ok.set(false);
|
|
27
27
|
});
|
|
28
28
|
});
|
|
29
|
-
this.#data = signal(
|
|
30
|
-
|
|
31
|
-
|
|
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
|
-
return
|
|
34
|
+
return this.#data.get();
|
|
35
35
|
}
|
|
36
36
|
get input() {
|
|
37
|
-
return
|
|
37
|
+
return this.#input.get();
|
|
38
38
|
}
|
|
39
39
|
get ok() {
|
|
40
|
-
return
|
|
40
|
+
return this.#ok.get();
|
|
41
41
|
}
|
|
42
42
|
dispose() {
|
|
43
43
|
this.#data.dispose();
|
|
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
|
@@ -1,34 +1,51 @@
|
|
|
1
|
-
import { Changed,
|
|
2
|
-
declare class
|
|
3
|
-
changed: Changed | null;
|
|
4
|
-
fn: Computed<T>['fn'] | Effect['fn'] | null;
|
|
1
|
+
import { Changed, Event, Function, Listener, NeverAsync, Options, State, Type } from './types';
|
|
2
|
+
declare class Core<T> {
|
|
5
3
|
listeners: Record<Event, (Listener<any> | null)[]> | null;
|
|
6
|
-
observers:
|
|
4
|
+
observers: Core<any>[] | null;
|
|
7
5
|
root: Root | null;
|
|
8
|
-
sources:
|
|
6
|
+
sources: Core<any>[] | null;
|
|
9
7
|
state: State;
|
|
10
|
-
|
|
11
|
-
type: Type;
|
|
12
|
-
updating: boolean | null;
|
|
8
|
+
updating: boolean;
|
|
13
9
|
value: T;
|
|
14
|
-
constructor(
|
|
10
|
+
constructor(state: State, value: T);
|
|
11
|
+
get type(): Type | never;
|
|
15
12
|
dispatch<D>(event: Event, data?: D): void;
|
|
16
13
|
dispose(): void;
|
|
17
|
-
on(event: Event, listener: Listener<
|
|
18
|
-
once(event: Event, listener: Listener<
|
|
19
|
-
reset(): void;
|
|
14
|
+
on<T>(event: Event, listener: Listener<T>): void;
|
|
15
|
+
once<T>(event: Event, listener: Listener<T>): void;
|
|
20
16
|
}
|
|
21
|
-
declare
|
|
17
|
+
declare class Computed<T> extends Core<T> {
|
|
18
|
+
changed: Changed;
|
|
19
|
+
fn: NeverAsync<() => T>;
|
|
20
|
+
constructor(fn: Computed<T>['fn'], options?: Options);
|
|
21
|
+
get type(): Type;
|
|
22
|
+
get(): T;
|
|
23
|
+
}
|
|
24
|
+
declare class Effect extends Core<null> {
|
|
25
|
+
fn: NeverAsync<(node: Effect) => void>;
|
|
26
|
+
task: Function;
|
|
27
|
+
constructor(fn: Effect['fn']);
|
|
28
|
+
get type(): Type;
|
|
29
|
+
}
|
|
30
|
+
declare class Root extends Core<null> {
|
|
31
|
+
scheduler: (fn: Function) => unknown;
|
|
32
|
+
tracking: boolean;
|
|
33
|
+
constructor(scheduler: Root['scheduler'], tracking: boolean);
|
|
34
|
+
get type(): Type;
|
|
35
|
+
}
|
|
36
|
+
declare class Signal<T> extends Core<T> {
|
|
37
|
+
changed: Changed;
|
|
38
|
+
constructor(data: T, options?: Options);
|
|
39
|
+
get type(): Type;
|
|
40
|
+
get(): T;
|
|
41
|
+
set(value: T): T;
|
|
42
|
+
}
|
|
43
|
+
declare const computed: <T>(fn: () => T extends unknown ? T : NeverAsync<T>, options?: Options) => Computed<T>;
|
|
22
44
|
declare const dispose: <T extends {
|
|
23
|
-
dispose:
|
|
24
|
-
}>(dispose?: T | T[] | undefined) => T | T[] | undefined;
|
|
25
|
-
declare const effect: (fn: Effect['fn']
|
|
26
|
-
declare const
|
|
27
|
-
declare const
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
declare function root<T>(fn: NeverAsync<() => T>, properties?: Root): T extends unknown ? T : NeverAsync<T>;
|
|
31
|
-
declare const signal: <T>(data: T, options?: Omit<Options, 'value'>) => Signal<T>;
|
|
32
|
-
declare const write: <T>(node: Signal<T>, value: unknown) => T;
|
|
33
|
-
export default Signal;
|
|
34
|
-
export { computed, dispose, effect, read, reset, root, signal, write };
|
|
45
|
+
dispose: VoidFunction;
|
|
46
|
+
}>(dispose?: T | T[] | null | undefined) => T | T[] | null | undefined;
|
|
47
|
+
declare const effect: (fn: Effect['fn']) => Effect;
|
|
48
|
+
declare const root: <T>(fn: (root: Root) => T, scheduler?: Root['scheduler']) => T;
|
|
49
|
+
declare const signal: <T>(value: T, options?: Options) => Signal<T>;
|
|
50
|
+
export { computed, dispose, effect, root, signal };
|
|
51
|
+
export { Computed, Effect, Signal };
|