@esportsplus/reactivity 0.1.19 → 0.1.21
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/.editorconfig +9 -9
- package/.gitattributes +2 -2
- package/.github/dependabot.yml +23 -0
- package/.github/workflows/bump.yml +7 -0
- package/.github/workflows/publish.yml +14 -0
- package/build/constants.js +1 -11
- package/build/index.js +6 -34
- package/build/macro.d.ts +1 -1
- package/build/macro.js +5 -10
- package/build/reactive/array.js +8 -12
- package/build/reactive/index.js +3 -5
- package/build/reactive/object.js +12 -15
- package/build/resource.js +7 -12
- package/build/signal.d.ts +3 -3
- package/build/signal.js +27 -34
- package/build/types.js +1 -2
- package/build/utilities.js +1 -5
- package/package.json +20 -20
- package/readme.md +1 -1
- package/src/constants.ts +18 -18
- package/src/index.ts +5 -5
- package/src/macro.ts +28 -28
- package/src/reactive/array.ts +212 -214
- package/src/reactive/index.ts +37 -37
- package/src/reactive/object.ts +76 -76
- package/src/resource.ts +70 -70
- package/src/signal.ts +375 -375
- package/src/types.ts +54 -54
- package/src/utilities.ts +5 -5
- package/tsconfig.json +10 -10
package/.editorconfig
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
root = true
|
|
2
|
-
|
|
3
|
-
[*]
|
|
4
|
-
indent_style = space
|
|
5
|
-
indent_size = 4
|
|
6
|
-
charset = utf-8
|
|
7
|
-
trim_trailing_whitespace = true
|
|
8
|
-
insert_final_newline = true
|
|
9
|
-
end_of_line = lf
|
|
1
|
+
root = true
|
|
2
|
+
|
|
3
|
+
[*]
|
|
4
|
+
indent_style = space
|
|
5
|
+
indent_size = 4
|
|
6
|
+
charset = utf-8
|
|
7
|
+
trim_trailing_whitespace = true
|
|
8
|
+
insert_final_newline = true
|
|
9
|
+
end_of_line = lf
|
package/.gitattributes
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
# Auto detect text files and perform LF normalization
|
|
2
|
-
* text=auto
|
|
1
|
+
# Auto detect text files and perform LF normalization
|
|
2
|
+
* text=auto
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# To get started with Dependabot version updates, you'll need to specify which
|
|
2
|
+
# package ecosystems to update and where the package manifests are located.
|
|
3
|
+
# Please see the documentation for all configuration options:
|
|
4
|
+
# https://docs.github.com/code-security/dependabot/dependabot-version-updates/configuration-options-for-the-dependabot.yml-file
|
|
5
|
+
|
|
6
|
+
version: 2
|
|
7
|
+
registries:
|
|
8
|
+
npm-npmjs:
|
|
9
|
+
token: ${{secrets.NPM_TOKEN}}
|
|
10
|
+
type: npm-registry
|
|
11
|
+
url: https://registry.npmjs.org
|
|
12
|
+
updates:
|
|
13
|
+
- package-ecosystem: "npm"
|
|
14
|
+
directory: "/"
|
|
15
|
+
groups:
|
|
16
|
+
production-dependencies:
|
|
17
|
+
dependency-type: "production"
|
|
18
|
+
development-dependencies:
|
|
19
|
+
dependency-type: "development"
|
|
20
|
+
registries:
|
|
21
|
+
- npm-npmjs
|
|
22
|
+
schedule:
|
|
23
|
+
interval: "daily"
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
name: publish to npm
|
|
2
|
+
on:
|
|
3
|
+
release:
|
|
4
|
+
types: [published]
|
|
5
|
+
workflow_dispatch:
|
|
6
|
+
workflow_run:
|
|
7
|
+
workflows: [bump]
|
|
8
|
+
types:
|
|
9
|
+
- completed
|
|
10
|
+
jobs:
|
|
11
|
+
publish:
|
|
12
|
+
secrets:
|
|
13
|
+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN_PUBLISHING }}
|
|
14
|
+
uses: esportsplus/workflows/.github/workflows/publish.yml@main
|
package/build/constants.js
CHANGED
|
@@ -1,19 +1,9 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SIGNAL = exports.ROOT = exports.EFFECT = exports.DISPOSED = exports.DIRTY = exports.COMPUTED = exports.CLEAN = exports.CHECK = void 0;
|
|
4
1
|
const CLEAN = 0;
|
|
5
|
-
exports.CLEAN = CLEAN;
|
|
6
2
|
const CHECK = 1;
|
|
7
|
-
exports.CHECK = CHECK;
|
|
8
3
|
const DIRTY = 2;
|
|
9
|
-
exports.DIRTY = DIRTY;
|
|
10
4
|
const DISPOSED = 3;
|
|
11
|
-
exports.DISPOSED = DISPOSED;
|
|
12
5
|
const COMPUTED = 0;
|
|
13
|
-
exports.COMPUTED = COMPUTED;
|
|
14
6
|
const EFFECT = 1;
|
|
15
|
-
exports.EFFECT = EFFECT;
|
|
16
7
|
const ROOT = 2;
|
|
17
|
-
exports.ROOT = ROOT;
|
|
18
8
|
const SIGNAL = 3;
|
|
19
|
-
|
|
9
|
+
export { CHECK, CLEAN, COMPUTED, DIRTY, DISPOSED, EFFECT, ROOT, SIGNAL };
|
package/build/index.js
CHANGED
|
@@ -1,34 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
17
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
18
|
-
};
|
|
19
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
-
exports.signal = exports.root = exports.effect = exports.dispose = exports.computed = exports.reactive = exports.resource = exports.macro = void 0;
|
|
21
|
-
var macro_1 = require("./macro");
|
|
22
|
-
Object.defineProperty(exports, "macro", { enumerable: true, get: function () { return __importDefault(macro_1).default; } });
|
|
23
|
-
var resource_1 = require("./resource");
|
|
24
|
-
Object.defineProperty(exports, "resource", { enumerable: true, get: function () { return __importDefault(resource_1).default; } });
|
|
25
|
-
var reactive_1 = require("./reactive");
|
|
26
|
-
Object.defineProperty(exports, "reactive", { enumerable: true, get: function () { return __importDefault(reactive_1).default; } });
|
|
27
|
-
var signal_1 = require("./signal");
|
|
28
|
-
Object.defineProperty(exports, "computed", { enumerable: true, get: function () { return signal_1.computed; } });
|
|
29
|
-
Object.defineProperty(exports, "dispose", { enumerable: true, get: function () { return signal_1.dispose; } });
|
|
30
|
-
Object.defineProperty(exports, "effect", { enumerable: true, get: function () { return signal_1.effect; } });
|
|
31
|
-
Object.defineProperty(exports, "root", { enumerable: true, get: function () { return signal_1.root; } });
|
|
32
|
-
Object.defineProperty(exports, "signal", { enumerable: true, get: function () { return signal_1.signal; } });
|
|
33
|
-
__exportStar(require("./constants"), exports);
|
|
34
|
-
__exportStar(require("./types"), exports);
|
|
1
|
+
export { default as macro } from './macro';
|
|
2
|
+
export { default as resource } from './resource';
|
|
3
|
+
export { default as reactive } from './reactive';
|
|
4
|
+
export { computed, dispose, effect, root, signal } from './signal';
|
|
5
|
+
export * from './constants';
|
|
6
|
+
export * from './types';
|
package/build/macro.d.ts
CHANGED
|
@@ -6,5 +6,5 @@ declare class Macro<A extends unknown[], R> extends CustomFunction {
|
|
|
6
6
|
constructor(fn: Function<A, R>, options?: Options);
|
|
7
7
|
dispose(): void;
|
|
8
8
|
}
|
|
9
|
-
declare const _default: <A extends unknown[], R>(fn:
|
|
9
|
+
declare const _default: <A extends unknown[], R>(fn: Function<A, R>, options?: Options) => Macro<A, R>;
|
|
10
10
|
export default _default;
|
package/build/macro.js
CHANGED
|
@@ -1,22 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const custom_function_1 = __importDefault(require("@esportsplus/custom-function"));
|
|
7
|
-
const signal_1 = require("./signal");
|
|
8
|
-
class Macro extends custom_function_1.default {
|
|
1
|
+
import CustomFunction from '@esportsplus/custom-function';
|
|
2
|
+
import { computed } from './signal';
|
|
3
|
+
class Macro extends CustomFunction {
|
|
9
4
|
#factory;
|
|
10
5
|
constructor(fn, options = {}) {
|
|
11
6
|
super((...args) => {
|
|
12
7
|
return this.#factory.get()(...args);
|
|
13
8
|
});
|
|
14
|
-
this.#factory =
|
|
9
|
+
this.#factory = computed(fn, options);
|
|
15
10
|
}
|
|
16
11
|
dispose() {
|
|
17
12
|
this.#factory.dispose();
|
|
18
13
|
}
|
|
19
14
|
}
|
|
20
|
-
|
|
15
|
+
export default (fn, options = {}) => {
|
|
21
16
|
return new Macro(fn, options);
|
|
22
17
|
};
|
package/build/reactive/array.js
CHANGED
|
@@ -1,12 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.ReactiveObjectArray = exports.ReactiveArray = void 0;
|
|
4
|
-
const signal_1 = require("../signal");
|
|
5
|
-
const object_1 = require("./object");
|
|
1
|
+
import { dispose, signal } from '../signal';
|
|
2
|
+
import { ReactiveObject } from './object';
|
|
6
3
|
function factory(data, options = {}) {
|
|
7
4
|
let signals = [];
|
|
8
5
|
for (let i = 0, n = data.length; i < n; i++) {
|
|
9
|
-
signals.push(new
|
|
6
|
+
signals.push(new ReactiveObject(data[i], options));
|
|
10
7
|
}
|
|
11
8
|
return signals;
|
|
12
9
|
}
|
|
@@ -17,7 +14,7 @@ class ReactiveArray extends Array {
|
|
|
17
14
|
#signal;
|
|
18
15
|
constructor(data) {
|
|
19
16
|
super(...data);
|
|
20
|
-
this.#signal =
|
|
17
|
+
this.#signal = signal(false);
|
|
21
18
|
}
|
|
22
19
|
set length(n) {
|
|
23
20
|
if (n > this.length) {
|
|
@@ -102,7 +99,6 @@ class ReactiveArray extends Array {
|
|
|
102
99
|
return length;
|
|
103
100
|
}
|
|
104
101
|
}
|
|
105
|
-
exports.ReactiveArray = ReactiveArray;
|
|
106
102
|
class ReactiveObjectArray extends ReactiveArray {
|
|
107
103
|
#options;
|
|
108
104
|
constructor(data, options = {}) {
|
|
@@ -116,22 +112,22 @@ class ReactiveObjectArray extends ReactiveArray {
|
|
|
116
112
|
return unsupported('reverse');
|
|
117
113
|
}
|
|
118
114
|
pop() {
|
|
119
|
-
return
|
|
115
|
+
return dispose(super.pop());
|
|
120
116
|
}
|
|
121
117
|
push(...values) {
|
|
122
118
|
return super.push(...factory(values, this.#options));
|
|
123
119
|
}
|
|
124
120
|
shift() {
|
|
125
|
-
return
|
|
121
|
+
return dispose(super.shift());
|
|
126
122
|
}
|
|
127
123
|
sort() {
|
|
128
124
|
return unsupported('sort');
|
|
129
125
|
}
|
|
130
126
|
splice(start, deleteCount = super.length, ...values) {
|
|
131
|
-
return
|
|
127
|
+
return dispose(super.splice(start, deleteCount, ...factory(values, this.#options)));
|
|
132
128
|
}
|
|
133
129
|
unshift(...values) {
|
|
134
130
|
return super.unshift(...factory(values, this.#options));
|
|
135
131
|
}
|
|
136
132
|
}
|
|
137
|
-
|
|
133
|
+
export { ReactiveArray, ReactiveObjectArray };
|
package/build/reactive/index.js
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
exports.default = (data, options) => {
|
|
5
|
-
return new object_1.ReactiveObject(data, options);
|
|
1
|
+
import { ReactiveObject } from './object';
|
|
2
|
+
export default (data, options) => {
|
|
3
|
+
return new ReactiveObject(data, options);
|
|
6
4
|
};
|
package/build/reactive/object.js
CHANGED
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const signal_1 = require("../signal");
|
|
5
|
-
const utilities_1 = require("../utilities");
|
|
6
|
-
const array_1 = require("./array");
|
|
1
|
+
import { computed, signal } from '../signal';
|
|
2
|
+
import { defineProperty, isArray } from '../utilities';
|
|
3
|
+
import { ReactiveArray, ReactiveObjectArray } from './array';
|
|
7
4
|
class ReactiveObject {
|
|
8
5
|
nodes = {};
|
|
9
6
|
constructor(data, options = {}) {
|
|
@@ -11,23 +8,23 @@ class ReactiveObject {
|
|
|
11
8
|
for (let key in data) {
|
|
12
9
|
let input = data[key];
|
|
13
10
|
if (typeof input === 'function') {
|
|
14
|
-
let node = nodes[key] =
|
|
15
|
-
|
|
11
|
+
let node = nodes[key] = computed(input, options);
|
|
12
|
+
defineProperty(this, key, {
|
|
16
13
|
enumerable: true,
|
|
17
14
|
get() {
|
|
18
15
|
return node.get();
|
|
19
16
|
}
|
|
20
17
|
});
|
|
21
18
|
}
|
|
22
|
-
else if (
|
|
19
|
+
else if (isArray(input)) {
|
|
23
20
|
let node, test = input[0];
|
|
24
21
|
if (typeof test === 'object' && test !== null && test?.constructor?.name === 'Object') {
|
|
25
|
-
node = nodes[key] = new
|
|
22
|
+
node = nodes[key] = new ReactiveObjectArray(input, options);
|
|
26
23
|
}
|
|
27
24
|
else {
|
|
28
|
-
node = nodes[key] = new
|
|
25
|
+
node = nodes[key] = new ReactiveArray(input);
|
|
29
26
|
}
|
|
30
|
-
|
|
27
|
+
defineProperty(this, key, {
|
|
31
28
|
enumerable: true,
|
|
32
29
|
get() {
|
|
33
30
|
node.track();
|
|
@@ -36,8 +33,8 @@ class ReactiveObject {
|
|
|
36
33
|
});
|
|
37
34
|
}
|
|
38
35
|
else {
|
|
39
|
-
let node = nodes[key] =
|
|
40
|
-
|
|
36
|
+
let node = nodes[key] = signal(input, options);
|
|
37
|
+
defineProperty(this, key, {
|
|
41
38
|
enumerable: true,
|
|
42
39
|
get() {
|
|
43
40
|
return node.get();
|
|
@@ -56,4 +53,4 @@ class ReactiveObject {
|
|
|
56
53
|
}
|
|
57
54
|
}
|
|
58
55
|
}
|
|
59
|
-
|
|
56
|
+
export { ReactiveObject };
|
package/build/resource.js
CHANGED
|
@@ -1,11 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const custom_function_1 = __importDefault(require("@esportsplus/custom-function"));
|
|
7
|
-
const signal_1 = require("./signal");
|
|
8
|
-
class Resource extends custom_function_1.default {
|
|
1
|
+
import CustomFunction from '@esportsplus/custom-function';
|
|
2
|
+
import { signal } from './signal';
|
|
3
|
+
class Resource extends CustomFunction {
|
|
9
4
|
#data;
|
|
10
5
|
#input;
|
|
11
6
|
#ok;
|
|
@@ -31,9 +26,9 @@ class Resource extends custom_function_1.default {
|
|
|
31
26
|
this.#ok.set(false);
|
|
32
27
|
});
|
|
33
28
|
});
|
|
34
|
-
this.#data =
|
|
35
|
-
this.#input =
|
|
36
|
-
this.#ok =
|
|
29
|
+
this.#data = signal(undefined, options);
|
|
30
|
+
this.#input = signal(null, options);
|
|
31
|
+
this.#ok = signal(null, options);
|
|
37
32
|
}
|
|
38
33
|
get data() {
|
|
39
34
|
return this.#data.get();
|
|
@@ -50,6 +45,6 @@ class Resource extends custom_function_1.default {
|
|
|
50
45
|
this.#ok.dispose();
|
|
51
46
|
}
|
|
52
47
|
}
|
|
53
|
-
|
|
48
|
+
export default (fn, options = {}) => {
|
|
54
49
|
return new Resource(fn, options);
|
|
55
50
|
};
|
package/build/signal.d.ts
CHANGED
|
@@ -20,12 +20,12 @@ declare class Reactive<T> {
|
|
|
20
20
|
once<T>(event: Event, listener: Listener<T>): void;
|
|
21
21
|
set(value: T): T;
|
|
22
22
|
}
|
|
23
|
-
declare const computed: <T>(fn:
|
|
23
|
+
declare const computed: <T>(fn: Computed<T>['fn'], options?: Options) => Computed<T>;
|
|
24
24
|
declare const dispose: <T extends {
|
|
25
25
|
dispose: VoidFunction;
|
|
26
|
-
}>(dispose?: T | T
|
|
26
|
+
}>(dispose?: T[] | T | null) => T | T[] | null | undefined;
|
|
27
27
|
declare const effect: (fn: Effect['fn']) => Effect;
|
|
28
|
-
declare const root: <T>(fn: (instance: Root) => T
|
|
28
|
+
declare const root: <T>(fn: NeverAsync<(instance: Root) => T>, scheduler?: Scheduler) => T;
|
|
29
29
|
declare const signal: <T>(value: T, options?: Options) => Signal<T>;
|
|
30
30
|
export { computed, dispose, effect, root, signal };
|
|
31
31
|
export { Reactive };
|
package/build/signal.js
CHANGED
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.Reactive = exports.signal = exports.root = exports.effect = exports.dispose = exports.computed = void 0;
|
|
4
|
-
const constants_1 = require("./constants");
|
|
5
|
-
const utilities_1 = require("./utilities");
|
|
1
|
+
import { CHECK, CLEAN, COMPUTED, DIRTY, DISPOSED, EFFECT, ROOT, SIGNAL } from './constants';
|
|
2
|
+
import { isArray } from './utilities';
|
|
6
3
|
let index = 0, observer = null, observers = null, scope = null;
|
|
7
4
|
class Reactive {
|
|
8
5
|
changed = null;
|
|
@@ -19,7 +16,7 @@ class Reactive {
|
|
|
19
16
|
value;
|
|
20
17
|
constructor(state, type, value) {
|
|
21
18
|
let root = null;
|
|
22
|
-
if (type !==
|
|
19
|
+
if (type !== ROOT) {
|
|
23
20
|
if (scope !== null) {
|
|
24
21
|
root = scope;
|
|
25
22
|
}
|
|
@@ -27,7 +24,7 @@ class Reactive {
|
|
|
27
24
|
root = observer.root;
|
|
28
25
|
}
|
|
29
26
|
if (root == null) {
|
|
30
|
-
if (type ===
|
|
27
|
+
if (type === EFFECT) {
|
|
31
28
|
throw new Error(`Reactivity: 'effect' cannot be created without a reactive root`);
|
|
32
29
|
}
|
|
33
30
|
}
|
|
@@ -65,7 +62,7 @@ class Reactive {
|
|
|
65
62
|
}
|
|
66
63
|
}
|
|
67
64
|
dispose() {
|
|
68
|
-
if (this.state ===
|
|
65
|
+
if (this.state === DISPOSED) {
|
|
69
66
|
return;
|
|
70
67
|
}
|
|
71
68
|
this.dispatch('cleanup', this);
|
|
@@ -74,10 +71,10 @@ class Reactive {
|
|
|
74
71
|
this.listeners = null;
|
|
75
72
|
this.observers = null;
|
|
76
73
|
this.sources = null;
|
|
77
|
-
this.state =
|
|
74
|
+
this.state = DISPOSED;
|
|
78
75
|
}
|
|
79
76
|
get() {
|
|
80
|
-
if (this.state ===
|
|
77
|
+
if (this.state === DISPOSED) {
|
|
81
78
|
return this.value;
|
|
82
79
|
}
|
|
83
80
|
if (observer !== null) {
|
|
@@ -93,13 +90,13 @@ class Reactive {
|
|
|
93
90
|
observers.push(this);
|
|
94
91
|
}
|
|
95
92
|
}
|
|
96
|
-
if (this.type ===
|
|
93
|
+
if (this.type === COMPUTED || this.type === EFFECT) {
|
|
97
94
|
sync(this);
|
|
98
95
|
}
|
|
99
96
|
return this.value;
|
|
100
97
|
}
|
|
101
98
|
on(event, listener) {
|
|
102
|
-
if (this.state ===
|
|
99
|
+
if (this.state === DIRTY) {
|
|
103
100
|
if (event !== 'cleanup') {
|
|
104
101
|
throw new Error(`Reactivity: events set within computed or effects must use the 'cleanup' event name`);
|
|
105
102
|
}
|
|
@@ -129,17 +126,16 @@ class Reactive {
|
|
|
129
126
|
this.on(event, listener);
|
|
130
127
|
}
|
|
131
128
|
set(value) {
|
|
132
|
-
if (this.type !==
|
|
129
|
+
if (this.type !== SIGNAL && observer !== this) {
|
|
133
130
|
throw new Error(`Reactivity: 'set' method is only available on signals`);
|
|
134
131
|
}
|
|
135
132
|
if (this.changed(this.value, value)) {
|
|
136
133
|
this.value = value;
|
|
137
|
-
notify(this.observers,
|
|
134
|
+
notify(this.observers, DIRTY);
|
|
138
135
|
}
|
|
139
136
|
return this.value;
|
|
140
137
|
}
|
|
141
138
|
}
|
|
142
|
-
exports.Reactive = Reactive;
|
|
143
139
|
function changed(a, b) {
|
|
144
140
|
return a !== b;
|
|
145
141
|
}
|
|
@@ -150,11 +146,11 @@ function notify(nodes, state) {
|
|
|
150
146
|
for (let i = 0, n = nodes.length; i < n; i++) {
|
|
151
147
|
let node = nodes[i];
|
|
152
148
|
if (node.state < state) {
|
|
153
|
-
if (node.type ===
|
|
149
|
+
if (node.type === EFFECT && node.state === CLEAN) {
|
|
154
150
|
node.root.scheduler(node.task);
|
|
155
151
|
}
|
|
156
152
|
node.state = state;
|
|
157
|
-
notify(node.observers,
|
|
153
|
+
notify(node.observers, CHECK);
|
|
158
154
|
}
|
|
159
155
|
}
|
|
160
156
|
}
|
|
@@ -172,19 +168,19 @@ function removeSourceObservers(node, start) {
|
|
|
172
168
|
}
|
|
173
169
|
}
|
|
174
170
|
function sync(node) {
|
|
175
|
-
if (node.state ===
|
|
171
|
+
if (node.state === CHECK && node.sources !== null) {
|
|
176
172
|
for (let i = 0, n = node.sources.length; i < n; i++) {
|
|
177
173
|
sync(node.sources[i]);
|
|
178
|
-
if (node.state ===
|
|
174
|
+
if (node.state === DIRTY) {
|
|
179
175
|
break;
|
|
180
176
|
}
|
|
181
177
|
}
|
|
182
178
|
}
|
|
183
|
-
if (node.state ===
|
|
179
|
+
if (node.state === DIRTY) {
|
|
184
180
|
update(node);
|
|
185
181
|
}
|
|
186
182
|
else {
|
|
187
|
-
node.state =
|
|
183
|
+
node.state = CLEAN;
|
|
188
184
|
}
|
|
189
185
|
}
|
|
190
186
|
function update(node) {
|
|
@@ -221,7 +217,7 @@ function update(node) {
|
|
|
221
217
|
removeSourceObservers(node, index);
|
|
222
218
|
node.sources.length = index;
|
|
223
219
|
}
|
|
224
|
-
if (node.type ===
|
|
220
|
+
if (node.type === COMPUTED) {
|
|
225
221
|
node.set(value);
|
|
226
222
|
}
|
|
227
223
|
}
|
|
@@ -230,19 +226,18 @@ function update(node) {
|
|
|
230
226
|
observer = o;
|
|
231
227
|
observers = os;
|
|
232
228
|
}
|
|
233
|
-
node.state =
|
|
229
|
+
node.state = CLEAN;
|
|
234
230
|
}
|
|
235
231
|
const computed = (fn, options) => {
|
|
236
|
-
let instance = new Reactive(
|
|
232
|
+
let instance = new Reactive(DIRTY, COMPUTED, undefined);
|
|
237
233
|
instance.changed = options?.changed || changed;
|
|
238
234
|
instance.fn = fn;
|
|
239
235
|
return instance;
|
|
240
236
|
};
|
|
241
|
-
exports.computed = computed;
|
|
242
237
|
const dispose = (dispose) => {
|
|
243
238
|
if (dispose == null) {
|
|
244
239
|
}
|
|
245
|
-
else if (
|
|
240
|
+
else if (isArray(dispose)) {
|
|
246
241
|
for (let i = 0, n = dispose.length; i < n; i++) {
|
|
247
242
|
dispose[i].dispose();
|
|
248
243
|
}
|
|
@@ -252,19 +247,17 @@ const dispose = (dispose) => {
|
|
|
252
247
|
}
|
|
253
248
|
return dispose;
|
|
254
249
|
};
|
|
255
|
-
exports.dispose = dispose;
|
|
256
250
|
const effect = (fn) => {
|
|
257
|
-
let instance = new Reactive(
|
|
251
|
+
let instance = new Reactive(DIRTY, EFFECT, null);
|
|
258
252
|
instance.fn = fn;
|
|
259
253
|
instance.task = () => instance.get();
|
|
260
254
|
update(instance);
|
|
261
255
|
return instance;
|
|
262
256
|
};
|
|
263
|
-
exports.effect = effect;
|
|
264
257
|
const root = (fn, scheduler) => {
|
|
265
258
|
let o = observer, s = scope;
|
|
266
259
|
if (scheduler === undefined) {
|
|
267
|
-
if (o?.type ===
|
|
260
|
+
if (o?.type === EFFECT) {
|
|
268
261
|
scope = o.root;
|
|
269
262
|
}
|
|
270
263
|
if (scope === null) {
|
|
@@ -273,7 +266,7 @@ const root = (fn, scheduler) => {
|
|
|
273
266
|
scheduler = scope.scheduler;
|
|
274
267
|
}
|
|
275
268
|
observer = null;
|
|
276
|
-
scope = new Reactive(
|
|
269
|
+
scope = new Reactive(CLEAN, ROOT, null);
|
|
277
270
|
scope.scheduler = scheduler;
|
|
278
271
|
scope.tracking = fn.length > 0;
|
|
279
272
|
let result = fn.call(null, scope);
|
|
@@ -281,10 +274,10 @@ const root = (fn, scheduler) => {
|
|
|
281
274
|
scope = s;
|
|
282
275
|
return result;
|
|
283
276
|
};
|
|
284
|
-
exports.root = root;
|
|
285
277
|
const signal = (value, options) => {
|
|
286
|
-
let instance = new Reactive(
|
|
278
|
+
let instance = new Reactive(CLEAN, SIGNAL, value);
|
|
287
279
|
instance.changed = options?.changed || changed;
|
|
288
280
|
return instance;
|
|
289
281
|
};
|
|
290
|
-
|
|
282
|
+
export { computed, dispose, effect, root, signal };
|
|
283
|
+
export { Reactive };
|
package/build/types.js
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
export {};
|
package/build/utilities.js
CHANGED
|
@@ -1,7 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isArray = exports.defineProperty = void 0;
|
|
4
1
|
const { isArray } = Array;
|
|
5
|
-
exports.isArray = isArray;
|
|
6
2
|
const { defineProperty } = Object;
|
|
7
|
-
|
|
3
|
+
export { defineProperty, isArray };
|
package/package.json
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
{
|
|
2
|
-
"author": "ICJR",
|
|
3
|
-
"dependencies": {
|
|
4
|
-
"@esportsplus/custom-function": "^0.0.
|
|
5
|
-
},
|
|
6
|
-
"devDependencies": {
|
|
7
|
-
"@esportsplus/typescript": "^0.
|
|
8
|
-
},
|
|
9
|
-
"main": "build/index.js",
|
|
10
|
-
"name": "@esportsplus/reactivity",
|
|
11
|
-
"private": false,
|
|
12
|
-
"scripts": {
|
|
13
|
-
"build": "tsc && tsc-alias",
|
|
14
|
-
"-": "-",
|
|
15
|
-
"prepare": "npm run build",
|
|
16
|
-
"prepublishOnly": "npm run build"
|
|
17
|
-
},
|
|
18
|
-
"types": "build/index.d.ts",
|
|
19
|
-
"version": "0.1.
|
|
20
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"author": "ICJR",
|
|
3
|
+
"dependencies": {
|
|
4
|
+
"@esportsplus/custom-function": "^0.0.3"
|
|
5
|
+
},
|
|
6
|
+
"devDependencies": {
|
|
7
|
+
"@esportsplus/typescript": "^0.1.2"
|
|
8
|
+
},
|
|
9
|
+
"main": "build/index.js",
|
|
10
|
+
"name": "@esportsplus/reactivity",
|
|
11
|
+
"private": false,
|
|
12
|
+
"scripts": {
|
|
13
|
+
"build": "tsc && tsc-alias",
|
|
14
|
+
"-": "-",
|
|
15
|
+
"prepare": "npm run build",
|
|
16
|
+
"prepublishOnly": "npm run build"
|
|
17
|
+
},
|
|
18
|
+
"types": "build/index.d.ts",
|
|
19
|
+
"version": "0.1.21"
|
|
20
|
+
}
|
package/readme.md
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
https://github.com/maverick-js/signals
|
|
1
|
+
https://github.com/maverick-js/signals
|
|
2
2
|
https://github.com/modderme123/reactively
|
package/src/constants.ts
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
const CLEAN = 0;
|
|
2
|
-
|
|
3
|
-
const CHECK = 1;
|
|
4
|
-
|
|
5
|
-
const DIRTY = 2;
|
|
6
|
-
|
|
7
|
-
const DISPOSED = 3;
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
const COMPUTED = 0;
|
|
11
|
-
|
|
12
|
-
const EFFECT = 1;
|
|
13
|
-
|
|
14
|
-
const ROOT = 2;
|
|
15
|
-
|
|
16
|
-
const SIGNAL = 3;
|
|
17
|
-
|
|
18
|
-
|
|
1
|
+
const CLEAN = 0;
|
|
2
|
+
|
|
3
|
+
const CHECK = 1;
|
|
4
|
+
|
|
5
|
+
const DIRTY = 2;
|
|
6
|
+
|
|
7
|
+
const DISPOSED = 3;
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
const COMPUTED = 0;
|
|
11
|
+
|
|
12
|
+
const EFFECT = 1;
|
|
13
|
+
|
|
14
|
+
const ROOT = 2;
|
|
15
|
+
|
|
16
|
+
const SIGNAL = 3;
|
|
17
|
+
|
|
18
|
+
|
|
19
19
|
export { CHECK, CLEAN, COMPUTED, DIRTY, DISPOSED, EFFECT, ROOT, SIGNAL };
|