j-templates 7.0.93 → 7.0.94
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/storeSync.js +1 -1
- package/Store/Tree/observableNode.d.ts +2 -1
- package/Store/Tree/observableNode.js +42 -8
- package/Store/Tree/observableScope.d.ts +2 -4
- package/Store/Tree/observableScope.js +4 -6
- package/Utils/decorators.js +5 -2
- package/Utils/json.d.ts +2 -2
- package/Utils/json.js +1 -2
- package/package.json +1 -1
- package/Utils/distinctArray.d.ts +0 -12
- package/Utils/distinctArray.js +0 -49
- /package/{Utils → _not_used}/array.d.ts +0 -0
- /package/{Utils → _not_used}/array.js +0 -0
- /package/{Utils → _not_used}/avlTree.d.ts +0 -0
- /package/{Utils → _not_used}/avlTree.js +0 -0
package/Store/Store/storeSync.js
CHANGED
|
@@ -49,10 +49,10 @@ class StoreSync extends store_1.Store {
|
|
|
49
49
|
* @throws Will throw an error if no key is provided for the data.
|
|
50
50
|
*/
|
|
51
51
|
Write(data, key) {
|
|
52
|
-
// data = JsonDeepClone(data);
|
|
53
52
|
key = key || this.keyFunc?.(data);
|
|
54
53
|
if (!key)
|
|
55
54
|
throw "No key provided for data";
|
|
55
|
+
data = observableNode_1.ObservableNode.Unwrap(data);
|
|
56
56
|
const diffResult = this.diff.DiffPath(key, data);
|
|
57
57
|
this.UpdateRootMap(diffResult);
|
|
58
58
|
}
|
|
@@ -8,6 +8,7 @@ export declare namespace ObservableNode {
|
|
|
8
8
|
* @returns The unwrapped raw value without proxy wrappers.
|
|
9
9
|
*/
|
|
10
10
|
function Unwrap<T>(value: T): T;
|
|
11
|
+
function Clone<T>(value: T): T;
|
|
11
12
|
/**
|
|
12
13
|
* Creates an observable node from a plain value.
|
|
13
14
|
* Wraps the value in a proxy that tracks changes and enables reactive updates.
|
|
@@ -22,7 +23,7 @@ export declare namespace ObservableNode {
|
|
|
22
23
|
* @param value The observable node to touch.
|
|
23
24
|
* @param prop Optional property name or index to touch a specific nested property.
|
|
24
25
|
*/
|
|
25
|
-
function
|
|
26
|
+
function Update(value: unknown, prop?: string | number | symbol): void;
|
|
26
27
|
function Apply(rootNode: any, update: any): void;
|
|
27
28
|
/**
|
|
28
29
|
* Applies a JSON diff result to an observable node, efficiently updating only changed properties.
|
|
@@ -42,11 +42,20 @@ function ownKeys(value) {
|
|
|
42
42
|
function ownKeysArray(value) {
|
|
43
43
|
return Object.keys(value[NODE_VALUE]);
|
|
44
44
|
}
|
|
45
|
+
function TouchValue(value, prop = OBJECT_SCOPE) {
|
|
46
|
+
const wrapper = wrapperCache.get(value);
|
|
47
|
+
if (wrapper) {
|
|
48
|
+
const scope = wrapper[prop] ?? wrapper[OBJECT_SCOPE];
|
|
49
|
+
observableScope_1.ObservableScope.Touch(scope);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
45
52
|
function UnwrapProxy(value, type = (0, json_2.JsonType)(value)) {
|
|
46
53
|
if (type === "value")
|
|
47
54
|
return value;
|
|
48
|
-
if (value[IS_NODE])
|
|
49
|
-
|
|
55
|
+
if (value[IS_NODE]) {
|
|
56
|
+
const nodeValue = value[NODE_VALUE];
|
|
57
|
+
return nodeValue;
|
|
58
|
+
}
|
|
50
59
|
switch (type) {
|
|
51
60
|
case "object": {
|
|
52
61
|
const keys = Object.keys(value);
|
|
@@ -62,6 +71,27 @@ function UnwrapProxy(value, type = (0, json_2.JsonType)(value)) {
|
|
|
62
71
|
}
|
|
63
72
|
return value;
|
|
64
73
|
}
|
|
74
|
+
function CloneProxy(value, type = (0, json_2.JsonType)(value)) {
|
|
75
|
+
if (type === "value")
|
|
76
|
+
return value;
|
|
77
|
+
if (value[IS_NODE]) {
|
|
78
|
+
return (0, json_1.JsonDeepClone)(value);
|
|
79
|
+
}
|
|
80
|
+
switch (type) {
|
|
81
|
+
case "object": {
|
|
82
|
+
const keys = Object.keys(value);
|
|
83
|
+
for (let x = 0; x < keys.length; x++)
|
|
84
|
+
value[keys[x]] = CloneProxy(value[keys[x]]);
|
|
85
|
+
break;
|
|
86
|
+
}
|
|
87
|
+
case "array": {
|
|
88
|
+
for (let x = 0; x < value.length; x++)
|
|
89
|
+
value[x] = CloneProxy(value[x]);
|
|
90
|
+
break;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
return value;
|
|
94
|
+
}
|
|
65
95
|
function CreateProxyFactory(alias) {
|
|
66
96
|
function ToJsonCopy(value) {
|
|
67
97
|
const type = (0, json_2.JsonType)(value);
|
|
@@ -146,7 +176,7 @@ function CreateProxyFactory(alias) {
|
|
|
146
176
|
case NODE_VALUE:
|
|
147
177
|
return object[NODE_VALUE];
|
|
148
178
|
default: {
|
|
149
|
-
const scope = object[OBJECT_SCOPE];
|
|
179
|
+
const scope = object[OBJECT_SCOPE];
|
|
150
180
|
const array = observableScope_1.ObservableScope.Value(scope);
|
|
151
181
|
const arrayValue = array[prop];
|
|
152
182
|
if (typeof prop === "symbol")
|
|
@@ -264,6 +294,10 @@ var ObservableNode;
|
|
|
264
294
|
return UnwrapProxy(value);
|
|
265
295
|
}
|
|
266
296
|
ObservableNode.Unwrap = Unwrap;
|
|
297
|
+
function Clone(value) {
|
|
298
|
+
return CloneProxy(value);
|
|
299
|
+
}
|
|
300
|
+
ObservableNode.Clone = Clone;
|
|
267
301
|
/**
|
|
268
302
|
* Creates an observable node from a plain value.
|
|
269
303
|
* Wraps the value in a proxy that tracks changes and enables reactive updates.
|
|
@@ -281,14 +315,14 @@ var ObservableNode;
|
|
|
281
315
|
* @param value The observable node to touch.
|
|
282
316
|
* @param prop Optional property name or index to touch a specific nested property.
|
|
283
317
|
*/
|
|
284
|
-
function
|
|
318
|
+
function Update(value, prop = OBJECT_SCOPE) {
|
|
285
319
|
const wrapper = wrapperCache.get(value);
|
|
286
320
|
if (wrapper) {
|
|
287
321
|
const scope = wrapper[prop] ?? wrapper[OBJECT_SCOPE];
|
|
288
322
|
observableScope_1.ObservableScope.Update(scope);
|
|
289
323
|
}
|
|
290
324
|
}
|
|
291
|
-
ObservableNode.
|
|
325
|
+
ObservableNode.Update = Update;
|
|
292
326
|
function Apply(rootNode, update) {
|
|
293
327
|
const root = rootNode[NODE_VALUE];
|
|
294
328
|
const diff = (0, json_1.JsonDiff)(update, root);
|
|
@@ -313,7 +347,7 @@ var ObservableNode;
|
|
|
313
347
|
switch (rootType) {
|
|
314
348
|
case "array": {
|
|
315
349
|
root.splice(0, root.length, ...rootPatch);
|
|
316
|
-
ObservableNode.
|
|
350
|
+
ObservableNode.Update(root);
|
|
317
351
|
break;
|
|
318
352
|
}
|
|
319
353
|
case "object": {
|
|
@@ -324,7 +358,7 @@ var ObservableNode;
|
|
|
324
358
|
delete root[keys[x]];
|
|
325
359
|
Object.assign(root, rootPatch);
|
|
326
360
|
for (let x = 0; x < keys.length; x++)
|
|
327
|
-
ObservableNode.
|
|
361
|
+
ObservableNode.Update(root, keys[x]);
|
|
328
362
|
break;
|
|
329
363
|
}
|
|
330
364
|
case "value":
|
|
@@ -352,7 +386,7 @@ var ObservableNode;
|
|
|
352
386
|
}
|
|
353
387
|
const assignValue = pathTuples[y][1];
|
|
354
388
|
assignValue[path[y]] = value;
|
|
355
|
-
ObservableNode.
|
|
389
|
+
ObservableNode.Update(assignValue, path[y]);
|
|
356
390
|
}
|
|
357
391
|
}
|
|
358
392
|
ObservableNode.ApplyDiff = ApplyDiff;
|
|
@@ -117,14 +117,12 @@ export declare namespace ObservableScope {
|
|
|
117
117
|
* Creates a new observable scope from a value function.
|
|
118
118
|
* @template T The type of value returned by the function.
|
|
119
119
|
* @param valueFunction Function that returns the scope's value. Can be async.
|
|
120
|
-
* @param greedy Whether updates should be batched via microtask queue. Defaults to false.
|
|
121
|
-
* @param force If true, always creates a dynamic scope even without dependencies. Defaults to false.
|
|
122
120
|
* @returns A new observable scope.
|
|
123
121
|
*/
|
|
124
122
|
function Create<T>(valueFunction: {
|
|
125
123
|
(): T | Promise<T>;
|
|
126
124
|
}): IObservableScope<T>;
|
|
127
|
-
function
|
|
125
|
+
function Gated<T>(valueFunction: {
|
|
128
126
|
(): T | Promise<T>;
|
|
129
127
|
}): IObservableScope<T>;
|
|
130
128
|
function Basic<T>(valueFunction: {
|
|
@@ -161,7 +159,7 @@ export declare namespace ObservableScope {
|
|
|
161
159
|
* @param scope The scope to watch for changes.
|
|
162
160
|
* @param callback Function to invoke when the scope's value changes.
|
|
163
161
|
*/
|
|
164
|
-
function Watch<T>(scope: IObservableScope<T>, callback: (scope: IObservableScope<T>) => void): void;
|
|
162
|
+
function Watch<T>(scope: IObservableScope<T> | IBasicObservableScope<T>, callback: (scope: IObservableScope<T>) => void): void;
|
|
165
163
|
/**
|
|
166
164
|
* Unsubscribes from changes on a dynamic scope.
|
|
167
165
|
* @template T The type of value stored in the scope.
|
|
@@ -284,7 +284,7 @@ function ExecuteScope(scope) {
|
|
|
284
284
|
function ExecuteFunction(callback, greedy) {
|
|
285
285
|
const async = (0, functions_1.IsAsync)(callback);
|
|
286
286
|
const state = WatchFunction(callback, null, null, null);
|
|
287
|
-
if (async || state.emitters !== null) {
|
|
287
|
+
if (greedy || async || state.emitters !== null) {
|
|
288
288
|
const scope = CreateDynamicScope(callback, greedy, async ? null : state.value);
|
|
289
289
|
scope.scopes = state.nextScopes;
|
|
290
290
|
scope.mappedScopes = state.nextMappedScopes;
|
|
@@ -539,18 +539,16 @@ var ObservableScope;
|
|
|
539
539
|
* Creates a new observable scope from a value function.
|
|
540
540
|
* @template T The type of value returned by the function.
|
|
541
541
|
* @param valueFunction Function that returns the scope's value. Can be async.
|
|
542
|
-
* @param greedy Whether updates should be batched via microtask queue. Defaults to false.
|
|
543
|
-
* @param force If true, always creates a dynamic scope even without dependencies. Defaults to false.
|
|
544
542
|
* @returns A new observable scope.
|
|
545
543
|
*/
|
|
546
544
|
function Create(valueFunction) {
|
|
547
545
|
return ExecuteFunction(valueFunction, false);
|
|
548
546
|
}
|
|
549
547
|
ObservableScope.Create = Create;
|
|
550
|
-
function
|
|
548
|
+
function Gated(valueFunction) {
|
|
551
549
|
return ExecuteFunction(valueFunction, true);
|
|
552
550
|
}
|
|
553
|
-
ObservableScope.
|
|
551
|
+
ObservableScope.Gated = Gated;
|
|
554
552
|
function Basic(valueFunction) {
|
|
555
553
|
return CreateBasicScope(valueFunction);
|
|
556
554
|
}
|
|
@@ -646,7 +644,7 @@ var ObservableScope;
|
|
|
646
644
|
if (!scope || scope.destroyed || scope.type === "static")
|
|
647
645
|
return;
|
|
648
646
|
if (scope.type === "basic") {
|
|
649
|
-
emitter_1.Emitter.Emit(scope.emitter,
|
|
647
|
+
emitter_1.Emitter.Emit(scope.emitter, scope);
|
|
650
648
|
return;
|
|
651
649
|
}
|
|
652
650
|
scope.setCallback();
|
package/Utils/decorators.js
CHANGED
|
@@ -134,7 +134,10 @@ function GetDestroyArrayForPrototype(prototype, create = true) {
|
|
|
134
134
|
return array;
|
|
135
135
|
}
|
|
136
136
|
function CreateComputedScope(getter, store, defaultValue) {
|
|
137
|
-
const getterScope = observableScope_1.ObservableScope.
|
|
137
|
+
const getterScope = observableScope_1.ObservableScope.Gated(function () {
|
|
138
|
+
const value = getter();
|
|
139
|
+
return observableNode_1.ObservableNode.Clone(value);
|
|
140
|
+
});
|
|
138
141
|
observableScope_1.ObservableScope.Watch(getterScope, (scope) => {
|
|
139
142
|
const data = observableScope_1.ObservableScope.Peek(scope);
|
|
140
143
|
store.Write(data, "root");
|
|
@@ -814,7 +817,7 @@ function WatchDecorator(target, propertyKey, descriptor, scopeFunction) {
|
|
|
814
817
|
function scopeFunctionWrapper() {
|
|
815
818
|
return scopeFunction(instance);
|
|
816
819
|
}
|
|
817
|
-
const scope = observableScope_1.ObservableScope.
|
|
820
|
+
const scope = observableScope_1.ObservableScope.Gated(scopeFunctionWrapper);
|
|
818
821
|
const propertyMap = GetScopeMapForInstance(this);
|
|
819
822
|
propertyMap[propertyKey] = [scope, undefined];
|
|
820
823
|
observableScope_1.ObservableScope.Watch(scope, function (scope) {
|
package/Utils/json.d.ts
CHANGED
|
@@ -16,7 +16,7 @@ export type JsonDiffFactoryResult = ReturnType<typeof JsonDiffFactory>;
|
|
|
16
16
|
export declare function JsonDiffFactory(): {
|
|
17
17
|
JsonDiff: <T>(newValue: T, oldValue: T, rootPath?: string, initResult?: JsonDiffResult<T>) => JsonDiffResult<T>;
|
|
18
18
|
JsonType: (value: any) => "object" | "value" | "array";
|
|
19
|
-
JsonDeepClone: <T>(value: T) => T;
|
|
19
|
+
JsonDeepClone: <T>(value: T, type?: string) => T;
|
|
20
20
|
JsonMerge: (source: unknown, patch: unknown) => unknown;
|
|
21
21
|
};
|
|
22
|
-
export declare const JsonDiff: <T>(newValue: T, oldValue: T, rootPath?: string, initResult?: JsonDiffResult<T>) => JsonDiffResult<T>, JsonType: (value: any) => "object" | "value" | "array", JsonDeepClone: <T>(value: T) => T, JsonMerge: (source: unknown, patch: unknown) => unknown;
|
|
22
|
+
export declare const JsonDiff: <T>(newValue: T, oldValue: T, rootPath?: string, initResult?: JsonDiffResult<T>) => JsonDiffResult<T>, JsonType: (value: any) => "object" | "value" | "array", JsonDeepClone: <T>(value: T, type?: string) => T, JsonMerge: (source: unknown, patch: unknown) => unknown;
|
package/Utils/json.js
CHANGED
|
@@ -84,8 +84,7 @@ function JsonDiffFactory() {
|
|
|
84
84
|
* @param value - The value to clone
|
|
85
85
|
* @returns A deep clone of the value
|
|
86
86
|
*/
|
|
87
|
-
function JsonDeepClone(value) {
|
|
88
|
-
const type = JsonType(value);
|
|
87
|
+
function JsonDeepClone(value, type = JsonType(value)) {
|
|
89
88
|
switch (type) {
|
|
90
89
|
case "array": {
|
|
91
90
|
const typed = value;
|
package/package.json
CHANGED
package/Utils/distinctArray.d.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
export type DistinctArray<T> = {
|
|
2
|
-
id: (value: T) => unknown;
|
|
3
|
-
distinct: Set<unknown> | null;
|
|
4
|
-
array: T[];
|
|
5
|
-
};
|
|
6
|
-
export declare namespace DistinctArray {
|
|
7
|
-
function Create<T>(id?: (value: T) => unknown): DistinctArray<T>;
|
|
8
|
-
function Push<T>(distinctArr: DistinctArray<T>, value: T): void;
|
|
9
|
-
function Get<T>({ array }: DistinctArray<T>): T[];
|
|
10
|
-
function Size<T>(distinct: DistinctArray<T>): number;
|
|
11
|
-
function Clear<T>(distinct: DistinctArray<T>): void;
|
|
12
|
-
}
|
package/Utils/distinctArray.js
DELETED
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.DistinctArray = void 0;
|
|
4
|
-
var DistinctArray;
|
|
5
|
-
(function (DistinctArray) {
|
|
6
|
-
function Create(id = (val) => val) {
|
|
7
|
-
return {
|
|
8
|
-
id,
|
|
9
|
-
distinct: null,
|
|
10
|
-
array: [],
|
|
11
|
-
};
|
|
12
|
-
}
|
|
13
|
-
DistinctArray.Create = Create;
|
|
14
|
-
function Push(distinctArr, value) {
|
|
15
|
-
switch (distinctArr.array.length) {
|
|
16
|
-
case 0:
|
|
17
|
-
distinctArr.array.push(value);
|
|
18
|
-
break;
|
|
19
|
-
case 1: {
|
|
20
|
-
if (distinctArr.distinct === null) {
|
|
21
|
-
distinctArr.distinct = new Set([
|
|
22
|
-
distinctArr.id(distinctArr.array[0]),
|
|
23
|
-
]);
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
default: {
|
|
27
|
-
const vId = distinctArr.id(value);
|
|
28
|
-
if (!distinctArr.distinct.has(vId)) {
|
|
29
|
-
distinctArr.distinct.add(vId);
|
|
30
|
-
distinctArr.array.push(value);
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
DistinctArray.Push = Push;
|
|
36
|
-
function Get({ array }) {
|
|
37
|
-
return array;
|
|
38
|
-
}
|
|
39
|
-
DistinctArray.Get = Get;
|
|
40
|
-
function Size(distinct) {
|
|
41
|
-
return distinct.distinct.size;
|
|
42
|
-
}
|
|
43
|
-
DistinctArray.Size = Size;
|
|
44
|
-
function Clear(distinct) {
|
|
45
|
-
distinct.array = [];
|
|
46
|
-
distinct.distinct?.clear();
|
|
47
|
-
}
|
|
48
|
-
DistinctArray.Clear = Clear;
|
|
49
|
-
})(DistinctArray || (exports.DistinctArray = DistinctArray = {}));
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|