j-templates 8.0.2 → 8.0.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.
@@ -333,7 +333,7 @@ var ObservableNode;
333
333
  function Update(value, prop = OBJECT_SCOPE) {
334
334
  const wrapper = wrapperCache.get(value);
335
335
  if (wrapper) {
336
- const scope = wrapper[prop] ?? wrapper[OBJECT_SCOPE];
336
+ const scope = Array.isArray(wrapper) ? wrapper[OBJECT_SCOPE] : wrapper[prop] ?? wrapper[OBJECT_SCOPE];
337
337
  observableScope_1.ObservableScope.Update(scope);
338
338
  }
339
339
  }
@@ -399,6 +399,10 @@ var ObservableNode;
399
399
  }
400
400
  return;
401
401
  }
402
+ // Assign every change before emitting any, so the diff lands atomically. Emitting per
403
+ // assignment let synchronous readers see partial states, e.g. an array's new length
404
+ // before its new elements were written.
405
+ // const updates = new Map<any, Set<string | number>>();
402
406
  const pathTuples = [["", root]];
403
407
  for (let x = 0; x < diffResult.length; x++) {
404
408
  const { path, value } = diffResult[x];
@@ -420,7 +424,12 @@ var ObservableNode;
420
424
  const assignValue = pathTuples[y][1];
421
425
  assignValue[path[y]] = value;
422
426
  ObservableNode.Update(assignValue, path[y]);
427
+ /* let props = updates.get(assignValue);
428
+ if (props === undefined) updates.set(assignValue, (props = new Set()));
429
+ props.add(path[y]); */
423
430
  }
431
+ /* for (const [assignValue, props] of updates)
432
+ for (const prop of props) ObservableNode.Update(assignValue, prop as any); */
424
433
  }
425
434
  ObservableNode.ApplyDiff = ApplyDiff;
426
435
  /**
package/Utils/json.js CHANGED
@@ -171,11 +171,6 @@ function JsonDiffFactory() {
171
171
  return oldValue.length !== newValue.length;
172
172
  }
173
173
  let allChildrenChanged = true;
174
- if (newValue.length !== oldValue.length)
175
- resp.push({
176
- path: path.concat("length"),
177
- value: newValue.length,
178
- });
179
174
  if (newValue.length > 0 || oldValue.length > 0) {
180
175
  for (let y = 0; y < newValue.length; y++) {
181
176
  const arrayPath = path.concat(y);
@@ -187,6 +182,11 @@ function JsonDiffFactory() {
187
182
  }
188
183
  else
189
184
  allChildrenChanged = false;
185
+ if (newValue.length !== oldValue.length)
186
+ resp.push({
187
+ path: path.concat("length"),
188
+ value: newValue.length,
189
+ });
190
190
  return allChildrenChanged;
191
191
  }
192
192
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "j-templates",
3
- "version": "8.0.2",
3
+ "version": "8.0.4",
4
4
  "description": "j-templates",
5
5
  "license": "MIT",
6
6
  "repository": "https://github.com/TypesInCode/jTemplates",