jazz-tools 0.7.0-alpha.35 → 0.7.0-alpha.36

Sign up to get free protection for your applications and to get access to all the features.
Files changed (35) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/dist/coValues/account.js +5 -4
  3. package/dist/coValues/account.js.map +1 -1
  4. package/dist/coValues/coList.js +2 -1
  5. package/dist/coValues/coList.js.map +1 -1
  6. package/dist/coValues/coMap.js +6 -4
  7. package/dist/coValues/coMap.js.map +1 -1
  8. package/dist/coValues/coStream.js +2 -2
  9. package/dist/coValues/coStream.js.map +1 -1
  10. package/dist/coValues/extensions/imageDef.js +1 -1
  11. package/dist/coValues/extensions/imageDef.js.map +1 -1
  12. package/dist/coValues/group.js +1 -1
  13. package/dist/coValues/group.js.map +1 -1
  14. package/dist/coValues/interfaces.js +16 -9
  15. package/dist/coValues/interfaces.js.map +1 -1
  16. package/dist/implementation/devtoolsFormatters.js +113 -0
  17. package/dist/implementation/devtoolsFormatters.js.map +1 -0
  18. package/dist/implementation/refs.js +24 -4
  19. package/dist/implementation/refs.js.map +1 -1
  20. package/dist/implementation/subscriptionScope.js +14 -1
  21. package/dist/implementation/subscriptionScope.js.map +1 -1
  22. package/dist/internal.js +1 -0
  23. package/dist/internal.js.map +1 -1
  24. package/package.json +3 -3
  25. package/src/coValues/account.ts +5 -4
  26. package/src/coValues/coList.ts +11 -8
  27. package/src/coValues/coMap.ts +12 -4
  28. package/src/coValues/coStream.ts +2 -2
  29. package/src/coValues/extensions/imageDef.ts +1 -1
  30. package/src/coValues/group.ts +1 -1
  31. package/src/coValues/interfaces.ts +33 -20
  32. package/src/implementation/devtoolsFormatters.ts +109 -0
  33. package/src/implementation/refs.ts +22 -4
  34. package/src/implementation/subscriptionScope.ts +17 -1
  35. package/src/internal.ts +3 -1
@@ -6,6 +6,8 @@ export const subscriptionsScopes = new WeakMap<
6
6
  SubscriptionScope<any>
7
7
  >();
8
8
 
9
+ const TRACE_INVALIDATIONS = false;
10
+
9
11
  export class SubscriptionScope<
10
12
  Root extends CoValue
11
13
  > {
@@ -23,6 +25,8 @@ export class SubscriptionScope<
23
25
  };
24
26
  onUpdate: (newRoot: Root) => void;
25
27
  scheduledUpdate: boolean = false;
28
+ cachedValues: {[id: ID<CoValue>]: CoValue} = {};
29
+ parents: {[id: ID<CoValue>]: Set<ID<CoValue>>} = {};
26
30
 
27
31
  constructor(
28
32
  root: Root,
@@ -63,12 +67,15 @@ export class SubscriptionScope<
63
67
  }
64
68
  }
65
69
 
66
- onRefAccessedOrSet(accessedOrSetId: ID<CoValue> | undefined) {
70
+ onRefAccessedOrSet(fromId: ID<CoValue>, accessedOrSetId: ID<CoValue> | undefined) {
67
71
  // console.log("onRefAccessedOrSet", this.scopeID, accessedOrSetId);
68
72
  if (!accessedOrSetId) {
69
73
  return;
70
74
  }
71
75
 
76
+ this.parents[accessedOrSetId] = this.parents[accessedOrSetId] || new Set();
77
+ this.parents[accessedOrSetId]!.add(fromId);
78
+
72
79
  if (!this.entries.has(accessedOrSetId)) {
73
80
  const loadingEntry = {
74
81
  state: "loading",
@@ -94,6 +101,7 @@ export class SubscriptionScope<
94
101
  const rawUnsub = core.subscribe((rawUpdate) => {
95
102
  // console.log("ref update", this.scopeID, accessedOrSetId, JSON.stringify(rawUpdate))
96
103
  if (!rawUpdate) return;
104
+ this.invalidate(accessedOrSetId);
97
105
  this.scheduleUpdate();
98
106
  });
99
107
 
@@ -103,6 +111,14 @@ export class SubscriptionScope<
103
111
  }
104
112
  }
105
113
 
114
+ invalidate(id: ID<CoValue>, fromChild?: ID<CoValue>) {
115
+ TRACE_INVALIDATIONS && console.log("invalidating", fromChild, "->", id, this.cachedValues[id]);
116
+ delete this.cachedValues[id];
117
+ for (const parent of this.parents[id] || []) {
118
+ this.invalidate(parent, id);
119
+ }
120
+ }
121
+
106
122
  unsubscribeAll() {
107
123
  for (const entry of this.entries.values()) {
108
124
  if (entry.state === "loaded") {
package/src/internal.ts CHANGED
@@ -13,4 +13,6 @@ export * from "./implementation/refs.js";
13
13
  export * from "./implementation/schema.js";
14
14
  export * from "./implementation/subscriptionScope.js";
15
15
 
16
- export * from "./coValues/extensions/imageDef.js";
16
+ export * from "./coValues/extensions/imageDef.js";
17
+
18
+ import "./implementation/devtoolsFormatters.js"