@esportsplus/reactivity 0.7.0 → 0.8.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.
@@ -1,4 +1,4 @@
1
- import { isArray, isFunction, isInstanceOf, isNumber, isObject } from '@esportsplus/utilities';
1
+ import { isFunction, isInstanceOf, isNumber, isObject } from '@esportsplus/utilities';
2
2
  import { computed, dispose, isComputed, read } from '../signal.js';
3
3
  import object from './object.js';
4
4
  import { Disposable } from './disposable.js';
@@ -162,10 +162,7 @@ function factory(input) {
162
162
  let items = [];
163
163
  for (let i = 0, n = input.length; i < n; i++) {
164
164
  let value = input[i];
165
- if (isArray(value)) {
166
- items[i] = array(value);
167
- }
168
- else if (isFunction(value)) {
165
+ if (isFunction(value)) {
169
166
  items[i] = computed(value);
170
167
  }
171
168
  else if (isObject(value)) {
@@ -196,7 +193,7 @@ export default function array(input) {
196
193
  if (isNumber(key)) {
197
194
  let host = wrapped[key];
198
195
  if (host === undefined || !isComputed(host)) {
199
- wrapped[key] = factory([value])[0];
196
+ a.splice(key, 1, value);
200
197
  }
201
198
  else {
202
199
  return false;
@@ -1,4 +1,4 @@
1
- import { defineProperty, isArray, isAsyncFunction, isFunction, isInstanceOf, isObject } from '@esportsplus/utilities';
1
+ import { defineProperty, isArray, isAsyncFunction, isFunction, isInstanceOf } from '@esportsplus/utilities';
2
2
  import array from './array.js';
3
3
  import { computed, dispose, read, signal } from '../signal.js';
4
4
  import { Disposable } from './disposable.js';
@@ -20,12 +20,12 @@ class ReactiveObject extends Disposable {
20
20
  return a;
21
21
  },
22
22
  set(v) {
23
- set(t, !!t.value);
24
23
  a = disposable[key] = array(v);
24
+ set(t, !!t.value);
25
25
  }
26
26
  });
27
27
  }
28
- if (isAsyncFunction(value)) {
28
+ else if (isAsyncFunction(value)) {
29
29
  let p = promise(value);
30
30
  defineProperty(this, key, {
31
31
  enumerable: true,
@@ -43,28 +43,11 @@ class ReactiveObject extends Disposable {
43
43
  }
44
44
  });
45
45
  }
46
- else if (isObject(value)) {
47
- let o = disposable[key] = new ReactiveObject(value), t = triggers[key] = signal(false);
48
- defineProperty(this, key, {
49
- enumerable: true,
50
- get() {
51
- read(t);
52
- return o;
53
- },
54
- set(v) {
55
- set(t, !!t.value);
56
- o = disposable[key] = new ReactiveObject(v);
57
- }
58
- });
59
- }
60
46
  else {
61
47
  let s = signal(value);
62
48
  defineProperty(this, key, {
63
49
  enumerable: true,
64
50
  get() {
65
- if (s === undefined) {
66
- s = signal(value);
67
- }
68
51
  return read(s);
69
52
  },
70
53
  set(v) {
package/build/signal.d.ts CHANGED
@@ -11,5 +11,8 @@ declare const signal: {
11
11
  <T>(value: T): Signal<T>;
12
12
  set<T>(el: Signal<T>, v: T): void;
13
13
  };
14
- declare const stabilize: () => void;
14
+ declare const stabilize: {
15
+ (): void;
16
+ state: Signal<number>;
17
+ };
15
18
  export { computed, dispose, isComputed, isReactive, isSignal, oncleanup, read, root, signal, stabilize };
package/build/signal.js CHANGED
@@ -1,6 +1,5 @@
1
1
  import { isArray, isObject } from '@esportsplus/utilities';
2
2
  import { REACTIVE, STATE_CHECK, STATE_DIRTY, STATE_IN_HEAP, STATE_NONE, STATE_RECOMPUTING } from './constants.js';
3
- import { state } from './scheduler.js';
4
3
  let dirtyHeap = new Array(2000), maxDirty = 0, markedHeap = false, minDirty = 0, observer = null;
5
4
  function cleanup(node) {
6
5
  if (!node.cleanup) {
@@ -160,8 +159,8 @@ function recompute(el, del) {
160
159
  insertIntoHeap(o);
161
160
  }
162
161
  }
163
- if (state.value === STATE_NONE) {
164
- root(() => signal.set(state, STATE_DIRTY));
162
+ if (stabilize.state.value === STATE_NONE) {
163
+ root(() => signal.set(stabilize.state, STATE_DIRTY));
165
164
  }
166
165
  }
167
166
  function unlink(link) {
@@ -319,7 +318,8 @@ const stabilize = () => {
319
318
  el = next;
320
319
  }
321
320
  }
322
- signal.set(state, STATE_NONE);
321
+ signal.set(stabilize.state, STATE_NONE);
323
322
  });
324
323
  };
324
+ stabilize.state = signal(STATE_NONE);
325
325
  export { computed, dispose, isComputed, isReactive, isSignal, oncleanup, read, root, signal, stabilize };
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "author": "ICJR",
3
3
  "dependencies": {
4
4
  "@esportsplus/custom-function": "^0.0.13",
5
- "@esportsplus/utilities": "^0.19.1"
5
+ "@esportsplus/utilities": "^0.21.0"
6
6
  },
7
7
  "devDependencies": {
8
8
  "@esportsplus/typescript": "^0.9.2"
@@ -12,7 +12,7 @@
12
12
  "private": false,
13
13
  "type": "module",
14
14
  "types": "build/index.d.ts",
15
- "version": "0.7.0",
15
+ "version": "0.8.0",
16
16
  "scripts": {
17
17
  "build": "tsc && tsc-alias",
18
18
  "-": "-"
@@ -1,4 +1,4 @@
1
- import { isArray, isFunction, isInstanceOf, isNumber, isObject } from '@esportsplus/utilities';
1
+ import { isFunction, isInstanceOf, isNumber, isObject } from '@esportsplus/utilities';
2
2
  import { computed, dispose, isComputed, read } from '~/signal';
3
3
  import { Computed, Infer } from '~/types';
4
4
  import object, { ReactiveObject } from './object';
@@ -284,10 +284,7 @@ function factory<T>(input: T[]) {
284
284
  for (let i = 0, n = input.length; i < n; i++) {
285
285
  let value = input[i];
286
286
 
287
- if (isArray(value)) {
288
- items[i] = array(value);
289
- }
290
- else if (isFunction(value)) {
287
+ if (isFunction(value)) {
291
288
  items[i] = computed(value as Computed<T>['fn']);
292
289
  }
293
290
  else if (isObject(value)) {
@@ -325,7 +322,7 @@ export default function array<T>(input: T[]) {
325
322
  let host = wrapped[key];
326
323
 
327
324
  if (host === undefined || !isComputed(host)) {
328
- wrapped[key] = factory([value] as T[])[0];
325
+ a.splice(key, 1, value);
329
326
  }
330
327
  else {
331
328
  return false;
@@ -1,4 +1,4 @@
1
- import { defineProperty, isArray, isAsyncFunction, isFunction, isInstanceOf, isObject, Prettify } from '@esportsplus/utilities';
1
+ import { defineProperty, isArray, isAsyncFunction, isFunction, isInstanceOf, Prettify } from '@esportsplus/utilities';
2
2
  import array, { ReactiveArray } from './array';
3
3
  import { computed, dispose, read, signal } from '~/signal';
4
4
  import { Computed, Infer, Signal } from '~/types';
@@ -39,12 +39,12 @@ class ReactiveObject<T extends Record<PropertyKey, unknown>> extends Disposable
39
39
  return a;
40
40
  },
41
41
  set(v: typeof value) {
42
- set(t, !!t.value);
43
42
  a = disposable[key] = array(v);
43
+ set(t, !!t.value);
44
44
  }
45
45
  });
46
46
  }
47
- if (isAsyncFunction(value)) {
47
+ else if (isAsyncFunction(value)) {
48
48
  let p = promise(value);
49
49
 
50
50
  defineProperty(this, key, {
@@ -64,32 +64,12 @@ class ReactiveObject<T extends Record<PropertyKey, unknown>> extends Disposable
64
64
  }
65
65
  });
66
66
  }
67
- else if (isObject(value)) {
68
- let o = disposable[key] = new ReactiveObject(value),
69
- t = triggers[key] = signal(false);
70
-
71
- defineProperty(this, key, {
72
- enumerable: true,
73
- get() {
74
- read(t);
75
- return o;
76
- },
77
- set(v: typeof value) {
78
- set(t, !!t.value);
79
- o = disposable[key] = new ReactiveObject(v);
80
- }
81
- });
82
- }
83
67
  else {
84
68
  let s = signal(value);
85
69
 
86
70
  defineProperty(this, key, {
87
71
  enumerable: true,
88
72
  get() {
89
- if (s === undefined) {
90
- s = signal(value);
91
- }
92
-
93
73
  return read(s as Signal<typeof value>);
94
74
  },
95
75
  set(v: typeof value) {
package/src/signal.ts CHANGED
@@ -1,7 +1,6 @@
1
1
  import { isArray, isObject } from '@esportsplus/utilities';
2
2
  import { REACTIVE, STATE_CHECK, STATE_DIRTY, STATE_IN_HEAP, STATE_NONE, STATE_RECOMPUTING } from './constants';
3
3
  import { Computed, Link, Signal, } from './types';
4
- import { state } from './scheduler';
5
4
 
6
5
 
7
6
  let dirtyHeap: (Computed<unknown> | undefined)[] = new Array(2000),
@@ -228,8 +227,8 @@ function recompute<T>(el: Computed<T>, del: boolean) {
228
227
  }
229
228
  }
230
229
 
231
- if (state.value === STATE_NONE) {
232
- root(() => signal.set(state, STATE_DIRTY));
230
+ if (stabilize.state.value === STATE_NONE) {
231
+ root(() => signal.set(stabilize.state, STATE_DIRTY));
233
232
  }
234
233
  }
235
234
 
@@ -441,10 +440,12 @@ const stabilize = () => {
441
440
  }
442
441
  }
443
442
 
444
- signal.set(state, STATE_NONE);
443
+ signal.set(stabilize.state, STATE_NONE);
445
444
  });
446
445
  };
447
446
 
447
+ stabilize.state = signal(STATE_NONE);
448
+
448
449
 
449
450
  export {
450
451
  computed,