@oscarpalmer/mora 0.6.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.
- package/README.md +2 -0
- package/dist/computed.cjs +10 -9
- package/dist/computed.js +10 -9
- package/dist/effect.cjs +0 -4
- package/dist/effect.js +0 -4
- package/dist/mora.full.js +18 -14
- package/dist/signal.cjs +8 -3
- package/dist/signal.js +8 -3
- package/package.json +1 -1
- package/src/computed.ts +11 -10
- package/src/effect.ts +1 -1
- package/src/signal.ts +9 -4
- package/types/computed.d.cts +4 -0
- package/types/computed.d.ts +4 -0
- package/types/index.d.cts +8 -0
- package/types/signal.d.cts +4 -0
- package/types/signal.d.ts +4 -0
package/README.md
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# Mora
|
|
2
2
|
|
|
3
|
+
[](https://www.npmjs.com/package/@oscarpalmer/mora) [](https://github.com/oscarpalmer/mora/actions/workflows/test.yml)
|
|
4
|
+
|
|
3
5
|
Signals and stuff…
|
|
4
6
|
|
|
5
7
|
## License
|
package/dist/computed.cjs
CHANGED
|
@@ -24,9 +24,8 @@ class Computed {
|
|
|
24
24
|
exports.activeComputed = previousComputed;
|
|
25
25
|
if (!Object.is(this.state.value, value)) {
|
|
26
26
|
this.state.value = value;
|
|
27
|
-
for (const
|
|
28
|
-
|
|
29
|
-
effect.dirtyEffects.add(comp.state.effect);
|
|
27
|
+
for (const computed2 of this.state.computeds) {
|
|
28
|
+
computed2.state.dirty = true;
|
|
30
29
|
}
|
|
31
30
|
for (const effect2 of this.state.effects) {
|
|
32
31
|
effect.dirtyEffects.add(effect2);
|
|
@@ -46,15 +45,17 @@ class Computed {
|
|
|
46
45
|
if (effect.activeEffect != null && effect.activeEffect !== this.state.effect) {
|
|
47
46
|
this.state.effects.add(effect.activeEffect);
|
|
48
47
|
}
|
|
49
|
-
if (this.state.dirty) {
|
|
50
|
-
|
|
51
|
-
effect.runEffect(this.state.effect);
|
|
52
|
-
} else {
|
|
53
|
-
effect.dirtyEffects.add(this.state.effect);
|
|
54
|
-
}
|
|
48
|
+
if (this.state.dirty && batch.batchDepth === 0) {
|
|
49
|
+
effect.runEffect(this.state.effect);
|
|
55
50
|
}
|
|
56
51
|
return this.state.value;
|
|
57
52
|
}
|
|
53
|
+
/**
|
|
54
|
+
* Get the value _(without reactivity)_
|
|
55
|
+
*/
|
|
56
|
+
peek() {
|
|
57
|
+
return this.state.value;
|
|
58
|
+
}
|
|
58
59
|
}
|
|
59
60
|
function computed(callback) {
|
|
60
61
|
return new Computed(callback);
|
package/dist/computed.js
CHANGED
|
@@ -22,9 +22,8 @@ class Computed {
|
|
|
22
22
|
activeComputed = previousComputed;
|
|
23
23
|
if (!Object.is(this.state.value, value)) {
|
|
24
24
|
this.state.value = value;
|
|
25
|
-
for (const
|
|
26
|
-
|
|
27
|
-
dirtyEffects.add(comp.state.effect);
|
|
25
|
+
for (const computed2 of this.state.computeds) {
|
|
26
|
+
computed2.state.dirty = true;
|
|
28
27
|
}
|
|
29
28
|
for (const effect2 of this.state.effects) {
|
|
30
29
|
dirtyEffects.add(effect2);
|
|
@@ -44,15 +43,17 @@ class Computed {
|
|
|
44
43
|
if (activeEffect != null && activeEffect !== this.state.effect) {
|
|
45
44
|
this.state.effects.add(activeEffect);
|
|
46
45
|
}
|
|
47
|
-
if (this.state.dirty) {
|
|
48
|
-
|
|
49
|
-
runEffect(this.state.effect);
|
|
50
|
-
} else {
|
|
51
|
-
dirtyEffects.add(this.state.effect);
|
|
52
|
-
}
|
|
46
|
+
if (this.state.dirty && batchDepth === 0) {
|
|
47
|
+
runEffect(this.state.effect);
|
|
53
48
|
}
|
|
54
49
|
return this.state.value;
|
|
55
50
|
}
|
|
51
|
+
/**
|
|
52
|
+
* Get the value _(without reactivity)_
|
|
53
|
+
*/
|
|
54
|
+
peek() {
|
|
55
|
+
return this.state.value;
|
|
56
|
+
}
|
|
56
57
|
}
|
|
57
58
|
function computed(callback) {
|
|
58
59
|
return new Computed(callback);
|
package/dist/effect.cjs
CHANGED
|
@@ -1,11 +1,7 @@
|
|
|
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
|
class Effect {
|
|
7
4
|
constructor(callback) {
|
|
8
|
-
__publicField(this, "state");
|
|
9
5
|
this.state = {
|
|
10
6
|
callback
|
|
11
7
|
};
|
package/dist/effect.js
CHANGED
|
@@ -1,9 +1,5 @@
|
|
|
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
|
class Effect {
|
|
5
2
|
constructor(callback) {
|
|
6
|
-
__publicField(this, "state");
|
|
7
3
|
this.state = {
|
|
8
4
|
callback
|
|
9
5
|
};
|
package/dist/mora.full.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
class Effect {
|
|
2
|
-
state;
|
|
3
2
|
constructor(callback) {
|
|
4
3
|
this.state = {
|
|
5
4
|
callback,
|
|
@@ -71,9 +70,8 @@ class Computed {
|
|
|
71
70
|
activeComputed = previousComputed;
|
|
72
71
|
if (!Object.is(this.state.value, value)) {
|
|
73
72
|
this.state.value = value;
|
|
74
|
-
for (const
|
|
75
|
-
|
|
76
|
-
dirtyEffects.add(comp.state.effect);
|
|
73
|
+
for (const computed of this.state.computeds) {
|
|
74
|
+
computed.state.dirty = true;
|
|
77
75
|
}
|
|
78
76
|
for (const effect of this.state.effects) {
|
|
79
77
|
dirtyEffects.add(effect);
|
|
@@ -93,16 +91,17 @@ class Computed {
|
|
|
93
91
|
if (activeEffect != null && activeEffect !== this.state.effect) {
|
|
94
92
|
this.state.effects.add(activeEffect);
|
|
95
93
|
}
|
|
96
|
-
if (this.state.dirty) {
|
|
97
|
-
|
|
98
|
-
runEffect(this.state.effect);
|
|
99
|
-
}
|
|
100
|
-
else {
|
|
101
|
-
dirtyEffects.add(this.state.effect);
|
|
102
|
-
}
|
|
94
|
+
if (this.state.dirty && batchDepth === 0) {
|
|
95
|
+
runEffect(this.state.effect);
|
|
103
96
|
}
|
|
104
97
|
return this.state.value;
|
|
105
98
|
}
|
|
99
|
+
/**
|
|
100
|
+
* Get the value _(without reactivity)_
|
|
101
|
+
*/
|
|
102
|
+
peek() {
|
|
103
|
+
return this.state.value;
|
|
104
|
+
}
|
|
106
105
|
}
|
|
107
106
|
/**
|
|
108
107
|
* Create a computed value
|
|
@@ -132,6 +131,12 @@ class Signal {
|
|
|
132
131
|
}
|
|
133
132
|
return this.state.value;
|
|
134
133
|
}
|
|
134
|
+
/**
|
|
135
|
+
* Get the value _(without reactivity)_
|
|
136
|
+
*/
|
|
137
|
+
peek() {
|
|
138
|
+
return this.state.value;
|
|
139
|
+
}
|
|
135
140
|
/**
|
|
136
141
|
* Set the value
|
|
137
142
|
*/
|
|
@@ -140,9 +145,8 @@ class Signal {
|
|
|
140
145
|
return;
|
|
141
146
|
}
|
|
142
147
|
this.state.value = value;
|
|
143
|
-
for (const
|
|
144
|
-
|
|
145
|
-
dirtyEffects.add(comp.state.effect);
|
|
148
|
+
for (const computed of this.state.computeds) {
|
|
149
|
+
computed.state.dirty = true;
|
|
146
150
|
}
|
|
147
151
|
for (const effect of this.state.effects) {
|
|
148
152
|
dirtyEffects.add(effect);
|
package/dist/signal.cjs
CHANGED
|
@@ -27,6 +27,12 @@ class Signal {
|
|
|
27
27
|
}
|
|
28
28
|
return this.state.value;
|
|
29
29
|
}
|
|
30
|
+
/**
|
|
31
|
+
* Get the value _(without reactivity)_
|
|
32
|
+
*/
|
|
33
|
+
peek() {
|
|
34
|
+
return this.state.value;
|
|
35
|
+
}
|
|
30
36
|
/**
|
|
31
37
|
* Set the value
|
|
32
38
|
*/
|
|
@@ -35,9 +41,8 @@ class Signal {
|
|
|
35
41
|
return;
|
|
36
42
|
}
|
|
37
43
|
this.state.value = value;
|
|
38
|
-
for (const
|
|
39
|
-
|
|
40
|
-
effect.dirtyEffects.add(comp.state.effect);
|
|
44
|
+
for (const computed2 of this.state.computeds) {
|
|
45
|
+
computed2.state.dirty = true;
|
|
41
46
|
}
|
|
42
47
|
for (const effect$1 of this.state.effects) {
|
|
43
48
|
effect.dirtyEffects.add(effect$1);
|
package/dist/signal.js
CHANGED
|
@@ -25,6 +25,12 @@ class Signal {
|
|
|
25
25
|
}
|
|
26
26
|
return this.state.value;
|
|
27
27
|
}
|
|
28
|
+
/**
|
|
29
|
+
* Get the value _(without reactivity)_
|
|
30
|
+
*/
|
|
31
|
+
peek() {
|
|
32
|
+
return this.state.value;
|
|
33
|
+
}
|
|
28
34
|
/**
|
|
29
35
|
* Set the value
|
|
30
36
|
*/
|
|
@@ -33,9 +39,8 @@ class Signal {
|
|
|
33
39
|
return;
|
|
34
40
|
}
|
|
35
41
|
this.state.value = value;
|
|
36
|
-
for (const
|
|
37
|
-
|
|
38
|
-
dirtyEffects.add(comp.state.effect);
|
|
42
|
+
for (const computed of this.state.computeds) {
|
|
43
|
+
computed.state.dirty = true;
|
|
39
44
|
}
|
|
40
45
|
for (const effect of this.state.effects) {
|
|
41
46
|
dirtyEffects.add(effect);
|
package/package.json
CHANGED
package/src/computed.ts
CHANGED
|
@@ -46,10 +46,8 @@ export class Computed<Value> {
|
|
|
46
46
|
if (!Object.is(this.state.value, value)) {
|
|
47
47
|
this.state.value = value;
|
|
48
48
|
|
|
49
|
-
for (const
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
dirtyEffects.add(comp.state.effect);
|
|
49
|
+
for (const computed of this.state.computeds) {
|
|
50
|
+
computed.state.dirty = true;
|
|
53
51
|
}
|
|
54
52
|
|
|
55
53
|
for (const effect of this.state.effects) {
|
|
@@ -74,16 +72,19 @@ export class Computed<Value> {
|
|
|
74
72
|
this.state.effects.add(activeEffect);
|
|
75
73
|
}
|
|
76
74
|
|
|
77
|
-
if (this.state.dirty) {
|
|
78
|
-
|
|
79
|
-
runEffect(this.state.effect);
|
|
80
|
-
} else {
|
|
81
|
-
dirtyEffects.add(this.state.effect);
|
|
82
|
-
}
|
|
75
|
+
if (this.state.dirty && batchDepth === 0) {
|
|
76
|
+
runEffect(this.state.effect);
|
|
83
77
|
}
|
|
84
78
|
|
|
85
79
|
return this.state.value;
|
|
86
80
|
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Get the value _(without reactivity)_
|
|
84
|
+
*/
|
|
85
|
+
peek(): Value {
|
|
86
|
+
return this.state.value;
|
|
87
|
+
}
|
|
87
88
|
}
|
|
88
89
|
|
|
89
90
|
/**
|
package/src/effect.ts
CHANGED
package/src/signal.ts
CHANGED
|
@@ -34,6 +34,13 @@ export class Signal<Value> {
|
|
|
34
34
|
return this.state.value;
|
|
35
35
|
}
|
|
36
36
|
|
|
37
|
+
/**
|
|
38
|
+
* Get the value _(without reactivity)_
|
|
39
|
+
*/
|
|
40
|
+
peek(): Value {
|
|
41
|
+
return this.state.value;
|
|
42
|
+
}
|
|
43
|
+
|
|
37
44
|
/**
|
|
38
45
|
* Set the value
|
|
39
46
|
*/
|
|
@@ -44,10 +51,8 @@ export class Signal<Value> {
|
|
|
44
51
|
|
|
45
52
|
this.state.value = value;
|
|
46
53
|
|
|
47
|
-
for (const
|
|
48
|
-
(
|
|
49
|
-
|
|
50
|
-
dirtyEffects.add((comp as unknown as InternalComputed).state.effect);
|
|
54
|
+
for (const computed of this.state.computeds) {
|
|
55
|
+
(computed as unknown as InternalComputed).state.dirty = true;
|
|
51
56
|
}
|
|
52
57
|
|
|
53
58
|
for (const effect of this.state.effects) {
|
package/types/computed.d.cts
CHANGED
package/types/computed.d.ts
CHANGED
package/types/index.d.cts
CHANGED
|
@@ -7,6 +7,10 @@ export declare class Signal<Value> {
|
|
|
7
7
|
* Get the value
|
|
8
8
|
*/
|
|
9
9
|
get(): Value;
|
|
10
|
+
/**
|
|
11
|
+
* Get the value _(without reactivity)_
|
|
12
|
+
*/
|
|
13
|
+
peek(): Value;
|
|
10
14
|
/**
|
|
11
15
|
* Set the value
|
|
12
16
|
*/
|
|
@@ -41,6 +45,10 @@ export declare class Computed<Value> {
|
|
|
41
45
|
* Get the value
|
|
42
46
|
*/
|
|
43
47
|
get(): Value;
|
|
48
|
+
/**
|
|
49
|
+
* Get the value _(without reactivity)_
|
|
50
|
+
*/
|
|
51
|
+
peek(): Value;
|
|
44
52
|
}
|
|
45
53
|
/**
|
|
46
54
|
* Create a computed value
|
package/types/signal.d.cts
CHANGED