async-reactivity 2.0.24 → 2.0.26

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
@@ -15,7 +15,7 @@ export default class Computed extends Tracker {
15
15
  getter;
16
16
  isEqual;
17
17
  state = ComputedState.Invalid;
18
- dependencies = new Map(); // boolean indicates whether value is up to date in regards to the dependency (false - up to date, true - needs update)
18
+ dependencies = new Map(); // boolean indicates whether value is in sync with the dependency
19
19
  computePromise;
20
20
  computePromiseActions;
21
21
  lastComputeAttemptPromise;
@@ -50,14 +50,14 @@ export default class Computed extends Tracker {
50
50
  }
51
51
  compute() {
52
52
  if (this.state === ComputedState.Uncertain) {
53
- const upToDate = ![...this.dependencies.entries()].some(([d, needsUpdate]) => {
54
- if (needsUpdate && d instanceof Computed && d.state === ComputedState.Uncertain) {
53
+ const inSync = [...this.dependencies.entries()].every(([d, inSync]) => {
54
+ if (!inSync && d instanceof Computed && d.state === ComputedState.Uncertain) {
55
55
  d.value;
56
56
  return this.dependencies.get(d);
57
57
  }
58
- return needsUpdate;
58
+ return inSync;
59
59
  });
60
- if (upToDate) {
60
+ if (inSync) {
61
61
  this.finalizeComputing();
62
62
  this.validateDependents();
63
63
  return this._value;
@@ -112,7 +112,7 @@ export default class Computed extends Tracker {
112
112
  if (this.dependents.has(dependency)) {
113
113
  throw new CircularDependencyError();
114
114
  }
115
- this.dependencies.set(dependency, false);
115
+ this.dependencies.set(dependency, true);
116
116
  dependency.addDependent(this);
117
117
  return dependency.value;
118
118
  }
@@ -124,20 +124,20 @@ export default class Computed extends Tracker {
124
124
  this.prepareComputePromise();
125
125
  }
126
126
  invalidate(dependency) {
127
+ if (dependency) {
128
+ this.dependencies.set(dependency, false);
129
+ }
130
+ else {
131
+ for (const dep of this.dependencies.keys()) {
132
+ this.dependencies.set(dep, false);
133
+ }
134
+ }
127
135
  if (this.state === ComputedState.Computing) {
128
136
  this.lastComputeAttemptPromise = undefined; // prevent finalizeComputing if it is in the event loop already
129
137
  Promise.resolve().then(this.compute.bind(this));
130
138
  }
131
139
  else if (this.state === ComputedState.Valid) {
132
140
  this.state = ComputedState.Uncertain;
133
- if (dependency) {
134
- this.dependencies.set(dependency, true);
135
- }
136
- else {
137
- for (const dep of this.dependencies.keys()) {
138
- this.dependencies.set(dep, true);
139
- }
140
- }
141
141
  super.invalidate();
142
142
  }
143
143
  }
@@ -148,7 +148,7 @@ export default class Computed extends Tracker {
148
148
  }
149
149
  }
150
150
  validate(dependency) {
151
- this.dependencies.set(dependency, false);
151
+ this.dependencies.set(dependency, true);
152
152
  }
153
153
  validateDependents() {
154
154
  for (const dependent of this.dependents.keys()) {
package/lib/watcher.js CHANGED
@@ -34,7 +34,6 @@ export default class Watcher extends Tracker {
34
34
  });
35
35
  }
36
36
  validate() {
37
- console.log('validate');
38
37
  this.state = WatchState.Valid;
39
38
  }
40
39
  dispose() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "async-reactivity",
3
- "version": "2.0.24",
3
+ "version": "2.0.26",
4
4
  "description": "",
5
5
  "main": "lib/index.js",
6
6
  "types": "types/index.d.ts",
package/src/computed.ts CHANGED
@@ -22,7 +22,7 @@ export default class Computed<T> extends Tracker<T> implements Dependent, Depend
22
22
  getter: ComputeFunc<T>;
23
23
  isEqual: typeof defaultIsEqual<T>;
24
24
  private state = ComputedState.Invalid;
25
- private dependencies = new Map<Dependency<unknown>, boolean>(); // boolean indicates whether value is up to date in regards to the dependency (false - up to date, true - needs update)
25
+ private dependencies = new Map<Dependency<unknown>, boolean>(); // boolean indicates whether value is in sync with the dependency
26
26
  private computePromise?: Promise<unknown>;
27
27
  private computePromiseActions?: { resolve: Function, reject: Function };
28
28
  private lastComputeAttemptPromise?: Promise<void>;
@@ -63,14 +63,14 @@ export default class Computed<T> extends Tracker<T> implements Dependent, Depend
63
63
 
64
64
  private compute() {
65
65
  if (this.state === ComputedState.Uncertain) {
66
- const upToDate = ![...this.dependencies.entries()].some(([d, needsUpdate]) => {
67
- if (needsUpdate && d instanceof Computed && d.state === ComputedState.Uncertain) {
66
+ const inSync = [...this.dependencies.entries()].every(([d, inSync]) => {
67
+ if (!inSync && d instanceof Computed && d.state === ComputedState.Uncertain) {
68
68
  d.value;
69
69
  return this.dependencies.get(d);
70
70
  }
71
- return needsUpdate;
71
+ return inSync;
72
72
  });
73
- if (upToDate) {
73
+ if (inSync) {
74
74
  this.finalizeComputing();
75
75
  this.validateDependents();
76
76
  return this._value!;
@@ -128,7 +128,7 @@ export default class Computed<T> extends Tracker<T> implements Dependent, Depend
128
128
  if (this.dependents.has(dependency as any)) {
129
129
  throw new CircularDependencyError();
130
130
  }
131
- this.dependencies.set(dependency, false);
131
+ this.dependencies.set(dependency, true);
132
132
  dependency.addDependent(this);
133
133
  return dependency.value;
134
134
  }
@@ -143,18 +143,18 @@ export default class Computed<T> extends Tracker<T> implements Dependent, Depend
143
143
  }
144
144
 
145
145
  public invalidate(dependency?: Dependency<unknown>) {
146
+ if (dependency) {
147
+ this.dependencies.set(dependency, false);
148
+ } else {
149
+ for (const dep of this.dependencies.keys()) {
150
+ this.dependencies.set(dep, false);
151
+ }
152
+ }
146
153
  if (this.state === ComputedState.Computing) {
147
154
  this.lastComputeAttemptPromise = undefined; // prevent finalizeComputing if it is in the event loop already
148
155
  Promise.resolve().then(this.compute.bind(this));
149
156
  } else if (this.state === ComputedState.Valid) {
150
157
  this.state = ComputedState.Uncertain;
151
- if (dependency) {
152
- this.dependencies.set(dependency, true);
153
- } else {
154
- for (const dep of this.dependencies.keys()) {
155
- this.dependencies.set(dep, true);
156
- }
157
- }
158
158
  super.invalidate();
159
159
  }
160
160
  }
@@ -167,7 +167,7 @@ export default class Computed<T> extends Tracker<T> implements Dependent, Depend
167
167
  }
168
168
 
169
169
  public validate(dependency: Dependency<unknown>) {
170
- this.dependencies.set(dependency, false);
170
+ this.dependencies.set(dependency, true);
171
171
  }
172
172
 
173
173
  private validateDependents() {
package/src/watcher.ts CHANGED
@@ -43,7 +43,6 @@ export default class Watcher<T> extends Tracker<T> implements Dependent {
43
43
  }
44
44
 
45
45
  public validate() {
46
- console.log('validate');
47
46
  this.state = WatchState.Valid;
48
47
  }
49
48
 
@@ -1 +1 @@
1
- {"version":3,"file":"watcher.d.ts","sourceRoot":"","sources":["../src/watcher.ts"],"names":[],"mappings":"AAAA,OAAO,UAAU,MAAM,iBAAiB,CAAC;AACzC,OAAO,SAAS,MAAM,gBAAgB,CAAC;AACvC,OAAO,OAAO,MAAM,cAAc,CAAC;AAOnC,KAAK,YAAY,CAAC,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC,EAAE,QAAQ,CAAC,EAAE,CAAC,KAAK,IAAI,CAAC;AAE3D,MAAM,CAAC,OAAO,OAAO,OAAO,CAAC,CAAC,CAAE,SAAQ,OAAO,CAAC,CAAC,CAAE,YAAW,SAAS;IAEnE,OAAO,CAAC,QAAQ,CAAkB;IAClC,OAAO,CAAC,UAAU,CAAgB;IAClC,OAAO,CAAC,KAAK,CAAoB;gBAErB,UAAU,EAAE,UAAU,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,YAAY,CAAC,CAAC,CAAC,EAAE,SAAS,GAAE,OAAc;IAYpF,UAAU;IAeV,QAAQ;IAKR,OAAO;CAGjB"}
1
+ {"version":3,"file":"watcher.d.ts","sourceRoot":"","sources":["../src/watcher.ts"],"names":[],"mappings":"AAAA,OAAO,UAAU,MAAM,iBAAiB,CAAC;AACzC,OAAO,SAAS,MAAM,gBAAgB,CAAC;AACvC,OAAO,OAAO,MAAM,cAAc,CAAC;AAOnC,KAAK,YAAY,CAAC,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC,EAAE,QAAQ,CAAC,EAAE,CAAC,KAAK,IAAI,CAAC;AAE3D,MAAM,CAAC,OAAO,OAAO,OAAO,CAAC,CAAC,CAAE,SAAQ,OAAO,CAAC,CAAC,CAAE,YAAW,SAAS;IAEnE,OAAO,CAAC,QAAQ,CAAkB;IAClC,OAAO,CAAC,UAAU,CAAgB;IAClC,OAAO,CAAC,KAAK,CAAoB;gBAErB,UAAU,EAAE,UAAU,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,YAAY,CAAC,CAAC,CAAC,EAAE,SAAS,GAAE,OAAc;IAYpF,UAAU;IAeV,QAAQ;IAIR,OAAO;CAGjB"}