j-templates 8.0.6 → 8.0.7

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.
@@ -20,7 +20,7 @@ class Store {
20
20
  this.keyFunc = keyFunc;
21
21
  this.rootMap = new Map();
22
22
  const aliasFunc = keyFunc &&
23
- ((value) => {
23
+ ((value, reactive = true) => {
24
24
  const key = keyFunc(value);
25
25
  if (key === undefined)
26
26
  return undefined;
@@ -28,7 +28,7 @@ class Store {
28
28
  if (rootObject === undefined)
29
29
  throw `No root object found for key: ${key}`;
30
30
  const rootValue = observableNode_1.ObservableNode.Unwrap(rootObject); // rootObject[GET_OBSERVABLE_VALUE];
31
- observableNode_1.ObservableNode.Touch(rootValue, key);
31
+ reactive && observableNode_1.ObservableNode.Touch(rootValue, key);
32
32
  const alias = rootValue[key];
33
33
  return alias;
34
34
  });
@@ -84,7 +84,7 @@ export declare class StoreAsync extends Store {
84
84
  * @param items Optional elements to insert into the array.
85
85
  * @returns The array of deleted elements.
86
86
  */
87
- Splice(key: string, start: number, deleteCount?: number, ...items: unknown[]): Promise<any[]>;
87
+ Splice(key: string, start: number, deleteCount?: number, ...items: unknown[]): Promise<any>;
88
88
  /**
89
89
  * Destroys the StoreAsync instance, stopping the async queue and cleaning up the diff instance.
90
90
  * This method should be called when the instance is no longer needed to free up resources.
@@ -4,7 +4,6 @@ exports.StoreAsync = void 0;
4
4
  const asyncQueue_1 = require("../../Utils/asyncQueue");
5
5
  const json_1 = require("../../Utils/json");
6
6
  const diffAsync_1 = require("../Diff/diffAsync");
7
- const observableNode_1 = require("../Tree/observableNode");
8
7
  const store_1 = require("./store");
9
8
  /**
10
9
  * StoreAsync class extends the base Store class to provide asynchronous data management operations.
@@ -124,10 +123,9 @@ class StoreAsync extends store_1.Store {
124
123
  async Splice(key, start, deleteCount, ...items) {
125
124
  return await this.queue.Next(async () => {
126
125
  const arr = this.Get(key);
127
- const arrValue = observableNode_1.ObservableNode.Unwrap(arr); // (arr as any)[GET_OBSERVABLE_VALUE] as any[];
128
- const arrCopy = arrValue.slice();
129
- const spliceResult = (0, json_1.JsonDeepClone)(arrCopy.splice(start, deleteCount, ...items));
130
- const diffResult = await this.diff.DiffPath(key, arrCopy);
126
+ const arrValue = arr.toJSON();
127
+ const spliceResult = arrValue.splice(start, deleteCount, ...items);
128
+ const diffResult = await this.diff.DiffPath(key, arrValue);
131
129
  this.UpdateRootMap(diffResult);
132
130
  return spliceResult;
133
131
  });
@@ -67,5 +67,5 @@ export declare class StoreSync extends Store {
67
67
  * @param items Optional elements to insert into the array.
68
68
  * @returns The array of deleted elements.
69
69
  */
70
- Splice(key: string, start: number, deleteCount?: number, ...items: unknown[]): any[];
70
+ Splice(key: string, start: number, deleteCount?: number, ...items: unknown[]): any;
71
71
  }
@@ -98,10 +98,9 @@ class StoreSync extends store_1.Store {
98
98
  */
99
99
  Splice(key, start, deleteCount, ...items) {
100
100
  const arr = this.Get(key);
101
- const arrValue = observableNode_1.ObservableNode.Unwrap(arr); // (arr as any)[GET_OBSERVABLE_VALUE] as any[];
102
- const arrCopy = arrValue.slice();
103
- const spliceResult = (0, json_1.JsonDeepClone)(arrCopy.splice(start, deleteCount, ...items));
104
- const diffResult = this.diff.DiffPath(key, arrCopy);
101
+ const arrValue = arr.toJSON();
102
+ const spliceResult = arrValue.splice(start, deleteCount, ...items);
103
+ const diffResult = this.diff.DiffPath(key, arrValue);
105
104
  this.UpdateRootMap(diffResult);
106
105
  return spliceResult;
107
106
  }
@@ -82,5 +82,5 @@ export declare namespace ObservableNode {
82
82
  * @param alias Optional function to transform values before making them observable.
83
83
  * @returns A function that creates observable nodes from plain values.
84
84
  */
85
- function CreateFactory(alias?: (value: any) => any | undefined): <T>(value: T) => T;
85
+ function CreateFactory(alias?: (value: any, reactive?: boolean) => any | undefined): <T>(value: T) => T;
86
86
  }
@@ -99,13 +99,13 @@ function CreateProxyFactory(alias) {
99
99
  switch (type) {
100
100
  case "array": {
101
101
  const typedValue = value;
102
- const proxy = CreateProxy(typedValue);
103
- return proxy.map(ToJsonCopy);
102
+ const arrayValue = alias(typedValue, false) ?? typedValue;
103
+ return arrayValue.map(ToJsonCopy);
104
104
  }
105
105
  case "object": {
106
106
  const typedValue = alias(value) ?? value;
107
- const proxy = CreateProxy(typedValue);
108
- const keys = Object.keys(proxy);
107
+ const objectValue = alias(typedValue, false) ?? typedValue;
108
+ const keys = Object.keys(objectValue);
109
109
  const copy = {};
110
110
  for (let x = 0; x < keys.length; x++)
111
111
  copy[keys[x]] = ToJsonCopy(typedValue[keys[x]]);
@@ -116,7 +116,7 @@ function CreateProxyFactory(alias) {
116
116
  }
117
117
  }
118
118
  function ToJsonDefault(value) {
119
- return value;
119
+ return (0, json_1.JsonDeepClone)(value);
120
120
  }
121
121
  const ToJson = alias !== undefined ? ToJsonCopy : ToJsonDefault;
122
122
  const readOnly = alias !== undefined;
@@ -465,8 +465,6 @@ var ObservableNode;
465
465
  }
466
466
  }
467
467
  const assignValue = pathTuples[y][1];
468
- // assignValue[path[y]] = JsonDeepClone(value);
469
- // ObservableNode.Update(assignValue, path[y]);
470
468
  ObservableNode.Assign(assignValue, path[y], (0, json_1.JsonDeepClone)(value));
471
469
  }
472
470
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "j-templates",
3
- "version": "8.0.6",
3
+ "version": "8.0.7",
4
4
  "description": "j-templates",
5
5
  "license": "MIT",
6
6
  "repository": "https://github.com/TypesInCode/jTemplates",