@player-ui/player 0.7.4-next.2 → 0.7.4-next.4

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/package.json CHANGED
@@ -1,14 +1,14 @@
1
1
  {
2
2
  "name": "@player-ui/player",
3
- "version": "0.7.4-next.2",
3
+ "version": "0.7.4-next.4",
4
4
  "private": false,
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org"
7
7
  },
8
8
  "peerDependencies": {},
9
9
  "dependencies": {
10
- "@player-ui/partial-match-registry": "0.7.4-next.2",
11
- "@player-ui/types": "0.7.4-next.2",
10
+ "@player-ui/partial-match-registry": "0.7.4-next.4",
11
+ "@player-ui/types": "0.7.4-next.4",
12
12
  "dequal": "^2.0.2",
13
13
  "p-defer": "^3.0.0",
14
14
  "queue-microtask": "^1.2.3",
@@ -1,5 +1,6 @@
1
1
  import type { Validation } from '@player-ui/types';
2
2
  import type { ViewPlugin, Resolver, Node, ViewInstance } from '../../view';
3
+ import { NodeType } from '../../view';
3
4
  import type {
4
5
  BindingInstance,
5
6
  BindingLike,
@@ -67,25 +68,15 @@ export class ValidationBindingTrackerViewPlugin
67
68
 
68
69
  let lastViewUpdateChangeSet: Set<BindingInstance> | undefined;
69
70
 
70
- const nodeTree = new Map<Node.Node, Set<Node.Node>>();
71
-
72
71
  /** Map of node to all bindings in children */
73
- let lastComputedBindingTree = new Map<Node.Node, Set<BindingInstance>>();
72
+ const lastComputedBindingTree = new Map<Node.Node, Set<BindingInstance>>();
74
73
  let currentBindingTree = new Map<Node.Node, Set<BindingInstance>>();
75
74
 
76
75
  /** Map of registered section nodes to bindings */
77
76
  const lastSectionBindingTree = new Map<Node.Node, Set<BindingInstance>>();
78
77
 
79
- /** Add the given child to the parent's tree. Create the parent entry if none exists */
80
- function addToTree(child: Node.Node, parent: Node.Node) {
81
- if (nodeTree.has(parent)) {
82
- nodeTree.get(parent)?.add(child);
83
-
84
- return;
85
- }
86
-
87
- nodeTree.set(parent, new Set([child]));
88
- }
78
+ /** Map of resolved nodes to their original nodes. */
79
+ const resolvedNodeMap: Map<Node.Node, Node.Node> = new Map();
89
80
 
90
81
  resolver.hooks.beforeUpdate.tap(CONTEXT, (changes) => {
91
82
  lastViewUpdateChangeSet = changes;
@@ -214,46 +205,66 @@ export class ValidationBindingTrackerViewPlugin
214
205
  };
215
206
  });
216
207
 
217
- resolver.hooks.afterNodeUpdate.tap(CONTEXT, (node, parent, update) => {
218
- if (parent) {
219
- addToTree(node, parent);
220
- }
208
+ resolver.hooks.afterNodeUpdate.tap(
209
+ CONTEXT,
210
+ (originalNode, parent, update) => {
211
+ // Compute the new tree for this node
212
+ // If it's not-updated, use the last known value
213
+
214
+ const { updated, node: resolvedNode } = update;
215
+ resolvedNodeMap.set(resolvedNode, originalNode);
216
+
217
+ if (updated) {
218
+ const newlyComputed = new Set(tracked.get(originalNode));
219
+ if (resolvedNode.type === NodeType.MultiNode) {
220
+ resolvedNode.values.forEach((value) =>
221
+ currentBindingTree
222
+ .get(value)
223
+ ?.forEach((b) => newlyComputed.add(b))
224
+ );
225
+ }
221
226
 
222
- // Compute the new tree for this node
223
- // If it's not-updated, use the last known value
224
-
225
- if (update.updated) {
226
- const newlyComputed = new Set(tracked.get(node));
227
- nodeTree.get(node)?.forEach((child) => {
228
- currentBindingTree.get(child)?.forEach((b) => newlyComputed.add(b));
229
- });
230
- currentBindingTree.set(node, newlyComputed);
231
- } else {
232
- currentBindingTree.set(
233
- node,
234
- lastComputedBindingTree.get(node) ?? new Set()
235
- );
236
- }
227
+ if ('children' in resolvedNode && resolvedNode.children) {
228
+ resolvedNode.children.forEach((child) => {
229
+ currentBindingTree
230
+ .get(child.value)
231
+ ?.forEach((b) => newlyComputed.add(b));
232
+ });
233
+ }
237
234
 
238
- if (node === resolver.root) {
239
- this.trackedBindings = new Set(currentBindingTree.get(node));
240
- lastComputedBindingTree = currentBindingTree;
235
+ currentBindingTree.set(resolvedNode, newlyComputed);
236
+ } else {
237
+ currentBindingTree.set(
238
+ resolvedNode,
239
+ lastComputedBindingTree.get(originalNode) ?? new Set()
240
+ );
241
+ }
241
242
 
242
- lastSectionBindingTree.clear();
243
- sections.forEach((nodeSet, sectionNode) => {
244
- const temp = new Set<BindingInstance>();
245
- nodeSet.forEach((n) => {
246
- tracked.get(n)?.forEach(temp.add, temp);
243
+ if (originalNode === resolver.root) {
244
+ this.trackedBindings = new Set(currentBindingTree.get(resolvedNode));
245
+ lastComputedBindingTree.clear();
246
+ currentBindingTree.forEach((value, key) => {
247
+ const node = resolvedNodeMap.get(key);
248
+ if (node) {
249
+ lastComputedBindingTree.set(node, value);
250
+ }
247
251
  });
248
- lastSectionBindingTree.set(sectionNode, temp);
249
- });
250
252
 
251
- nodeTree.clear();
252
- tracked.clear();
253
- sections.clear();
254
- currentBindingTree = new Map();
253
+ lastSectionBindingTree.clear();
254
+ sections.forEach((nodeSet, sectionNode) => {
255
+ const temp = new Set<BindingInstance>();
256
+ nodeSet.forEach((n) => {
257
+ tracked.get(n)?.forEach(temp.add, temp);
258
+ });
259
+ lastSectionBindingTree.set(sectionNode, temp);
260
+ });
261
+
262
+ tracked.clear();
263
+ sections.clear();
264
+ currentBindingTree = new Map();
265
+ }
255
266
  }
256
- });
267
+ );
257
268
  }
258
269
 
259
270
  apply(view: ViewInstance) {
package/src/player.ts CHANGED
@@ -30,8 +30,8 @@ import type {
30
30
  import { NOT_STARTED_STATE } from './types';
31
31
 
32
32
  // Variables injected at build time
33
- const PLAYER_VERSION = '0.7.4-next.2';
34
- const COMMIT = '472fbef4a5f0fcbd23179a4092e77bb6df0d1a27';
33
+ const PLAYER_VERSION = '0.7.4-next.4';
34
+ const COMMIT = '498d9be0ba0bbbe6839b7d227d3900eabbd24cdd';
35
35
 
36
36
  export interface PlayerPlugin {
37
37
  /**