@oscarpalmer/mora 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.
package/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # Mora
2
2
 
3
+ [![npm](https://badge.fury.io/js/@oscarpalmer%2Fmora.svg)](https://www.npmjs.com/package/@oscarpalmer/mora) [![Tests](https://github.com/oscarpalmer/mora/actions/workflows/test.yml/badge.svg)](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 comp of this.state.computeds) {
28
- comp.state.dirty = true;
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
- if (batch.batchDepth === 0) {
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 comp of this.state.computeds) {
26
- comp.state.dirty = true;
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
- if (batchDepth === 0) {
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 comp of this.state.computeds) {
75
- comp.state.dirty = true;
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
- if (batchDepth === 0) {
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 comp of this.state.computeds) {
144
- comp.state.dirty = true;
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 comp of this.state.computeds) {
39
- comp.state.dirty = true;
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 comp of this.state.computeds) {
37
- comp.state.dirty = true;
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
@@ -52,5 +52,5 @@
52
52
  },
53
53
  "type": "module",
54
54
  "types": "./types/index.d.ts",
55
- "version": "0.7.0"
55
+ "version": "0.8.0"
56
56
  }
package/src/computed.ts CHANGED
@@ -48,8 +48,6 @@ export class Computed<Value> {
48
48
 
49
49
  for (const computed of this.state.computeds) {
50
50
  computed.state.dirty = true;
51
-
52
- dirtyEffects.add(computed.state.effect);
53
51
  }
54
52
 
55
53
  for (const effect of this.state.effects) {
@@ -74,12 +72,8 @@ export class Computed<Value> {
74
72
  this.state.effects.add(activeEffect);
75
73
  }
76
74
 
77
- if (this.state.dirty) {
78
- if (batchDepth === 0) {
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;
package/src/signal.ts CHANGED
@@ -53,8 +53,6 @@ export class Signal<Value> {
53
53
 
54
54
  for (const computed of this.state.computeds) {
55
55
  (computed as unknown as InternalComputed).state.dirty = true;
56
-
57
- dirtyEffects.add((computed as unknown as InternalComputed).state.effect);
58
56
  }
59
57
 
60
58
  for (const effect of this.state.effects) {
@@ -23,6 +23,10 @@ export declare class Computed<Value> {
23
23
  * Get the value
24
24
  */
25
25
  get(): Value;
26
+ /**
27
+ * Get the value _(without reactivity)_
28
+ */
29
+ peek(): Value;
26
30
  }
27
31
  /**
28
32
  * Create a computed value
@@ -17,6 +17,10 @@ export declare class Computed<Value> {
17
17
  * Get the value
18
18
  */
19
19
  get(): Value;
20
+ /**
21
+ * Get the value _(without reactivity)_
22
+ */
23
+ peek(): Value;
20
24
  }
21
25
  /**
22
26
  * Create a computed value
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
@@ -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
  */
package/types/signal.d.ts CHANGED
@@ -5,6 +5,10 @@ export declare class Signal<Value> {
5
5
  * Get the value
6
6
  */
7
7
  get(): Value;
8
+ /**
9
+ * Get the value _(without reactivity)_
10
+ */
11
+ peek(): Value;
8
12
  /**
9
13
  * Set the value
10
14
  */