@esportsplus/reactivity 0.0.18 → 0.0.19
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.js → index.browser.js} +90 -3
- package/build/index.js +277 -4
- package/build/methods/reactive.d.ts +1 -1
- package/package.json +6 -6
- package/tsconfig.json +5 -19
- package/webpack.config.ts +6 -0
- package/build/methods/effect.js +0 -4
- package/build/methods/index.js +0 -3
- package/build/methods/reactive.js +0 -52
- package/build/symbols.js +0 -4
- package/build/types.js +0 -1
|
@@ -1,4 +1,17 @@
|
|
|
1
|
-
|
|
1
|
+
/******/ (() => { // webpackBootstrap
|
|
2
|
+
/******/ "use strict";
|
|
3
|
+
var __webpack_exports__ = {};
|
|
4
|
+
|
|
5
|
+
// UNUSED EXPORTS: default, effect, reactive, scheduler
|
|
6
|
+
|
|
7
|
+
;// CONCATENATED MODULE: ./src/symbols.ts
|
|
8
|
+
const CLEAN = 0;
|
|
9
|
+
const CHECK = 1;
|
|
10
|
+
const DIRTY = 2;
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
;// CONCATENATED MODULE: ./src/reactive.ts
|
|
14
|
+
|
|
2
15
|
let index = 0, reaction = null, queue = [], scheduled = false, schedulers = new Set, stack = null;
|
|
3
16
|
function mark(instances, state) {
|
|
4
17
|
if (!instances) {
|
|
@@ -186,5 +199,79 @@ const scheduler = {
|
|
|
186
199
|
schedulers.delete(scheduler);
|
|
187
200
|
}
|
|
188
201
|
};
|
|
189
|
-
|
|
190
|
-
|
|
202
|
+
/* harmony default export */ const reactive = (Reactive);
|
|
203
|
+
|
|
204
|
+
|
|
205
|
+
;// CONCATENATED MODULE: ./src/methods/effect.ts
|
|
206
|
+
|
|
207
|
+
/* harmony default export */ const effect = ((fn) => {
|
|
208
|
+
new reactive(fn, true);
|
|
209
|
+
});
|
|
210
|
+
|
|
211
|
+
;// CONCATENATED MODULE: ./src/methods/reactive.ts
|
|
212
|
+
|
|
213
|
+
function factory(value) {
|
|
214
|
+
if (typeof value === 'object' && value !== null && (value.constructor === Object)) {
|
|
215
|
+
return obj(value);
|
|
216
|
+
}
|
|
217
|
+
return new reactive(value);
|
|
218
|
+
}
|
|
219
|
+
function fn(value) {
|
|
220
|
+
let fn = new reactive(value);
|
|
221
|
+
return (...args) => {
|
|
222
|
+
let value = fn.get();
|
|
223
|
+
if (args.length && typeof value === 'function') {
|
|
224
|
+
value = value(...args);
|
|
225
|
+
}
|
|
226
|
+
return value;
|
|
227
|
+
};
|
|
228
|
+
}
|
|
229
|
+
function obj(values) {
|
|
230
|
+
let lazy = {}, properties = {};
|
|
231
|
+
for (let key in values) {
|
|
232
|
+
properties[key] = {
|
|
233
|
+
get() {
|
|
234
|
+
if (!lazy[key]) {
|
|
235
|
+
lazy[key] = factory(values[key]);
|
|
236
|
+
}
|
|
237
|
+
if (lazy[key] instanceof reactive) {
|
|
238
|
+
return lazy[key].get();
|
|
239
|
+
}
|
|
240
|
+
return lazy[key];
|
|
241
|
+
},
|
|
242
|
+
set(value) {
|
|
243
|
+
if (!lazy[key]) {
|
|
244
|
+
lazy[key] = factory(values[key]);
|
|
245
|
+
}
|
|
246
|
+
if (lazy[key] instanceof reactive) {
|
|
247
|
+
lazy[key].set(value);
|
|
248
|
+
}
|
|
249
|
+
else {
|
|
250
|
+
lazy[key] = factory(value);
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
};
|
|
254
|
+
}
|
|
255
|
+
return Object.defineProperties({}, properties);
|
|
256
|
+
}
|
|
257
|
+
;
|
|
258
|
+
/* harmony default export */ const methods_reactive = ((value) => {
|
|
259
|
+
if (typeof value === 'function') {
|
|
260
|
+
return fn(value);
|
|
261
|
+
}
|
|
262
|
+
return factory(value);
|
|
263
|
+
});
|
|
264
|
+
|
|
265
|
+
;// CONCATENATED MODULE: ./src/methods/index.ts
|
|
266
|
+
|
|
267
|
+
|
|
268
|
+
|
|
269
|
+
|
|
270
|
+
;// CONCATENATED MODULE: ./src/index.ts
|
|
271
|
+
|
|
272
|
+
|
|
273
|
+
/* harmony default export */ const src = ({ effect: effect, reactive: methods_reactive, scheduler: scheduler });
|
|
274
|
+
|
|
275
|
+
|
|
276
|
+
/******/ })()
|
|
277
|
+
;
|
package/build/index.js
CHANGED
|
@@ -1,4 +1,277 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
/******/ (() => { // webpackBootstrap
|
|
2
|
+
/******/ "use strict";
|
|
3
|
+
var __webpack_exports__ = {};
|
|
4
|
+
|
|
5
|
+
// UNUSED EXPORTS: default, effect, reactive, scheduler
|
|
6
|
+
|
|
7
|
+
;// CONCATENATED MODULE: ./src/symbols.ts
|
|
8
|
+
const CLEAN = 0;
|
|
9
|
+
const CHECK = 1;
|
|
10
|
+
const DIRTY = 2;
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
;// CONCATENATED MODULE: ./src/reactive.ts
|
|
14
|
+
|
|
15
|
+
let index = 0, reaction = null, queue = [], scheduled = false, schedulers = new Set, stack = null;
|
|
16
|
+
function mark(instances, state) {
|
|
17
|
+
if (!instances) {
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
for (let i = 0, n = instances.length; i < n; i++) {
|
|
21
|
+
let instance = instances[i];
|
|
22
|
+
if (instance.state < state) {
|
|
23
|
+
if (instance.effect && instance.state === CLEAN) {
|
|
24
|
+
queue.push(instance);
|
|
25
|
+
if (!scheduled) {
|
|
26
|
+
schedule();
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
instance.state = state;
|
|
30
|
+
if (instance.observers) {
|
|
31
|
+
mark(instance.observers, CHECK);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
function schedule() {
|
|
37
|
+
if (scheduled) {
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
for (let scheduler of schedulers) {
|
|
41
|
+
scheduler.schedule();
|
|
42
|
+
}
|
|
43
|
+
scheduled = true;
|
|
44
|
+
}
|
|
45
|
+
async function task() {
|
|
46
|
+
let n = queue.length;
|
|
47
|
+
for (let i = 0; i < n; i++) {
|
|
48
|
+
await queue[i].get();
|
|
49
|
+
}
|
|
50
|
+
queue.splice(0, n);
|
|
51
|
+
scheduled = false;
|
|
52
|
+
if (queue.length) {
|
|
53
|
+
schedule();
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
class Reactive {
|
|
57
|
+
fn;
|
|
58
|
+
value;
|
|
59
|
+
effect;
|
|
60
|
+
cleanup = null;
|
|
61
|
+
observers = null;
|
|
62
|
+
sources = null;
|
|
63
|
+
state;
|
|
64
|
+
constructor(data, effect = false) {
|
|
65
|
+
this.effect = effect;
|
|
66
|
+
if (typeof data === 'function') {
|
|
67
|
+
this.fn = data;
|
|
68
|
+
this.state = DIRTY;
|
|
69
|
+
this.value = undefined;
|
|
70
|
+
if (effect) {
|
|
71
|
+
this.update();
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
else {
|
|
75
|
+
this.state = CLEAN;
|
|
76
|
+
this.value = data;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
get() {
|
|
80
|
+
if (reaction) {
|
|
81
|
+
if (!stack && reaction.sources && reaction.sources[index] == this) {
|
|
82
|
+
index++;
|
|
83
|
+
}
|
|
84
|
+
else {
|
|
85
|
+
if (!stack) {
|
|
86
|
+
stack = [this];
|
|
87
|
+
}
|
|
88
|
+
else {
|
|
89
|
+
stack.push(this);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
if (this.fn) {
|
|
94
|
+
this.sync();
|
|
95
|
+
}
|
|
96
|
+
return this.value;
|
|
97
|
+
}
|
|
98
|
+
set(value) {
|
|
99
|
+
if (this.value !== value) {
|
|
100
|
+
mark(this.observers, DIRTY);
|
|
101
|
+
}
|
|
102
|
+
this.value = value;
|
|
103
|
+
}
|
|
104
|
+
removeParentObservers() {
|
|
105
|
+
if (!this.sources) {
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
for (let i = index; i < this.sources.length; i++) {
|
|
109
|
+
let source = this.sources[i];
|
|
110
|
+
source.observers[source.observers.findIndex((v) => v === this)] = source.observers[source.observers.length - 1];
|
|
111
|
+
source.observers.pop();
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
sync() {
|
|
115
|
+
if (this.state === CHECK && this.sources) {
|
|
116
|
+
for (let i = 0, n = this.sources.length; i < n; i++) {
|
|
117
|
+
this.sources[i].sync();
|
|
118
|
+
if (this.state === DIRTY) {
|
|
119
|
+
break;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
if (this.state === DIRTY) {
|
|
124
|
+
this.update();
|
|
125
|
+
}
|
|
126
|
+
this.state = CLEAN;
|
|
127
|
+
}
|
|
128
|
+
update() {
|
|
129
|
+
let previous = {
|
|
130
|
+
index: index,
|
|
131
|
+
reaction: reaction,
|
|
132
|
+
stack: stack,
|
|
133
|
+
value: this.value
|
|
134
|
+
};
|
|
135
|
+
index = 0;
|
|
136
|
+
reaction = this;
|
|
137
|
+
stack = [];
|
|
138
|
+
try {
|
|
139
|
+
if (this.cleanup) {
|
|
140
|
+
for (let i = 0, n = this.cleanup.length; i < n; i++) {
|
|
141
|
+
this.cleanup[i](this.value);
|
|
142
|
+
}
|
|
143
|
+
this.cleanup.length = 0;
|
|
144
|
+
}
|
|
145
|
+
this.value = this.fn((fn) => {
|
|
146
|
+
if (!this.cleanup) {
|
|
147
|
+
this.cleanup = [fn];
|
|
148
|
+
}
|
|
149
|
+
else {
|
|
150
|
+
this.cleanup.push(fn);
|
|
151
|
+
}
|
|
152
|
+
});
|
|
153
|
+
if (stack.length) {
|
|
154
|
+
this.removeParentObservers();
|
|
155
|
+
if (this.sources && index > 0) {
|
|
156
|
+
this.sources.length = index + stack.length;
|
|
157
|
+
for (let i = 0; i < stack.length; i++) {
|
|
158
|
+
this.sources[index + i] = stack[i];
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
else {
|
|
162
|
+
this.sources = stack;
|
|
163
|
+
}
|
|
164
|
+
for (let i = index; i < this.sources.length; i++) {
|
|
165
|
+
let source = this.sources[i];
|
|
166
|
+
if (!source.observers) {
|
|
167
|
+
source.observers = [this];
|
|
168
|
+
}
|
|
169
|
+
else {
|
|
170
|
+
source.observers.push(this);
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
else if (this.sources && index < this.sources.length) {
|
|
175
|
+
this.removeParentObservers();
|
|
176
|
+
this.sources.length = index;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
finally {
|
|
180
|
+
index = previous.index;
|
|
181
|
+
reaction = previous.reaction;
|
|
182
|
+
stack = previous.stack;
|
|
183
|
+
}
|
|
184
|
+
if (this.observers && previous.value !== this.value) {
|
|
185
|
+
for (let i = 0; i < this.observers.length; i++) {
|
|
186
|
+
this.observers[i].state = DIRTY;
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
this.state = CLEAN;
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
const scheduler = {
|
|
193
|
+
add: (scheduler) => {
|
|
194
|
+
scheduler.tasks.add(task);
|
|
195
|
+
schedulers.add(scheduler);
|
|
196
|
+
},
|
|
197
|
+
delete: (scheduler) => {
|
|
198
|
+
scheduler.tasks.delete(task);
|
|
199
|
+
schedulers.delete(scheduler);
|
|
200
|
+
}
|
|
201
|
+
};
|
|
202
|
+
/* harmony default export */ const reactive = (Reactive);
|
|
203
|
+
|
|
204
|
+
|
|
205
|
+
;// CONCATENATED MODULE: ./src/methods/effect.ts
|
|
206
|
+
|
|
207
|
+
/* harmony default export */ const effect = ((fn) => {
|
|
208
|
+
new reactive(fn, true);
|
|
209
|
+
});
|
|
210
|
+
|
|
211
|
+
;// CONCATENATED MODULE: ./src/methods/reactive.ts
|
|
212
|
+
|
|
213
|
+
function factory(value) {
|
|
214
|
+
if (typeof value === 'object' && value !== null && (value.constructor === Object)) {
|
|
215
|
+
return obj(value);
|
|
216
|
+
}
|
|
217
|
+
return new reactive(value);
|
|
218
|
+
}
|
|
219
|
+
function fn(value) {
|
|
220
|
+
let fn = new reactive(value);
|
|
221
|
+
return (...args) => {
|
|
222
|
+
let value = fn.get();
|
|
223
|
+
if (args.length && typeof value === 'function') {
|
|
224
|
+
value = value(...args);
|
|
225
|
+
}
|
|
226
|
+
return value;
|
|
227
|
+
};
|
|
228
|
+
}
|
|
229
|
+
function obj(values) {
|
|
230
|
+
let lazy = {}, properties = {};
|
|
231
|
+
for (let key in values) {
|
|
232
|
+
properties[key] = {
|
|
233
|
+
get() {
|
|
234
|
+
if (!lazy[key]) {
|
|
235
|
+
lazy[key] = factory(values[key]);
|
|
236
|
+
}
|
|
237
|
+
if (lazy[key] instanceof reactive) {
|
|
238
|
+
return lazy[key].get();
|
|
239
|
+
}
|
|
240
|
+
return lazy[key];
|
|
241
|
+
},
|
|
242
|
+
set(value) {
|
|
243
|
+
if (!lazy[key]) {
|
|
244
|
+
lazy[key] = factory(values[key]);
|
|
245
|
+
}
|
|
246
|
+
if (lazy[key] instanceof reactive) {
|
|
247
|
+
lazy[key].set(value);
|
|
248
|
+
}
|
|
249
|
+
else {
|
|
250
|
+
lazy[key] = factory(value);
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
};
|
|
254
|
+
}
|
|
255
|
+
return Object.defineProperties({}, properties);
|
|
256
|
+
}
|
|
257
|
+
;
|
|
258
|
+
/* harmony default export */ const methods_reactive = ((value) => {
|
|
259
|
+
if (typeof value === 'function') {
|
|
260
|
+
return fn(value);
|
|
261
|
+
}
|
|
262
|
+
return factory(value);
|
|
263
|
+
});
|
|
264
|
+
|
|
265
|
+
;// CONCATENATED MODULE: ./src/methods/index.ts
|
|
266
|
+
|
|
267
|
+
|
|
268
|
+
|
|
269
|
+
|
|
270
|
+
;// CONCATENATED MODULE: ./src/index.ts
|
|
271
|
+
|
|
272
|
+
|
|
273
|
+
/* harmony default export */ const src = ({ effect: effect, reactive: methods_reactive, scheduler: scheduler });
|
|
274
|
+
|
|
275
|
+
|
|
276
|
+
/******/ })()
|
|
277
|
+
;
|
package/package.json
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
{
|
|
2
2
|
"author": "ICJR",
|
|
3
|
+
"browser": "build/index.browser.js",
|
|
3
4
|
"description": "Reactivity",
|
|
4
5
|
"devDependencies": {
|
|
5
|
-
"
|
|
6
|
-
"typescript": "^4.9.4"
|
|
6
|
+
"@esportsplus/webpack": "^0.0.78"
|
|
7
7
|
},
|
|
8
|
-
"main": "
|
|
8
|
+
"main": "build/index.js",
|
|
9
9
|
"name": "@esportsplus/reactivity",
|
|
10
10
|
"private": false,
|
|
11
11
|
"scripts": {
|
|
12
|
-
"build": "
|
|
12
|
+
"build": "webpack",
|
|
13
13
|
"-": "-",
|
|
14
14
|
"prepare": "npm run build",
|
|
15
15
|
"prepublishOnly": "npm run build"
|
|
16
16
|
},
|
|
17
|
-
"types": "
|
|
18
|
-
"version": "0.0.
|
|
17
|
+
"types": "build/index.d.ts",
|
|
18
|
+
"version": "0.0.19"
|
|
19
19
|
}
|
package/tsconfig.json
CHANGED
|
@@ -1,24 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"compilerOptions": {
|
|
3
|
-
"
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
"declaration": true,
|
|
7
|
-
"declarationDir": "./build",
|
|
8
|
-
"lib": ["dom", "esnext"],
|
|
9
|
-
"module": "esnext",
|
|
10
|
-
"moduleResolution": "nodenext",
|
|
11
|
-
"noUnusedLocals": true,
|
|
12
|
-
"noUnusedParameters": true,
|
|
13
|
-
"outDir": "./build",
|
|
14
|
-
"paths": {
|
|
15
|
-
"~/*": ["*"]
|
|
16
|
-
},
|
|
17
|
-
"removeComments": true,
|
|
18
|
-
"resolveJsonModule": true,
|
|
19
|
-
"strict": true,
|
|
20
|
-
"target": "esnext"
|
|
3
|
+
"baseUrl": ".",
|
|
4
|
+
"declarationDir": "build",
|
|
5
|
+
"outDir": "build",
|
|
21
6
|
},
|
|
22
7
|
"exclude": ["node_modules"],
|
|
8
|
+
"extends": "@esportsplus/webpack/tsconfig.base.json",
|
|
23
9
|
"include": ["src"]
|
|
24
|
-
}
|
|
10
|
+
}
|
package/build/methods/effect.js
DELETED
package/build/methods/index.js
DELETED
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import Reactive from '../reactive';
|
|
2
|
-
function factory(value) {
|
|
3
|
-
if (typeof value === 'object' && value !== null && (value.constructor === Object)) {
|
|
4
|
-
return obj(value);
|
|
5
|
-
}
|
|
6
|
-
return new Reactive(value);
|
|
7
|
-
}
|
|
8
|
-
function fn(value) {
|
|
9
|
-
let fn = new Reactive(value);
|
|
10
|
-
return (...args) => {
|
|
11
|
-
let value = fn.get();
|
|
12
|
-
if (args.length && typeof value === 'function') {
|
|
13
|
-
value = value(...args);
|
|
14
|
-
}
|
|
15
|
-
return value;
|
|
16
|
-
};
|
|
17
|
-
}
|
|
18
|
-
function obj(values) {
|
|
19
|
-
let lazy = {}, properties = {};
|
|
20
|
-
for (let key in values) {
|
|
21
|
-
properties[key] = {
|
|
22
|
-
get() {
|
|
23
|
-
if (!lazy[key]) {
|
|
24
|
-
lazy[key] = factory(values[key]);
|
|
25
|
-
}
|
|
26
|
-
if (lazy[key] instanceof Reactive) {
|
|
27
|
-
return lazy[key].get();
|
|
28
|
-
}
|
|
29
|
-
return lazy[key];
|
|
30
|
-
},
|
|
31
|
-
set(value) {
|
|
32
|
-
if (!lazy[key]) {
|
|
33
|
-
lazy[key] = factory(values[key]);
|
|
34
|
-
}
|
|
35
|
-
if (lazy[key] instanceof Reactive) {
|
|
36
|
-
lazy[key].set(value);
|
|
37
|
-
}
|
|
38
|
-
else {
|
|
39
|
-
lazy[key] = factory(value);
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
};
|
|
43
|
-
}
|
|
44
|
-
return Object.defineProperties({}, properties);
|
|
45
|
-
}
|
|
46
|
-
;
|
|
47
|
-
export default (value) => {
|
|
48
|
-
if (typeof value === 'function') {
|
|
49
|
-
return fn(value);
|
|
50
|
-
}
|
|
51
|
-
return factory(value);
|
|
52
|
-
};
|
package/build/symbols.js
DELETED
package/build/types.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|