j-templates 8.0.7 → 8.0.8
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/Store/Store/store.d.ts +2 -1
- package/Store/Store/store.js +4 -2
- package/Store/Store/storeAsync.d.ts +1 -1
- package/Store/Store/storeAsync.js +22 -4
- package/Store/Store/storeSync.d.ts +1 -1
- package/Store/Store/storeSync.js +7 -3
- package/Store/Tree/observableNode.d.ts +1 -1
- package/Store/Tree/observableNode.js +4 -3
- package/package.json +1 -1
package/Store/Store/store.d.ts
CHANGED
|
@@ -8,6 +8,7 @@ import { JsonDiffResult } from "../../Utils/json";
|
|
|
8
8
|
*/
|
|
9
9
|
export declare abstract class Store {
|
|
10
10
|
protected keyFunc?: (value: any) => string | undefined;
|
|
11
|
+
private cloneData;
|
|
11
12
|
private rootMap;
|
|
12
13
|
private createNode;
|
|
13
14
|
/**
|
|
@@ -15,7 +16,7 @@ export declare abstract class Store {
|
|
|
15
16
|
* @param keyFunc Optional function to generate a key for a given data value.
|
|
16
17
|
* When provided, enables alias functionality where values can reference other root objects.
|
|
17
18
|
*/
|
|
18
|
-
constructor(keyFunc?: (value: any) => string | undefined);
|
|
19
|
+
constructor(keyFunc?: (value: any) => string | undefined, cloneData?: boolean);
|
|
19
20
|
/**
|
|
20
21
|
* Retrieves a value from the store by id.
|
|
21
22
|
* @template O - The type of the value to retrieve
|
package/Store/Store/store.js
CHANGED
|
@@ -16,8 +16,9 @@ class Store {
|
|
|
16
16
|
* @param keyFunc Optional function to generate a key for a given data value.
|
|
17
17
|
* When provided, enables alias functionality where values can reference other root objects.
|
|
18
18
|
*/
|
|
19
|
-
constructor(keyFunc) {
|
|
19
|
+
constructor(keyFunc, cloneData = true) {
|
|
20
20
|
this.keyFunc = keyFunc;
|
|
21
|
+
this.cloneData = cloneData;
|
|
21
22
|
this.rootMap = new Map();
|
|
22
23
|
const aliasFunc = keyFunc &&
|
|
23
24
|
((value, reactive = true) => {
|
|
@@ -72,7 +73,8 @@ class Store {
|
|
|
72
73
|
if (rootObject === undefined) {
|
|
73
74
|
if (results.length > 1 || results[0].path.length > 1)
|
|
74
75
|
throw `Unable to initialize root path ${rootPath} with ${results.length} results and initial path ${results[0].path}`;
|
|
75
|
-
const
|
|
76
|
+
const rootData = this.cloneData ? (0, json_1.JsonDeepClone)(results[0].value) : results[0].value;
|
|
77
|
+
const newRootObject = this.createNode({ [rootPath]: rootData });
|
|
76
78
|
this.rootMap.set(rootPath, newRootObject);
|
|
77
79
|
return;
|
|
78
80
|
}
|
|
@@ -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.
|
|
@@ -43,7 +43,7 @@ class StoreAsync extends store_1.Store {
|
|
|
43
43
|
* @param keyFunc Optional function to generate a key for a given data value.
|
|
44
44
|
*/
|
|
45
45
|
constructor(keyFunc) {
|
|
46
|
-
super(keyFunc);
|
|
46
|
+
super(keyFunc, false);
|
|
47
47
|
/**
|
|
48
48
|
* The async queue instance used to manage asynchronous operations in a non-blocking manner.
|
|
49
49
|
* @private
|
|
@@ -123,11 +123,29 @@ class StoreAsync extends store_1.Store {
|
|
|
123
123
|
async Splice(key, start, deleteCount, ...items) {
|
|
124
124
|
return await this.queue.Next(async () => {
|
|
125
125
|
const arr = this.Get(key);
|
|
126
|
-
const
|
|
127
|
-
const spliceResult =
|
|
128
|
-
const
|
|
126
|
+
const arrNodes = arr.slice(start); // Array starting from the splice start index
|
|
127
|
+
const spliceResult = arrNodes.splice(0, deleteCount ?? arrNodes.length, ...items);
|
|
128
|
+
const diffBatch = new Array(arrNodes.length + 1);
|
|
129
|
+
for (let x = 0; x < arrNodes.length; x++)
|
|
130
|
+
diffBatch[x] = { path: `${key}.${x + start}`, value: arrNodes[x]?.toJSON?.() ?? arrNodes[x] };
|
|
131
|
+
diffBatch[diffBatch.length - 1] = { path: `${key}.length`, value: start + arrNodes.length };
|
|
132
|
+
const diffResult = await this.diff.DiffBatch(diffBatch);
|
|
129
133
|
this.UpdateRootMap(diffResult);
|
|
130
134
|
return spliceResult;
|
|
135
|
+
/* const arr = this.Get(key) as any[];
|
|
136
|
+
const arrNodes = arr.slice(start); // Array starting from the splice start index
|
|
137
|
+
const spliceResult = arrNodes.splice(0, deleteCount, ...items);
|
|
138
|
+
|
|
139
|
+
const diffBatch: { path: string, value: any }[] = new Array(arrNodes.length + 1);
|
|
140
|
+
for (let x = 0; x < arrNodes.length; x++)
|
|
141
|
+
diffBatch[x] = { path: `${key}.${x + start}`, value: arrNodes[x]?.toJSON?.() };
|
|
142
|
+
|
|
143
|
+
diffBatch[diffBatch.length - 1] = { path: `${key}.length`, value: arrNodes.length + start + items.length };
|
|
144
|
+
|
|
145
|
+
const diffResult = await this.diff.DiffBatch(diffBatch);
|
|
146
|
+
this.UpdateRootMap(diffResult);
|
|
147
|
+
|
|
148
|
+
return spliceResult; */
|
|
131
149
|
});
|
|
132
150
|
}
|
|
133
151
|
/**
|
|
@@ -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
|
}
|
package/Store/Store/storeSync.js
CHANGED
|
@@ -98,9 +98,13 @@ class StoreSync extends store_1.Store {
|
|
|
98
98
|
*/
|
|
99
99
|
Splice(key, start, deleteCount, ...items) {
|
|
100
100
|
const arr = this.Get(key);
|
|
101
|
-
const
|
|
102
|
-
const spliceResult =
|
|
103
|
-
const
|
|
101
|
+
const arrNodes = arr.slice(start); // Array starting from the splice start index
|
|
102
|
+
const spliceResult = arrNodes.splice(0, deleteCount ?? arrNodes.length, ...items);
|
|
103
|
+
const diffBatch = new Array(arrNodes.length + 1);
|
|
104
|
+
for (let x = 0; x < arrNodes.length; x++)
|
|
105
|
+
diffBatch[x] = { path: `${key}.${x + start}`, value: arrNodes[x]?.toJSON?.() ?? arrNodes[x] };
|
|
106
|
+
diffBatch[diffBatch.length - 1] = { path: `${key}.length`, value: start + arrNodes.length };
|
|
107
|
+
const diffResult = this.diff.DiffBatch(diffBatch);
|
|
104
108
|
this.UpdateRootMap(diffResult);
|
|
105
109
|
return spliceResult;
|
|
106
110
|
}
|
|
@@ -74,7 +74,7 @@ export declare namespace ObservableNode {
|
|
|
74
74
|
* @param rootNode The observable node to apply the diff to.
|
|
75
75
|
* @param diffResult The diff result from JsonDiff containing path-value pairs of changes.
|
|
76
76
|
*/
|
|
77
|
-
function ApplyDiff(rootNode: any, diffResult: JsonDiffResult): void;
|
|
77
|
+
function ApplyDiff(rootNode: any, diffResult: JsonDiffResult, cloneData?: boolean): void;
|
|
78
78
|
/**
|
|
79
79
|
* Creates a factory function for making values observable with optional aliasing.
|
|
80
80
|
* The alias function transforms values before creating the observable proxy,
|
|
@@ -415,11 +415,11 @@ var ObservableNode;
|
|
|
415
415
|
* @param rootNode The observable node to apply the diff to.
|
|
416
416
|
* @param diffResult The diff result from JsonDiff containing path-value pairs of changes.
|
|
417
417
|
*/
|
|
418
|
-
function ApplyDiff(rootNode, diffResult) {
|
|
418
|
+
function ApplyDiff(rootNode, diffResult, cloneData = true) {
|
|
419
419
|
const root = rootNode[NODE_VALUE];
|
|
420
420
|
if (diffResult.length === 1 && diffResult[0].path.length === 0) {
|
|
421
421
|
// Replacing rootNode
|
|
422
|
-
const rootPatch = (0, json_1.JsonDeepClone)(diffResult[0].value);
|
|
422
|
+
const rootPatch = cloneData ? (0, json_1.JsonDeepClone)(diffResult[0].value) : diffResult[0].value;
|
|
423
423
|
const rootType = (0, json_2.JsonType)(root);
|
|
424
424
|
const rootPatchType = (0, json_2.JsonType)(rootPatch);
|
|
425
425
|
if (rootType !== rootPatchType)
|
|
@@ -465,7 +465,8 @@ var ObservableNode;
|
|
|
465
465
|
}
|
|
466
466
|
}
|
|
467
467
|
const assignValue = pathTuples[y][1];
|
|
468
|
-
|
|
468
|
+
const assignData = cloneData ? (0, json_1.JsonDeepClone)(value) : value;
|
|
469
|
+
ObservableNode.Assign(assignValue, path[y], assignData);
|
|
469
470
|
}
|
|
470
471
|
}
|
|
471
472
|
ObservableNode.ApplyDiff = ApplyDiff;
|