@esportsplus/reactivity 0.4.7 → 0.5.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.
- package/.github/dependabot.yml +2 -0
- package/.github/workflows/bump.yml +2 -0
- package/.github/workflows/dependabot.yml +12 -0
- package/.github/workflows/publish.yml +2 -0
- package/build/constants.d.ts +7 -9
- package/build/constants.js +7 -9
- package/build/index.d.ts +1 -3
- package/build/index.js +1 -3
- package/build/reactive/array.d.ts +20 -17
- package/build/reactive/array.js +101 -52
- package/build/reactive/disposable.d.ts +4 -0
- package/build/reactive/disposable.js +6 -0
- package/build/reactive/index.d.ts +2 -2
- package/build/reactive/index.js +3 -3
- package/build/reactive/object.d.ts +12 -7
- package/build/reactive/object.js +42 -19
- package/build/signal.d.ts +15 -31
- package/build/signal.js +273 -235
- package/build/types.d.ts +27 -37
- package/build/types.js +1 -1
- package/package.json +4 -4
- package/readme.md +2 -2
- package/src/constants.ts +7 -12
- package/src/index.ts +1 -3
- package/src/reactive/array.ts +143 -67
- package/src/reactive/disposable.ts +8 -0
- package/src/reactive/index.ts +4 -4
- package/src/reactive/object.ts +56 -24
- package/src/signal.ts +338 -263
- package/src/types.ts +36 -57
- package/build/macro.d.ts +0 -9
- package/build/macro.js +0 -17
- package/src/macro.ts +0 -26
package/src/types.ts
CHANGED
|
@@ -1,82 +1,61 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { REACTIVE, STATE_CHECK, STATE_DIRTY, STATE_IN_HEAP, STATE_NONE, STATE_RECOMPUTING } from './constants';
|
|
2
|
+
import { oncleanup } from './signal';
|
|
2
3
|
import { ReactiveArray } from './reactive/array';
|
|
3
4
|
import { ReactiveObject } from './reactive/object';
|
|
4
|
-
import { CHECK, CLEAN, COMPUTED, DIRTY, DISPOSED, EFFECT, ROOT, SIGNAL } from './constants';
|
|
5
|
-
import { Reactive as ReactiveBase } from './signal';
|
|
6
5
|
|
|
7
6
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
7
|
+
interface Computed<T> extends Signal<T> {
|
|
8
|
+
[REACTIVE]: true;
|
|
9
|
+
cleanup: VoidFunction | VoidFunction[] | null;
|
|
10
|
+
deps: Link | null;
|
|
11
|
+
depsTail: Link | null;
|
|
12
|
+
fn: (oc?: typeof oncleanup) => T;
|
|
13
|
+
height: number;
|
|
14
|
+
nextHeap: Computed<unknown> | undefined;
|
|
15
|
+
prevHeap: Computed<unknown>;
|
|
16
|
+
state:
|
|
17
|
+
typeof STATE_CHECK |
|
|
18
|
+
typeof STATE_DIRTY |
|
|
19
|
+
typeof STATE_IN_HEAP |
|
|
20
|
+
typeof STATE_NONE |
|
|
21
|
+
typeof STATE_RECOMPUTING;
|
|
22
|
+
}
|
|
23
23
|
|
|
24
24
|
type Infer<T> =
|
|
25
25
|
T extends (...args: unknown[]) => unknown
|
|
26
26
|
? ReturnType<T>
|
|
27
27
|
: T extends (infer U)[]
|
|
28
28
|
? ReactiveArray<U>
|
|
29
|
-
: T extends ReactiveObject<
|
|
30
|
-
?
|
|
29
|
+
: T extends ReactiveObject<any>
|
|
30
|
+
? T
|
|
31
31
|
: T extends Record<PropertyKey, unknown>
|
|
32
32
|
? { [K in keyof T]: T[K] }
|
|
33
33
|
: T;
|
|
34
34
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
type Options = {
|
|
44
|
-
changed?: Changed;
|
|
45
|
-
};
|
|
35
|
+
interface Link {
|
|
36
|
+
dep: Signal<unknown> | Computed<unknown>;
|
|
37
|
+
sub: Computed<unknown>;
|
|
38
|
+
nextDep: Link | null;
|
|
39
|
+
nextSub: Link | null;
|
|
40
|
+
prevSub: Link | null;
|
|
41
|
+
}
|
|
46
42
|
|
|
47
43
|
type Reactive<T> = T extends Record<PropertyKey, unknown>
|
|
48
44
|
? ReactiveObject<T>
|
|
49
45
|
: ReactiveArray<T>;
|
|
50
46
|
|
|
51
|
-
type Root = {
|
|
52
|
-
scheduler: Scheduler;
|
|
53
|
-
tracking: boolean;
|
|
54
|
-
value: void;
|
|
55
|
-
} & Omit<ReactiveBase<void>, 'root'>;
|
|
56
|
-
|
|
57
|
-
type Scheduler = (fn: Function) => unknown;
|
|
58
|
-
|
|
59
47
|
type Signal<T> = {
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
type State = typeof CHECK | typeof CLEAN | typeof DIRTY | typeof DISPOSED;
|
|
66
|
-
|
|
67
|
-
type Type = typeof COMPUTED | typeof EFFECT | typeof ROOT | typeof SIGNAL;
|
|
48
|
+
[REACTIVE]: true;
|
|
49
|
+
subs: Link | null;
|
|
50
|
+
subsTail: Link | null;
|
|
51
|
+
value: T;
|
|
52
|
+
};
|
|
68
53
|
|
|
69
54
|
|
|
70
55
|
export type {
|
|
71
|
-
|
|
72
|
-
Effect, Event,
|
|
73
|
-
Function,
|
|
56
|
+
Computed,
|
|
74
57
|
Infer,
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
Prettify,
|
|
79
|
-
Reactive, ReactiveArray, ReactiveObject, Root,
|
|
80
|
-
Scheduler, Signal, State,
|
|
81
|
-
Type
|
|
58
|
+
Link,
|
|
59
|
+
Signal,
|
|
60
|
+
Reactive, ReactiveArray, ReactiveObject
|
|
82
61
|
};
|
package/build/macro.d.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import CustomFunction from '@esportsplus/custom-function';
|
|
2
|
-
import { Options } from './types.js';
|
|
3
|
-
declare class Macro<A extends unknown[], R> extends CustomFunction {
|
|
4
|
-
private factory;
|
|
5
|
-
constructor(fn: Macro<A, R>['factory']['fn'], options?: Options);
|
|
6
|
-
dispose(): void;
|
|
7
|
-
}
|
|
8
|
-
declare const _default: <A extends unknown[], R>(fn: Macro<A, R>["factory"]["fn"], options?: Options) => Macro<A, R>;
|
|
9
|
-
export default _default;
|
package/build/macro.js
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import CustomFunction from '@esportsplus/custom-function';
|
|
2
|
-
import { computed } from './signal.js';
|
|
3
|
-
class Macro extends CustomFunction {
|
|
4
|
-
factory;
|
|
5
|
-
constructor(fn, options = {}) {
|
|
6
|
-
super((...args) => {
|
|
7
|
-
return this.factory.get()(...args);
|
|
8
|
-
});
|
|
9
|
-
this.factory = computed(fn, options);
|
|
10
|
-
}
|
|
11
|
-
dispose() {
|
|
12
|
-
this.factory.dispose();
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
export default (fn, options = {}) => {
|
|
16
|
-
return new Macro(fn, options);
|
|
17
|
-
};
|
package/src/macro.ts
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import CustomFunction from '@esportsplus/custom-function';
|
|
2
|
-
import { computed } from './signal';
|
|
3
|
-
import { Computed, Options } from './types';
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
class Macro<A extends unknown[], R> extends CustomFunction {
|
|
7
|
-
private factory: Computed<(...args: A) => R>;
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
constructor(fn: Macro<A,R>['factory']['fn'], options: Options = {}) {
|
|
11
|
-
super((...args: A) => {
|
|
12
|
-
return this.factory.get()(...args);
|
|
13
|
-
});
|
|
14
|
-
this.factory = computed(fn, options);
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
dispose() {
|
|
19
|
-
this.factory.dispose();
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
export default <A extends unknown[], R>(fn: Macro<A,R>['factory']['fn'], options: Options = {}) => {
|
|
25
|
-
return new Macro(fn, options);
|
|
26
|
-
};
|