async-reactivity 2.0.29 → 2.1.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/lib/computed.js +2 -2
- package/lib/computed.test.js +7 -3
- package/lib/ref.test.js +1 -1
- package/package.json +1 -1
- package/src/computed.test.ts +10 -4
- package/src/computed.ts +2 -2
- package/src/ref.test.ts +1 -1
- package/src/watcher.ts +1 -1
- package/types/watcher.d.ts +1 -1
- package/types/watcher.d.ts.map +1 -1
- package/lib/tracker.js +0 -18
- package/types/tracker.d.ts +0 -10
- package/types/tracker.d.ts.map +0 -1
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
|
|
41
|
+
for (const dependent of this.dependents) {
|
|
42
42
|
dependent.validate(this);
|
|
43
43
|
}
|
|
44
44
|
}
|
package/lib/computed.test.js
CHANGED
|
@@ -152,14 +152,18 @@ describe('computed', function () {
|
|
|
152
152
|
});
|
|
153
153
|
it('isEqual', function () {
|
|
154
154
|
const a = new Ref(1);
|
|
155
|
-
|
|
156
|
-
|
|
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
package/src/computed.test.ts
CHANGED
|
@@ -179,16 +179,22 @@ describe('computed', function () {
|
|
|
179
179
|
|
|
180
180
|
it('isEqual', function () {
|
|
181
181
|
const a = new Ref(1);
|
|
182
|
-
|
|
183
|
-
|
|
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
|
|
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/src/watcher.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import Dependency from "./dependency.js";
|
|
2
2
|
import Effect from "./effect.js";
|
|
3
3
|
|
|
4
|
-
type onChangeFunc<T> = (newValue: T, oldValue?: T) => void
|
|
4
|
+
type onChangeFunc<T> = (newValue: T, oldValue?: T) => void | Promise<void>;
|
|
5
5
|
|
|
6
6
|
export default class Watcher<T> extends Effect {
|
|
7
7
|
constructor(dependency: Dependency<T>, onChange: onChangeFunc<T>, immediate: boolean = true) {
|
package/types/watcher.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import Dependency from "./dependency.js";
|
|
2
2
|
import Effect from "./effect.js";
|
|
3
|
-
type onChangeFunc<T> = (newValue: T, oldValue?: T) => void
|
|
3
|
+
type onChangeFunc<T> = (newValue: T, oldValue?: T) => void | Promise<void>;
|
|
4
4
|
export default class Watcher<T> extends Effect {
|
|
5
5
|
constructor(dependency: Dependency<T>, onChange: onChangeFunc<T>, immediate?: boolean);
|
|
6
6
|
}
|
package/types/watcher.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"watcher.d.ts","sourceRoot":"","sources":["../src/watcher.ts"],"names":[],"mappings":"AAAA,OAAO,UAAU,MAAM,iBAAiB,CAAC;AACzC,OAAO,MAAM,MAAM,aAAa,CAAC;AAEjC,KAAK,YAAY,CAAC,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC,EAAE,QAAQ,CAAC,EAAE,CAAC,KAAK,IAAI,CAAC;
|
|
1
|
+
{"version":3,"file":"watcher.d.ts","sourceRoot":"","sources":["../src/watcher.ts"],"names":[],"mappings":"AAAA,OAAO,UAAU,MAAM,iBAAiB,CAAC;AACzC,OAAO,MAAM,MAAM,aAAa,CAAC;AAEjC,KAAK,YAAY,CAAC,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC,EAAE,QAAQ,CAAC,EAAE,CAAC,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;AAE3E,MAAM,CAAC,OAAO,OAAO,OAAO,CAAC,CAAC,CAAE,SAAQ,MAAM;gBAC9B,UAAU,EAAE,UAAU,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,YAAY,CAAC,CAAC,CAAC,EAAE,SAAS,GAAE,OAAc;CAW9F"}
|
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
|
-
}
|
package/types/tracker.d.ts
DELETED
|
@@ -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
|
package/types/tracker.d.ts.map
DELETED
|
@@ -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"}
|