async-reactivity 2.0.29 → 2.0.30

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/lib/computed.js CHANGED
@@ -30,7 +30,7 @@ export default class Computed extends Effect {
30
30
  const newValue = this.run();
31
31
  if (newValue !== InSyncSymbol) {
32
32
  this._value = newValue;
33
- if (this.isEqual(this._value, oldValue)) {
33
+ if (this.dependents.size > 0 && this.isEqual(this._value, oldValue)) {
34
34
  this.validateDependents();
35
35
  }
36
36
  }
@@ -38,7 +38,7 @@ export default class Computed extends Effect {
38
38
  return this._value;
39
39
  }
40
40
  validateDependents() {
41
- for (const dependent of this.dependents.keys()) {
41
+ for (const dependent of this.dependents) {
42
42
  dependent.validate(this);
43
43
  }
44
44
  }
@@ -152,14 +152,18 @@ describe('computed', function () {
152
152
  });
153
153
  it('isEqual', function () {
154
154
  const a = new Ref(1);
155
- const b = new Computed((value) => {
156
- return value(a);
157
- }, (_newValue, oldValue) => oldValue !== undefined);
155
+ let isEqual = false;
156
+ const b = new Computed((value) => value(a), () => isEqual);
158
157
  const c = new Computed(value => value(b));
159
158
  assert.strictEqual(c.value, 1);
159
+ isEqual = true;
160
160
  a.value = 2;
161
161
  assert.strictEqual(c.value, 1);
162
162
  });
163
+ it('should not call isEqual when there are no dependents (optimization)', function () {
164
+ const a = new Computed(() => 5, () => assert.fail());
165
+ assert.strictEqual(a.value, 5);
166
+ });
163
167
  });
164
168
  describe('async', function () {
165
169
  it('getter', async function () {
package/lib/ref.test.js CHANGED
@@ -18,7 +18,7 @@ describe('ref', function () {
18
18
  }, false);
19
19
  a.value = 4;
20
20
  });
21
- it('should not call isEqual when there are no dependents', function () {
21
+ it('should not call isEqual when there are no dependents (optimization)', function () {
22
22
  const a = new Ref(5, () => assert.fail());
23
23
  a.value = 4;
24
24
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "async-reactivity",
3
- "version": "2.0.29",
3
+ "version": "2.0.30",
4
4
  "description": "",
5
5
  "main": "lib/index.js",
6
6
  "types": "types/index.d.ts",
@@ -179,16 +179,22 @@ describe('computed', function () {
179
179
 
180
180
  it('isEqual', function () {
181
181
  const a = new Ref(1);
182
- const b = new Computed((value) => {
183
- return value(a);
184
- }, (_newValue, oldValue) => oldValue !== undefined);
182
+ let isEqual = false;
183
+ const b = new Computed((value) => value(a), () => isEqual);
185
184
  const c = new Computed(value => value(b));
186
185
 
187
186
  assert.strictEqual(c.value, 1);
188
-
187
+ isEqual = true;
189
188
  a.value = 2;
189
+
190
190
  assert.strictEqual(c.value, 1);
191
191
  });
192
+
193
+ it('should not call isEqual when there are no dependents (optimization)', function () {
194
+ const a = new Computed(() => 5, () => assert.fail());
195
+
196
+ assert.strictEqual(a.value, 5);
197
+ });
192
198
  });
193
199
 
194
200
  describe('async', function () {
package/src/computed.ts CHANGED
@@ -42,7 +42,7 @@ export default class Computed<T> extends Effect implements Dependent, Dependency
42
42
  const newValue = this.run() as T;
43
43
  if (newValue !== InSyncSymbol) {
44
44
  this._value = newValue;
45
- if (this.isEqual(this._value!, oldValue)) {
45
+ if (this.dependents.size > 0 && this.isEqual(this._value!, oldValue)) {
46
46
  this.validateDependents();
47
47
  }
48
48
  }
@@ -52,7 +52,7 @@ export default class Computed<T> extends Effect implements Dependent, Dependency
52
52
  }
53
53
 
54
54
  private validateDependents() {
55
- for (const dependent of this.dependents.keys()) {
55
+ for (const dependent of this.dependents) {
56
56
  dependent.validate(this);
57
57
  }
58
58
  }
package/src/ref.test.ts CHANGED
@@ -22,7 +22,7 @@ describe('ref', function () {
22
22
  a.value = 4;
23
23
  });
24
24
 
25
- it('should not call isEqual when there are no dependents', function () {
25
+ it('should not call isEqual when there are no dependents (optimization)', function () {
26
26
  const a = new Ref(5, () => assert.fail());
27
27
  a.value = 4;
28
28
  });
package/lib/tracker.js DELETED
@@ -1,18 +0,0 @@
1
- export default class Tracker {
2
- dependents = new Set();
3
- _value;
4
- addDependent(dependent) {
5
- this.dependents.add(dependent);
6
- }
7
- removeDependent(dependent) {
8
- this.dependents.delete(dependent);
9
- }
10
- invalidate() {
11
- for (const dependent of [...this.dependents.keys()]) {
12
- dependent.invalidate(this);
13
- }
14
- }
15
- get value() {
16
- return this._value;
17
- }
18
- }
@@ -1,10 +0,0 @@
1
- import Dependent from "./dependent.js";
2
- export default class Tracker<T> {
3
- protected dependents: Set<Dependent>;
4
- protected _value?: T;
5
- addDependent(dependent: Dependent): void;
6
- removeDependent(dependent: Dependent): void;
7
- invalidate(): void;
8
- get value(): T | undefined;
9
- }
10
- //# sourceMappingURL=tracker.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"tracker.d.ts","sourceRoot":"","sources":["../src/tracker.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,gBAAgB,CAAC;AAEvC,MAAM,CAAC,OAAO,OAAO,OAAO,CAAC,CAAC;IAC1B,SAAS,CAAC,UAAU,iBAAwB;IAC5C,SAAS,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;IAEd,YAAY,CAAC,SAAS,EAAE,SAAS;IAIjC,eAAe,CAAC,SAAS,EAAE,SAAS;IAIpC,UAAU,IAAI,IAAI;IAMzB,IAAW,KAAK,kBAEf;CACJ"}