@esportsplus/reactivity 0.11.0 → 0.11.2
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/index.d.ts +2 -1
- package/build/system.js +10 -22
- package/build/types.d.ts +3 -2
- package/package.json +1 -1
- package/src/reactive/index.ts +3 -3
- package/src/system.ts +11 -25
- package/src/types.ts +3 -2
|
@@ -1,7 +1,8 @@
|
|
|
1
|
+
import { NeverAsync } from '@esportsplus/utilities';
|
|
1
2
|
import array from './array.js';
|
|
2
3
|
import object from './object.js';
|
|
3
4
|
type API<T> = T extends Record<PropertyKey, unknown> ? ReturnType<typeof object<T>> : T extends unknown[] ? ReturnType<typeof array<T>> : never;
|
|
4
|
-
type Input<T> = T extends (...args: unknown[]) =>
|
|
5
|
+
type Input<T> = T extends (...args: unknown[]) => unknown ? NeverAsync<T> : T extends {
|
|
5
6
|
dispose: any;
|
|
6
7
|
} | {
|
|
7
8
|
signals: any;
|
package/build/system.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { isArray, isObject
|
|
1
|
+
import { isArray, isObject } from '@esportsplus/utilities';
|
|
2
2
|
import { REACTIVE, STABILIZER_IDLE, STABILIZER_RUNNING, STABILIZER_SCHEDULED, STATE_CHECK, STATE_DIRTY, STATE_IN_HEAP, STATE_NONE, STATE_RECOMPUTING } from './constants.js';
|
|
3
3
|
let depth = 0, heap = new Array(2000), index = 0, length = 0, notified = false, observer = null, scheduler = queueMicrotask, stabilizer = STABILIZER_IDLE, version = 0;
|
|
4
4
|
function cleanup(node) {
|
|
@@ -138,7 +138,6 @@ function recompute(computed, del) {
|
|
|
138
138
|
catch (e) {
|
|
139
139
|
ok = false;
|
|
140
140
|
}
|
|
141
|
-
depth--;
|
|
142
141
|
observer = o;
|
|
143
142
|
computed.state = STATE_NONE;
|
|
144
143
|
let depsTail = computed.depsTail, toRemove = depsTail !== null ? depsTail.nextDep : computed.deps;
|
|
@@ -153,28 +152,17 @@ function recompute(computed, del) {
|
|
|
153
152
|
computed.deps = null;
|
|
154
153
|
}
|
|
155
154
|
}
|
|
156
|
-
if (ok) {
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
}
|
|
165
|
-
function set(computed, value) {
|
|
166
|
-
if (computed.value === value) {
|
|
167
|
-
return;
|
|
168
|
-
}
|
|
169
|
-
computed.value = value;
|
|
170
|
-
for (let c = computed.subs; c !== null; c = c.nextSub) {
|
|
171
|
-
let o = c.sub, state = o.state;
|
|
172
|
-
if (state & STATE_CHECK) {
|
|
173
|
-
o.state = state | STATE_DIRTY;
|
|
155
|
+
if (ok && value !== computed.value) {
|
|
156
|
+
computed.value = value;
|
|
157
|
+
for (let c = computed.subs; c !== null; c = c.nextSub) {
|
|
158
|
+
let o = c.sub, state = o.state;
|
|
159
|
+
if (state & STATE_CHECK) {
|
|
160
|
+
o.state = state | STATE_DIRTY;
|
|
161
|
+
}
|
|
162
|
+
insertIntoHeap(o);
|
|
174
163
|
}
|
|
175
|
-
insertIntoHeap(o);
|
|
176
164
|
}
|
|
177
|
-
if (
|
|
165
|
+
if (!--depth && stabilizer === STABILIZER_IDLE) {
|
|
178
166
|
stabilizer = STABILIZER_SCHEDULED;
|
|
179
167
|
scheduler(stabilize);
|
|
180
168
|
}
|
package/build/types.d.ts
CHANGED
|
@@ -2,18 +2,19 @@ import { REACTIVE, STATE_CHECK, STATE_DIRTY, STATE_IN_HEAP, STATE_NONE, STATE_RE
|
|
|
2
2
|
import { onCleanup } from './system.js';
|
|
3
3
|
import { ReactiveArray } from './reactive/array.js';
|
|
4
4
|
import { ReactiveObject } from './reactive/object.js';
|
|
5
|
+
import { NeverAsync } from '@esportsplus/utilities';
|
|
5
6
|
interface Computed<T> extends Signal<T> {
|
|
6
7
|
[REACTIVE]: true;
|
|
7
8
|
cleanup: VoidFunction | VoidFunction[] | null;
|
|
8
9
|
deps: Link | null;
|
|
9
10
|
depsTail: Link | null;
|
|
10
|
-
fn: (oc?: typeof onCleanup) => T
|
|
11
|
+
fn: NeverAsync<(oc?: typeof onCleanup) => T>;
|
|
11
12
|
height: number;
|
|
12
13
|
nextHeap: Computed<unknown> | undefined;
|
|
13
14
|
prevHeap: Computed<unknown>;
|
|
14
15
|
state: typeof STATE_CHECK | typeof STATE_DIRTY | typeof STATE_IN_HEAP | typeof STATE_NONE | typeof STATE_RECOMPUTING;
|
|
15
16
|
}
|
|
16
|
-
type Infer<T> = T extends (...args: unknown[]) => unknown ? ReturnType<
|
|
17
|
+
type Infer<T> = T extends (...args: unknown[]) => unknown ? ReturnType<T> : T extends (infer U)[] ? ReactiveArray<U> : T extends ReactiveObject<any> ? T : T extends Record<PropertyKey, unknown> ? {
|
|
17
18
|
[K in keyof T]: T[K];
|
|
18
19
|
} : T;
|
|
19
20
|
interface Link {
|
package/package.json
CHANGED
package/src/reactive/index.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { isArray, isObject } from '@esportsplus/utilities';
|
|
1
|
+
import { isArray, isObject, NeverAsync } from '@esportsplus/utilities';
|
|
2
2
|
import array from './array';
|
|
3
3
|
import object from './object';
|
|
4
4
|
|
|
@@ -11,8 +11,8 @@ type API<T> =
|
|
|
11
11
|
: never;
|
|
12
12
|
|
|
13
13
|
type Input<T> =
|
|
14
|
-
T extends (...args: unknown[]) =>
|
|
15
|
-
? T
|
|
14
|
+
T extends (...args: unknown[]) => unknown
|
|
15
|
+
? NeverAsync<T>
|
|
16
16
|
: T extends { dispose: any } | { signals: any }
|
|
17
17
|
? { never: '[ dispose, signals ] are reserved keys' }
|
|
18
18
|
: T extends Record<PropertyKey, unknown> | unknown[]
|
package/src/system.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { isArray, isObject
|
|
1
|
+
import { isArray, isObject } from '@esportsplus/utilities';
|
|
2
2
|
import {
|
|
3
3
|
REACTIVE,
|
|
4
4
|
STABILIZER_IDLE, STABILIZER_RUNNING, STABILIZER_SCHEDULED,
|
|
@@ -207,7 +207,6 @@ function recompute<T>(computed: Computed<T>, del: boolean) {
|
|
|
207
207
|
ok = false;
|
|
208
208
|
}
|
|
209
209
|
|
|
210
|
-
depth--;
|
|
211
210
|
observer = o;
|
|
212
211
|
computed.state = STATE_NONE;
|
|
213
212
|
|
|
@@ -228,35 +227,22 @@ function recompute<T>(computed: Computed<T>, del: boolean) {
|
|
|
228
227
|
}
|
|
229
228
|
}
|
|
230
229
|
|
|
231
|
-
if (ok) {
|
|
232
|
-
|
|
233
|
-
value.then(v => set(computed, v));
|
|
234
|
-
}
|
|
235
|
-
else {
|
|
236
|
-
set(computed, value);
|
|
237
|
-
}
|
|
238
|
-
}
|
|
239
|
-
}
|
|
230
|
+
if (ok && value !== computed.value) {
|
|
231
|
+
computed.value = value as T;
|
|
240
232
|
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
computed.value = value;
|
|
233
|
+
for (let c = computed.subs; c !== null; c = c.nextSub) {
|
|
234
|
+
let o = c.sub,
|
|
235
|
+
state = o.state;
|
|
247
236
|
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
237
|
+
if (state & STATE_CHECK) {
|
|
238
|
+
o.state = state | STATE_DIRTY;
|
|
239
|
+
}
|
|
251
240
|
|
|
252
|
-
|
|
253
|
-
o.state = state | STATE_DIRTY;
|
|
241
|
+
insertIntoHeap(o);
|
|
254
242
|
}
|
|
255
|
-
|
|
256
|
-
insertIntoHeap(o);
|
|
257
243
|
}
|
|
258
244
|
|
|
259
|
-
if (
|
|
245
|
+
if (!--depth && stabilizer === STABILIZER_IDLE) {
|
|
260
246
|
stabilizer = STABILIZER_SCHEDULED;
|
|
261
247
|
scheduler(stabilize);
|
|
262
248
|
}
|
package/src/types.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { REACTIVE, STATE_CHECK, STATE_DIRTY, STATE_IN_HEAP, STATE_NONE, STATE_RE
|
|
|
2
2
|
import { onCleanup } from './system';
|
|
3
3
|
import { ReactiveArray } from './reactive/array';
|
|
4
4
|
import { ReactiveObject } from './reactive/object';
|
|
5
|
+
import { NeverAsync } from '@esportsplus/utilities';
|
|
5
6
|
|
|
6
7
|
|
|
7
8
|
interface Computed<T> extends Signal<T> {
|
|
@@ -9,7 +10,7 @@ interface Computed<T> extends Signal<T> {
|
|
|
9
10
|
cleanup: VoidFunction | VoidFunction[] | null;
|
|
10
11
|
deps: Link | null;
|
|
11
12
|
depsTail: Link | null;
|
|
12
|
-
fn: (oc?: typeof onCleanup) => T
|
|
13
|
+
fn: NeverAsync<(oc?: typeof onCleanup) => T>;
|
|
13
14
|
height: number;
|
|
14
15
|
nextHeap: Computed<unknown> | undefined;
|
|
15
16
|
prevHeap: Computed<unknown>;
|
|
@@ -23,7 +24,7 @@ interface Computed<T> extends Signal<T> {
|
|
|
23
24
|
|
|
24
25
|
type Infer<T> =
|
|
25
26
|
T extends (...args: unknown[]) => unknown
|
|
26
|
-
? ReturnType<
|
|
27
|
+
? ReturnType<T>
|
|
27
28
|
: T extends (infer U)[]
|
|
28
29
|
? ReactiveArray<U>
|
|
29
30
|
: T extends ReactiveObject<any>
|