j-templates 8.0.15 → 8.0.16

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.
@@ -39,7 +39,7 @@ export interface IDiffTreeConstructor {
39
39
  * positionally in the same order, so each parameter can be typed at the call site instead of
40
40
  * cast out of a generic read.
41
41
  */
42
- export type DiffTreeProjectionFunc = (...values: any[]) => any;
42
+ export type DiffTreeProjectionFunc = (keys: string[], ...values: any[]) => any;
43
43
  /**
44
44
  * A projection's declaration: the dot-separated paths it reads (a plain tree path, an
45
45
  * entity's key, or another projection's `$projection_<id>` key for chaining) and the
@@ -211,27 +211,30 @@ function RunProjections(source, keyFunc, projections, memo) {
211
211
  for (let x = 0; x < projections.length; x++) {
212
212
  const { id, reads, projection } = projections[x];
213
213
  const values = [];
214
+ const keys = [];
214
215
  let allPathsExist = true;
215
216
  let y = 0;
216
217
  for (; allPathsExist && y < reads.length && !reads[y].endsWith("*"); y++) {
217
218
  const read = reads[y];
218
219
  const [value, found] = GetPathValue(source, read);
219
220
  allPathsExist = found;
220
- values[y] = (found && CreateSnapshot(source, keyFunc, value)) || value;
221
+ keys.push(read);
222
+ values.push((found && CreateSnapshot(source, keyFunc, value)) || value);
221
223
  }
222
224
  if (y < reads.length && reads[y].endsWith("*")) {
223
225
  const prefix = reads[y].slice(0, reads[y].length - 1);
224
- const keys = Object.keys(source).filter(key => key.startsWith(prefix));
225
- for (let z = 0; z < keys.length; z++) {
226
- const [value, found] = GetPathValue(source, keys[z]);
226
+ const matchedKeys = Object.keys(source).filter(key => key.startsWith(prefix));
227
+ for (let z = 0; z < matchedKeys.length; z++) {
228
+ const [value, found] = GetPathValue(source, matchedKeys[z]);
227
229
  allPathsExist = allPathsExist && found;
230
+ keys.push(matchedKeys[z]);
228
231
  values.push((found && CreateSnapshot(source, keyFunc, value)) || value);
229
232
  }
230
233
  }
231
234
  if (allPathsExist) {
232
235
  const priorValues = memo.get(id);
233
236
  if (!ArraysEqual(priorValues, values)) {
234
- const result = projection(...values);
237
+ const result = projection(keys, ...values);
235
238
  memo.set(id, values);
236
239
  // The same diff-and-apply UpdateSource uses for any other write, so a keyed entity
237
240
  // embedded in a projection's result is flattened to its own root like any other write,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "j-templates",
3
- "version": "8.0.15",
3
+ "version": "8.0.16",
4
4
  "description": "j-templates",
5
5
  "license": "MIT",
6
6
  "repository": "https://github.com/TypesInCode/jTemplates",