@esportsplus/reactivity 0.1.2 → 0.1.3
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/reactive/object.d.ts +2 -1
- package/build/reactive/object.js +4 -1
- package/build/signal.js +11 -6
- package/package.json +1 -1
- package/src/reactive/object.ts +8 -2
- package/src/signal.ts +12 -7
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { Computed, Object, Options, Signal } from '../types';
|
|
2
2
|
import { ReactiveArray, ReactiveObjectArray } from './array';
|
|
3
|
+
type Node = Computed<unknown> | ReactiveArray<unknown> | ReactiveObjectArray<Object> | Signal<unknown>;
|
|
3
4
|
declare class ReactiveObject<T extends Object> {
|
|
4
|
-
nodes: Record<PropertyKey,
|
|
5
|
+
nodes: Record<PropertyKey, Node>;
|
|
5
6
|
constructor(data: T, options?: Options);
|
|
6
7
|
dispose(): void;
|
|
7
8
|
reset(): void;
|
package/build/reactive/object.js
CHANGED
|
@@ -10,6 +10,7 @@ class ReactiveObject {
|
|
|
10
10
|
if (typeof input === 'function') {
|
|
11
11
|
let node = nodes[key] = computed(input, options);
|
|
12
12
|
defineProperty(this, key, {
|
|
13
|
+
enumerable: true,
|
|
13
14
|
get() {
|
|
14
15
|
return read(node);
|
|
15
16
|
}
|
|
@@ -17,13 +18,14 @@ class ReactiveObject {
|
|
|
17
18
|
}
|
|
18
19
|
else if (isArray(input)) {
|
|
19
20
|
let node, test = input[0];
|
|
20
|
-
if (typeof test === 'object' && test !== null && test
|
|
21
|
+
if (typeof test === 'object' && test !== null && test?.constructor?.name === 'Object') {
|
|
21
22
|
node = nodes[key] = new ReactiveObjectArray(input, options);
|
|
22
23
|
}
|
|
23
24
|
else {
|
|
24
25
|
node = nodes[key] = new ReactiveArray(input);
|
|
25
26
|
}
|
|
26
27
|
defineProperty(this, key, {
|
|
28
|
+
enumerable: true,
|
|
27
29
|
get() {
|
|
28
30
|
node.track();
|
|
29
31
|
return node;
|
|
@@ -33,6 +35,7 @@ class ReactiveObject {
|
|
|
33
35
|
else {
|
|
34
36
|
let node = nodes[key] = signal(input, options);
|
|
35
37
|
defineProperty(this, key, {
|
|
38
|
+
enumerable: true,
|
|
36
39
|
get() {
|
|
37
40
|
return read(node);
|
|
38
41
|
},
|
package/build/signal.js
CHANGED
|
@@ -216,12 +216,17 @@ const dispose = (dispose) => {
|
|
|
216
216
|
return dispose;
|
|
217
217
|
};
|
|
218
218
|
const effect = (fn, options = {}) => {
|
|
219
|
-
|
|
219
|
+
let node = new Signal(undefined, DIRTY, EFFECT, options);
|
|
220
|
+
if (scope !== null) {
|
|
221
|
+
node.root = scope;
|
|
222
|
+
}
|
|
223
|
+
else if (observer !== null && observer.type === EFFECT && observer.root !== null) {
|
|
224
|
+
node.root = observer.root;
|
|
225
|
+
}
|
|
226
|
+
else {
|
|
220
227
|
throw new Error('Reactivity: `effects` cannot be created without a reactive root');
|
|
221
228
|
}
|
|
222
|
-
let node = new Signal(undefined, DIRTY, EFFECT, options);
|
|
223
229
|
node.fn = fn;
|
|
224
|
-
node.root = scope;
|
|
225
230
|
node.task = () => read(node);
|
|
226
231
|
node.root.scheduler(node.task);
|
|
227
232
|
return node;
|
|
@@ -230,8 +235,8 @@ const read = (node) => {
|
|
|
230
235
|
if (node.state === DISPOSED) {
|
|
231
236
|
return node.value;
|
|
232
237
|
}
|
|
233
|
-
if (observer) {
|
|
234
|
-
if (
|
|
238
|
+
if (observer !== null) {
|
|
239
|
+
if (observers === null) {
|
|
235
240
|
if (observer.sources !== null && observer.sources[index] == node) {
|
|
236
241
|
index++;
|
|
237
242
|
}
|
|
@@ -243,7 +248,7 @@ const read = (node) => {
|
|
|
243
248
|
observers.push(node);
|
|
244
249
|
}
|
|
245
250
|
}
|
|
246
|
-
if (node.fn) {
|
|
251
|
+
if (node.fn !== null) {
|
|
247
252
|
sync(node);
|
|
248
253
|
}
|
|
249
254
|
return node.value;
|
package/package.json
CHANGED
package/src/reactive/object.ts
CHANGED
|
@@ -4,8 +4,11 @@ import { defineProperty, isArray } from '~/utilities';
|
|
|
4
4
|
import { ReactiveArray, ReactiveObjectArray } from './array';
|
|
5
5
|
|
|
6
6
|
|
|
7
|
+
type Node = Computed<unknown> | ReactiveArray<unknown> | ReactiveObjectArray<Object> | Signal<unknown>;
|
|
8
|
+
|
|
9
|
+
|
|
7
10
|
class ReactiveObject<T extends Object> {
|
|
8
|
-
nodes: Record<PropertyKey,
|
|
11
|
+
nodes: Record<PropertyKey, Node> = {};
|
|
9
12
|
|
|
10
13
|
|
|
11
14
|
constructor(data: T, options: Options = {}) {
|
|
@@ -18,6 +21,7 @@ class ReactiveObject<T extends Object> {
|
|
|
18
21
|
let node = nodes[key] = computed(input as Computed<unknown>['fn'], options);
|
|
19
22
|
|
|
20
23
|
defineProperty(this, key, {
|
|
24
|
+
enumerable: true,
|
|
21
25
|
get() {
|
|
22
26
|
return read(node);
|
|
23
27
|
}
|
|
@@ -27,7 +31,7 @@ class ReactiveObject<T extends Object> {
|
|
|
27
31
|
let node: ReactiveArray<unknown> | ReactiveObjectArray<Object>,
|
|
28
32
|
test = input[0];
|
|
29
33
|
|
|
30
|
-
if (typeof test === 'object' && test !== null && test
|
|
34
|
+
if (typeof test === 'object' && test !== null && test?.constructor?.name === 'Object') {
|
|
31
35
|
node = nodes[key] = new ReactiveObjectArray(input, options);
|
|
32
36
|
}
|
|
33
37
|
else {
|
|
@@ -35,6 +39,7 @@ class ReactiveObject<T extends Object> {
|
|
|
35
39
|
}
|
|
36
40
|
|
|
37
41
|
defineProperty(this, key, {
|
|
42
|
+
enumerable: true,
|
|
38
43
|
get() {
|
|
39
44
|
node.track();
|
|
40
45
|
|
|
@@ -46,6 +51,7 @@ class ReactiveObject<T extends Object> {
|
|
|
46
51
|
let node = nodes[key] = signal(input, options);
|
|
47
52
|
|
|
48
53
|
defineProperty(this, key, {
|
|
54
|
+
enumerable: true,
|
|
49
55
|
get() {
|
|
50
56
|
return read(node);
|
|
51
57
|
},
|
package/src/signal.ts
CHANGED
|
@@ -286,14 +286,19 @@ const dispose = <T extends { dispose: () => void }>(dispose?: T[] | T) => {
|
|
|
286
286
|
};
|
|
287
287
|
|
|
288
288
|
const effect = <T>(fn: Effect<T>['fn'], options: Omit<Options, 'value'> = {}) => {
|
|
289
|
-
|
|
289
|
+
let node = new Signal(undefined as any, DIRTY, EFFECT, options);
|
|
290
|
+
|
|
291
|
+
if (scope !== null) {
|
|
292
|
+
node.root = scope;
|
|
293
|
+
}
|
|
294
|
+
else if (observer !== null && observer.type === EFFECT && observer.root !== null) {
|
|
295
|
+
node.root = observer.root;
|
|
296
|
+
}
|
|
297
|
+
else {
|
|
290
298
|
throw new Error('Reactivity: `effects` cannot be created without a reactive root');
|
|
291
299
|
}
|
|
292
300
|
|
|
293
|
-
let node = new Signal(undefined as any, DIRTY, EFFECT, options);
|
|
294
|
-
|
|
295
301
|
node.fn = fn;
|
|
296
|
-
node.root = scope;
|
|
297
302
|
node.task = () => read(node);
|
|
298
303
|
|
|
299
304
|
node.root.scheduler(node.task);
|
|
@@ -306,8 +311,8 @@ const read = <T>(node: Signal<T>): typeof node['value'] => {
|
|
|
306
311
|
return node.value;
|
|
307
312
|
}
|
|
308
313
|
|
|
309
|
-
if (observer) {
|
|
310
|
-
if (
|
|
314
|
+
if (observer !== null) {
|
|
315
|
+
if (observers === null) {
|
|
311
316
|
if (observer.sources !== null && observer.sources[index] == node) {
|
|
312
317
|
index++;
|
|
313
318
|
}
|
|
@@ -320,7 +325,7 @@ const read = <T>(node: Signal<T>): typeof node['value'] => {
|
|
|
320
325
|
}
|
|
321
326
|
}
|
|
322
327
|
|
|
323
|
-
if (node.fn) {
|
|
328
|
+
if (node.fn !== null) {
|
|
324
329
|
sync(node);
|
|
325
330
|
}
|
|
326
331
|
|