@oscarpalmer/mora 0.10.0 → 0.11.1
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/dist/computed.cjs +15 -40
- package/dist/computed.js +13 -38
- package/dist/index.cjs +1 -0
- package/dist/index.js +2 -1
- package/dist/is.cjs +4 -0
- package/dist/is.js +4 -0
- package/dist/mora.full.js +53 -69
- package/dist/reactive.cjs +39 -0
- package/dist/reactive.js +39 -0
- package/dist/signal.cjs +6 -36
- package/dist/signal.js +4 -34
- package/package.json +1 -1
- package/src/batch.ts +1 -1
- package/src/computed.ts +20 -60
- package/src/index.ts +1 -1
- package/src/is.ts +5 -0
- package/src/reactive.ts +53 -0
- package/src/signal.ts +7 -54
- package/src/subscription.ts +12 -10
- package/types/batch.d.cts +15 -17
- package/types/batch.d.ts +1 -1
- package/types/computed.d.cts +22 -19
- package/types/computed.d.ts +8 -24
- package/types/index.d.cts +25 -21
- package/types/index.d.ts +1 -1
- package/types/is.d.cts +23 -19
- package/types/is.d.ts +2 -0
- package/types/reactive.d.cts +49 -0
- package/types/reactive.d.ts +25 -0
- package/types/signal.d.cts +18 -34
- package/types/signal.d.ts +2 -25
- package/types/subscription.d.cts +16 -18
- package/types/subscription.d.ts +9 -7
package/dist/computed.cjs
CHANGED
|
@@ -5,24 +5,17 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
5
5
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
6
6
|
const batch = require("./batch.cjs");
|
|
7
7
|
const effect = require("./effect.cjs");
|
|
8
|
-
const
|
|
8
|
+
const reactive = require("./reactive.cjs");
|
|
9
9
|
exports.activeComputed = void 0;
|
|
10
|
-
class Computed {
|
|
10
|
+
class Computed extends reactive.Reactive {
|
|
11
11
|
constructor(callback) {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
value: "computed"
|
|
15
|
-
});
|
|
16
|
-
this.state = {
|
|
17
|
-
computeds: /* @__PURE__ */ new Set(),
|
|
12
|
+
super("computed", void 0);
|
|
13
|
+
__publicField(this, "effect", {
|
|
18
14
|
dirty: true,
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
};
|
|
24
|
-
this.state.effect = effect.effect(() => {
|
|
25
|
-
if (this.state.dirty) {
|
|
15
|
+
instance: void 0
|
|
16
|
+
});
|
|
17
|
+
this.effect.instance = effect.effect(() => {
|
|
18
|
+
if (this.effect.dirty) {
|
|
26
19
|
const previousComputed = exports.activeComputed;
|
|
27
20
|
exports.activeComputed = this;
|
|
28
21
|
const value = callback();
|
|
@@ -30,16 +23,16 @@ class Computed {
|
|
|
30
23
|
if (!Object.is(this.state.value, value)) {
|
|
31
24
|
this.state.value = value;
|
|
32
25
|
for (const computed2 of this.state.computeds) {
|
|
33
|
-
computed2.
|
|
26
|
+
computed2.effect.dirty = true;
|
|
34
27
|
}
|
|
35
28
|
for (const effect2 of this.state.effects) {
|
|
36
29
|
batch.batchedHandlers.add(effect2);
|
|
37
30
|
}
|
|
38
|
-
for (const [,
|
|
39
|
-
|
|
31
|
+
for (const [, subscription] of this.state.subscriptions) {
|
|
32
|
+
subscription.callback(value);
|
|
40
33
|
}
|
|
41
34
|
}
|
|
42
|
-
this.
|
|
35
|
+
this.effect.dirty = false;
|
|
43
36
|
}
|
|
44
37
|
});
|
|
45
38
|
}
|
|
@@ -50,32 +43,14 @@ class Computed {
|
|
|
50
43
|
if (exports.activeComputed != null && exports.activeComputed !== this) {
|
|
51
44
|
this.state.computeds.add(exports.activeComputed);
|
|
52
45
|
}
|
|
53
|
-
if (effect.activeEffect != null && effect.activeEffect !== this.
|
|
46
|
+
if (effect.activeEffect != null && effect.activeEffect !== this.effect.instance) {
|
|
54
47
|
this.state.effects.add(effect.activeEffect);
|
|
55
48
|
}
|
|
56
|
-
if (this.
|
|
57
|
-
effect.runEffect(this.
|
|
49
|
+
if (this.effect.dirty && batch.batchDepth === 0) {
|
|
50
|
+
effect.runEffect(this.effect.instance);
|
|
58
51
|
}
|
|
59
52
|
return this.state.value;
|
|
60
53
|
}
|
|
61
|
-
/**
|
|
62
|
-
* Get the value _(without reactivity)_
|
|
63
|
-
*/
|
|
64
|
-
peek() {
|
|
65
|
-
return this.state.value;
|
|
66
|
-
}
|
|
67
|
-
/**
|
|
68
|
-
* Subscribe to changes
|
|
69
|
-
*/
|
|
70
|
-
subscribe(callback) {
|
|
71
|
-
return subscription.subscribe(this.state, callback);
|
|
72
|
-
}
|
|
73
|
-
/**
|
|
74
|
-
* Unsubscribe from changes
|
|
75
|
-
*/
|
|
76
|
-
unsubscribe(callback) {
|
|
77
|
-
subscription.unsubscribe(this.state, callback);
|
|
78
|
-
}
|
|
79
54
|
}
|
|
80
55
|
function computed(callback) {
|
|
81
56
|
return new Computed(callback);
|
package/dist/computed.js
CHANGED
|
@@ -3,24 +3,17 @@ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { en
|
|
|
3
3
|
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
4
4
|
import { batchedHandlers, batchDepth } from "./batch.js";
|
|
5
5
|
import { effect, activeEffect, runEffect } from "./effect.js";
|
|
6
|
-
import {
|
|
6
|
+
import { Reactive } from "./reactive.js";
|
|
7
7
|
let activeComputed;
|
|
8
|
-
class Computed {
|
|
8
|
+
class Computed extends Reactive {
|
|
9
9
|
constructor(callback) {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
value: "computed"
|
|
13
|
-
});
|
|
14
|
-
this.state = {
|
|
15
|
-
computeds: /* @__PURE__ */ new Set(),
|
|
10
|
+
super("computed", void 0);
|
|
11
|
+
__publicField(this, "effect", {
|
|
16
12
|
dirty: true,
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
};
|
|
22
|
-
this.state.effect = effect(() => {
|
|
23
|
-
if (this.state.dirty) {
|
|
13
|
+
instance: void 0
|
|
14
|
+
});
|
|
15
|
+
this.effect.instance = effect(() => {
|
|
16
|
+
if (this.effect.dirty) {
|
|
24
17
|
const previousComputed = activeComputed;
|
|
25
18
|
activeComputed = this;
|
|
26
19
|
const value = callback();
|
|
@@ -28,7 +21,7 @@ class Computed {
|
|
|
28
21
|
if (!Object.is(this.state.value, value)) {
|
|
29
22
|
this.state.value = value;
|
|
30
23
|
for (const computed2 of this.state.computeds) {
|
|
31
|
-
computed2.
|
|
24
|
+
computed2.effect.dirty = true;
|
|
32
25
|
}
|
|
33
26
|
for (const effect2 of this.state.effects) {
|
|
34
27
|
batchedHandlers.add(effect2);
|
|
@@ -37,7 +30,7 @@ class Computed {
|
|
|
37
30
|
subscription.callback(value);
|
|
38
31
|
}
|
|
39
32
|
}
|
|
40
|
-
this.
|
|
33
|
+
this.effect.dirty = false;
|
|
41
34
|
}
|
|
42
35
|
});
|
|
43
36
|
}
|
|
@@ -48,32 +41,14 @@ class Computed {
|
|
|
48
41
|
if (activeComputed != null && activeComputed !== this) {
|
|
49
42
|
this.state.computeds.add(activeComputed);
|
|
50
43
|
}
|
|
51
|
-
if (activeEffect != null && activeEffect !== this.
|
|
44
|
+
if (activeEffect != null && activeEffect !== this.effect.instance) {
|
|
52
45
|
this.state.effects.add(activeEffect);
|
|
53
46
|
}
|
|
54
|
-
if (this.
|
|
55
|
-
runEffect(this.
|
|
47
|
+
if (this.effect.dirty && batchDepth === 0) {
|
|
48
|
+
runEffect(this.effect.instance);
|
|
56
49
|
}
|
|
57
50
|
return this.state.value;
|
|
58
51
|
}
|
|
59
|
-
/**
|
|
60
|
-
* Get the value _(without reactivity)_
|
|
61
|
-
*/
|
|
62
|
-
peek() {
|
|
63
|
-
return this.state.value;
|
|
64
|
-
}
|
|
65
|
-
/**
|
|
66
|
-
* Subscribe to changes
|
|
67
|
-
*/
|
|
68
|
-
subscribe(callback) {
|
|
69
|
-
return subscribe(this.state, callback);
|
|
70
|
-
}
|
|
71
|
-
/**
|
|
72
|
-
* Unsubscribe from changes
|
|
73
|
-
*/
|
|
74
|
-
unsubscribe(callback) {
|
|
75
|
-
unsubscribe(this.state, callback);
|
|
76
|
-
}
|
|
77
52
|
}
|
|
78
53
|
function computed(callback) {
|
|
79
54
|
return new Computed(callback);
|
package/dist/index.cjs
CHANGED
package/dist/index.js
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import { startBatch, stopBatch } from "./batch.js";
|
|
2
2
|
import { computed } from "./computed.js";
|
|
3
3
|
import { effect } from "./effect.js";
|
|
4
|
-
import { isComputed, isEffect, isSignal } from "./is.js";
|
|
4
|
+
import { isComputed, isEffect, isReactive, isSignal } from "./is.js";
|
|
5
5
|
import { signal } from "./signal.js";
|
|
6
6
|
export {
|
|
7
7
|
computed,
|
|
8
8
|
effect,
|
|
9
9
|
isComputed,
|
|
10
10
|
isEffect,
|
|
11
|
+
isReactive,
|
|
11
12
|
isSignal,
|
|
12
13
|
signal,
|
|
13
14
|
startBatch,
|
package/dist/is.cjs
CHANGED
|
@@ -9,9 +9,13 @@ function isEffect(value) {
|
|
|
9
9
|
function isMora(value, name) {
|
|
10
10
|
return typeof value === "object" && value != null && "$mora" in value && value.$mora === name;
|
|
11
11
|
}
|
|
12
|
+
function isReactive(value) {
|
|
13
|
+
return isComputed(value) || isSignal(value);
|
|
14
|
+
}
|
|
12
15
|
function isSignal(value) {
|
|
13
16
|
return isMora(value, "signal");
|
|
14
17
|
}
|
|
15
18
|
exports.isComputed = isComputed;
|
|
16
19
|
exports.isEffect = isEffect;
|
|
20
|
+
exports.isReactive = isReactive;
|
|
17
21
|
exports.isSignal = isSignal;
|
package/dist/is.js
CHANGED
|
@@ -7,11 +7,15 @@ function isEffect(value) {
|
|
|
7
7
|
function isMora(value, name) {
|
|
8
8
|
return typeof value === "object" && value != null && "$mora" in value && value.$mora === name;
|
|
9
9
|
}
|
|
10
|
+
function isReactive(value) {
|
|
11
|
+
return isComputed(value) || isSignal(value);
|
|
12
|
+
}
|
|
10
13
|
function isSignal(value) {
|
|
11
14
|
return isMora(value, "signal");
|
|
12
15
|
}
|
|
13
16
|
export {
|
|
14
17
|
isComputed,
|
|
15
18
|
isEffect,
|
|
19
|
+
isReactive,
|
|
16
20
|
isSignal
|
|
17
21
|
};
|
package/dist/mora.full.js
CHANGED
|
@@ -45,6 +45,9 @@ function isMora(value, name) {
|
|
|
45
45
|
'$mora' in value &&
|
|
46
46
|
value.$mora === name);
|
|
47
47
|
}
|
|
48
|
+
function isReactive(value) {
|
|
49
|
+
return isComputed(value) || isSignal(value);
|
|
50
|
+
}
|
|
48
51
|
/**
|
|
49
52
|
* Is the value a signal?
|
|
50
53
|
*/
|
|
@@ -112,23 +115,49 @@ function unsubscribe(state, callback) {
|
|
|
112
115
|
}
|
|
113
116
|
}
|
|
114
117
|
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
118
|
+
class Reactive {
|
|
119
|
+
state = {
|
|
120
|
+
computeds: new Set(),
|
|
121
|
+
effects: new Set(),
|
|
122
|
+
subscriptions: new Map(),
|
|
123
|
+
value: undefined,
|
|
124
|
+
};
|
|
125
|
+
constructor(name, value) {
|
|
126
|
+
this.state.value = value;
|
|
119
127
|
Object.defineProperty(this, '$mora', {
|
|
120
|
-
value:
|
|
128
|
+
value: name,
|
|
121
129
|
});
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Get the value _(without reactivity)_
|
|
133
|
+
*/
|
|
134
|
+
peek() {
|
|
135
|
+
return this.state.value;
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Subscribe to changes
|
|
139
|
+
*/
|
|
140
|
+
subscribe(callback) {
|
|
141
|
+
return subscribe(this.state, callback);
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Unsubscribe from changes
|
|
145
|
+
*/
|
|
146
|
+
unsubscribe(callback) {
|
|
147
|
+
unsubscribe(this.state, callback);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
let activeComputed;
|
|
152
|
+
class Computed extends Reactive {
|
|
153
|
+
effect = {
|
|
154
|
+
dirty: true,
|
|
155
|
+
instance: undefined,
|
|
156
|
+
};
|
|
157
|
+
constructor(callback) {
|
|
158
|
+
super('computed', undefined);
|
|
159
|
+
this.effect.instance = effect(() => {
|
|
160
|
+
if (this.effect.dirty) {
|
|
132
161
|
const previousComputed = activeComputed;
|
|
133
162
|
activeComputed = this;
|
|
134
163
|
const value = callback();
|
|
@@ -136,7 +165,7 @@ class Computed {
|
|
|
136
165
|
if (!Object.is(this.state.value, value)) {
|
|
137
166
|
this.state.value = value;
|
|
138
167
|
for (const computed of this.state.computeds) {
|
|
139
|
-
computed.
|
|
168
|
+
computed.effect.dirty = true;
|
|
140
169
|
}
|
|
141
170
|
for (const effect of this.state.effects) {
|
|
142
171
|
batchedHandlers.add(effect);
|
|
@@ -145,7 +174,7 @@ class Computed {
|
|
|
145
174
|
subscription.callback(value);
|
|
146
175
|
}
|
|
147
176
|
}
|
|
148
|
-
this.
|
|
177
|
+
this.effect.dirty = false;
|
|
149
178
|
}
|
|
150
179
|
});
|
|
151
180
|
}
|
|
@@ -156,32 +185,14 @@ class Computed {
|
|
|
156
185
|
if (activeComputed != null && activeComputed !== this) {
|
|
157
186
|
this.state.computeds.add(activeComputed);
|
|
158
187
|
}
|
|
159
|
-
if (activeEffect != null && activeEffect !== this.
|
|
188
|
+
if (activeEffect != null && activeEffect !== this.effect.instance) {
|
|
160
189
|
this.state.effects.add(activeEffect);
|
|
161
190
|
}
|
|
162
|
-
if (this.
|
|
163
|
-
runEffect(this.
|
|
191
|
+
if (this.effect.dirty && batchDepth === 0) {
|
|
192
|
+
runEffect(this.effect.instance);
|
|
164
193
|
}
|
|
165
194
|
return this.state.value;
|
|
166
195
|
}
|
|
167
|
-
/**
|
|
168
|
-
* Get the value _(without reactivity)_
|
|
169
|
-
*/
|
|
170
|
-
peek() {
|
|
171
|
-
return this.state.value;
|
|
172
|
-
}
|
|
173
|
-
/**
|
|
174
|
-
* Subscribe to changes
|
|
175
|
-
*/
|
|
176
|
-
subscribe(callback) {
|
|
177
|
-
return subscribe(this.state, callback);
|
|
178
|
-
}
|
|
179
|
-
/**
|
|
180
|
-
* Unsubscribe from changes
|
|
181
|
-
*/
|
|
182
|
-
unsubscribe(callback) {
|
|
183
|
-
unsubscribe(this.state, callback);
|
|
184
|
-
}
|
|
185
196
|
}
|
|
186
197
|
/**
|
|
187
198
|
* Create a computed value
|
|
@@ -190,18 +201,9 @@ function computed(callback) {
|
|
|
190
201
|
return new Computed(callback);
|
|
191
202
|
}
|
|
192
203
|
|
|
193
|
-
class Signal {
|
|
194
|
-
state;
|
|
204
|
+
class Signal extends Reactive {
|
|
195
205
|
constructor(value) {
|
|
196
|
-
|
|
197
|
-
value: 'signal',
|
|
198
|
-
});
|
|
199
|
-
this.state = {
|
|
200
|
-
value,
|
|
201
|
-
computeds: new Set(),
|
|
202
|
-
effects: new Set(),
|
|
203
|
-
subscriptions: new Map(),
|
|
204
|
-
};
|
|
206
|
+
super('signal', value);
|
|
205
207
|
}
|
|
206
208
|
/**
|
|
207
209
|
* Get the value
|
|
@@ -215,12 +217,6 @@ class Signal {
|
|
|
215
217
|
}
|
|
216
218
|
return this.state.value;
|
|
217
219
|
}
|
|
218
|
-
/**
|
|
219
|
-
* Get the value _(without reactivity)_
|
|
220
|
-
*/
|
|
221
|
-
peek() {
|
|
222
|
-
return this.state.value;
|
|
223
|
-
}
|
|
224
220
|
/**
|
|
225
221
|
* Set the value
|
|
226
222
|
*/
|
|
@@ -230,7 +226,7 @@ class Signal {
|
|
|
230
226
|
}
|
|
231
227
|
this.state.value = value;
|
|
232
228
|
for (const computed of this.state.computeds) {
|
|
233
|
-
computed.
|
|
229
|
+
computed.effect.dirty = true;
|
|
234
230
|
}
|
|
235
231
|
for (const effect of this.state.effects) {
|
|
236
232
|
batchedHandlers.add(effect);
|
|
@@ -242,18 +238,6 @@ class Signal {
|
|
|
242
238
|
flushEffects();
|
|
243
239
|
}
|
|
244
240
|
}
|
|
245
|
-
/**
|
|
246
|
-
* Subscribe to changes
|
|
247
|
-
*/
|
|
248
|
-
subscribe(callback) {
|
|
249
|
-
return subscribe(this.state, callback);
|
|
250
|
-
}
|
|
251
|
-
/**
|
|
252
|
-
* Unsubscribe from changes
|
|
253
|
-
*/
|
|
254
|
-
unsubscribe(callback) {
|
|
255
|
-
unsubscribe(this.state, callback);
|
|
256
|
-
}
|
|
257
241
|
/**
|
|
258
242
|
* Update the value
|
|
259
243
|
*/
|
|
@@ -265,4 +249,4 @@ function signal(value) {
|
|
|
265
249
|
return new Signal(value);
|
|
266
250
|
}
|
|
267
251
|
|
|
268
|
-
export { computed, effect, isComputed, isEffect, isSignal, signal, startBatch, stopBatch };
|
|
252
|
+
export { computed, effect, isComputed, isEffect, isReactive, isSignal, signal, startBatch, stopBatch };
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
4
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
5
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
6
|
+
const subscription = require("./subscription.cjs");
|
|
7
|
+
class Reactive {
|
|
8
|
+
constructor(name, value) {
|
|
9
|
+
__publicField(this, "state", {
|
|
10
|
+
computeds: /* @__PURE__ */ new Set(),
|
|
11
|
+
effects: /* @__PURE__ */ new Set(),
|
|
12
|
+
subscriptions: /* @__PURE__ */ new Map(),
|
|
13
|
+
value: void 0
|
|
14
|
+
});
|
|
15
|
+
this.state.value = value;
|
|
16
|
+
Object.defineProperty(this, "$mora", {
|
|
17
|
+
value: name
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Get the value _(without reactivity)_
|
|
22
|
+
*/
|
|
23
|
+
peek() {
|
|
24
|
+
return this.state.value;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Subscribe to changes
|
|
28
|
+
*/
|
|
29
|
+
subscribe(callback) {
|
|
30
|
+
return subscription.subscribe(this.state, callback);
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Unsubscribe from changes
|
|
34
|
+
*/
|
|
35
|
+
unsubscribe(callback) {
|
|
36
|
+
subscription.unsubscribe(this.state, callback);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
exports.Reactive = Reactive;
|
package/dist/reactive.js
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
3
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
4
|
+
import { subscribe, unsubscribe } from "./subscription.js";
|
|
5
|
+
class Reactive {
|
|
6
|
+
constructor(name, value) {
|
|
7
|
+
__publicField(this, "state", {
|
|
8
|
+
computeds: /* @__PURE__ */ new Set(),
|
|
9
|
+
effects: /* @__PURE__ */ new Set(),
|
|
10
|
+
subscriptions: /* @__PURE__ */ new Map(),
|
|
11
|
+
value: void 0
|
|
12
|
+
});
|
|
13
|
+
this.state.value = value;
|
|
14
|
+
Object.defineProperty(this, "$mora", {
|
|
15
|
+
value: name
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Get the value _(without reactivity)_
|
|
20
|
+
*/
|
|
21
|
+
peek() {
|
|
22
|
+
return this.state.value;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Subscribe to changes
|
|
26
|
+
*/
|
|
27
|
+
subscribe(callback) {
|
|
28
|
+
return subscribe(this.state, callback);
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Unsubscribe from changes
|
|
32
|
+
*/
|
|
33
|
+
unsubscribe(callback) {
|
|
34
|
+
unsubscribe(this.state, callback);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
export {
|
|
38
|
+
Reactive
|
|
39
|
+
};
|
package/dist/signal.cjs
CHANGED
|
@@ -1,24 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
4
|
-
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
5
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
6
3
|
const batch = require("./batch.cjs");
|
|
7
4
|
const computed = require("./computed.cjs");
|
|
8
5
|
const effect = require("./effect.cjs");
|
|
9
|
-
const
|
|
10
|
-
class Signal {
|
|
6
|
+
const reactive = require("./reactive.cjs");
|
|
7
|
+
class Signal extends reactive.Reactive {
|
|
11
8
|
constructor(value) {
|
|
12
|
-
|
|
13
|
-
Object.defineProperty(this, "$mora", {
|
|
14
|
-
value: "signal"
|
|
15
|
-
});
|
|
16
|
-
this.state = {
|
|
17
|
-
value,
|
|
18
|
-
computeds: /* @__PURE__ */ new Set(),
|
|
19
|
-
effects: /* @__PURE__ */ new Set(),
|
|
20
|
-
subscriptions: /* @__PURE__ */ new Map()
|
|
21
|
-
};
|
|
9
|
+
super("signal", value);
|
|
22
10
|
}
|
|
23
11
|
/**
|
|
24
12
|
* Get the value
|
|
@@ -32,12 +20,6 @@ class Signal {
|
|
|
32
20
|
}
|
|
33
21
|
return this.state.value;
|
|
34
22
|
}
|
|
35
|
-
/**
|
|
36
|
-
* Get the value _(without reactivity)_
|
|
37
|
-
*/
|
|
38
|
-
peek() {
|
|
39
|
-
return this.state.value;
|
|
40
|
-
}
|
|
41
23
|
/**
|
|
42
24
|
* Set the value
|
|
43
25
|
*/
|
|
@@ -47,30 +29,18 @@ class Signal {
|
|
|
47
29
|
}
|
|
48
30
|
this.state.value = value;
|
|
49
31
|
for (const computed2 of this.state.computeds) {
|
|
50
|
-
computed2.
|
|
32
|
+
computed2.effect.dirty = true;
|
|
51
33
|
}
|
|
52
34
|
for (const effect2 of this.state.effects) {
|
|
53
35
|
batch.batchedHandlers.add(effect2);
|
|
54
36
|
}
|
|
55
|
-
for (const [,
|
|
56
|
-
batch.batchedHandlers.add(
|
|
37
|
+
for (const [, subscription] of this.state.subscriptions) {
|
|
38
|
+
batch.batchedHandlers.add(subscription);
|
|
57
39
|
}
|
|
58
40
|
if (batch.batchDepth === 0) {
|
|
59
41
|
batch.flushEffects();
|
|
60
42
|
}
|
|
61
43
|
}
|
|
62
|
-
/**
|
|
63
|
-
* Subscribe to changes
|
|
64
|
-
*/
|
|
65
|
-
subscribe(callback) {
|
|
66
|
-
return subscription.subscribe(this.state, callback);
|
|
67
|
-
}
|
|
68
|
-
/**
|
|
69
|
-
* Unsubscribe from changes
|
|
70
|
-
*/
|
|
71
|
-
unsubscribe(callback) {
|
|
72
|
-
subscription.unsubscribe(this.state, callback);
|
|
73
|
-
}
|
|
74
44
|
/**
|
|
75
45
|
* Update the value
|
|
76
46
|
*/
|
package/dist/signal.js
CHANGED
|
@@ -1,22 +1,10 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
3
|
-
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
4
1
|
import { batchedHandlers, flushEffects, batchDepth } from "./batch.js";
|
|
5
2
|
import { activeComputed } from "./computed.js";
|
|
6
3
|
import { activeEffect } from "./effect.js";
|
|
7
|
-
import {
|
|
8
|
-
class Signal {
|
|
4
|
+
import { Reactive } from "./reactive.js";
|
|
5
|
+
class Signal extends Reactive {
|
|
9
6
|
constructor(value) {
|
|
10
|
-
|
|
11
|
-
Object.defineProperty(this, "$mora", {
|
|
12
|
-
value: "signal"
|
|
13
|
-
});
|
|
14
|
-
this.state = {
|
|
15
|
-
value,
|
|
16
|
-
computeds: /* @__PURE__ */ new Set(),
|
|
17
|
-
effects: /* @__PURE__ */ new Set(),
|
|
18
|
-
subscriptions: /* @__PURE__ */ new Map()
|
|
19
|
-
};
|
|
7
|
+
super("signal", value);
|
|
20
8
|
}
|
|
21
9
|
/**
|
|
22
10
|
* Get the value
|
|
@@ -30,12 +18,6 @@ class Signal {
|
|
|
30
18
|
}
|
|
31
19
|
return this.state.value;
|
|
32
20
|
}
|
|
33
|
-
/**
|
|
34
|
-
* Get the value _(without reactivity)_
|
|
35
|
-
*/
|
|
36
|
-
peek() {
|
|
37
|
-
return this.state.value;
|
|
38
|
-
}
|
|
39
21
|
/**
|
|
40
22
|
* Set the value
|
|
41
23
|
*/
|
|
@@ -45,7 +27,7 @@ class Signal {
|
|
|
45
27
|
}
|
|
46
28
|
this.state.value = value;
|
|
47
29
|
for (const computed of this.state.computeds) {
|
|
48
|
-
computed.
|
|
30
|
+
computed.effect.dirty = true;
|
|
49
31
|
}
|
|
50
32
|
for (const effect of this.state.effects) {
|
|
51
33
|
batchedHandlers.add(effect);
|
|
@@ -57,18 +39,6 @@ class Signal {
|
|
|
57
39
|
flushEffects();
|
|
58
40
|
}
|
|
59
41
|
}
|
|
60
|
-
/**
|
|
61
|
-
* Subscribe to changes
|
|
62
|
-
*/
|
|
63
|
-
subscribe(callback) {
|
|
64
|
-
return subscribe(this.state, callback);
|
|
65
|
-
}
|
|
66
|
-
/**
|
|
67
|
-
* Unsubscribe from changes
|
|
68
|
-
*/
|
|
69
|
-
unsubscribe(callback) {
|
|
70
|
-
unsubscribe(this.state, callback);
|
|
71
|
-
}
|
|
72
42
|
/**
|
|
73
43
|
* Update the value
|
|
74
44
|
*/
|
package/package.json
CHANGED
package/src/batch.ts
CHANGED