j-templates 5.0.53 → 6.0.0

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.
Files changed (45) hide show
  1. package/Node/component.d.ts +0 -2
  2. package/Node/component.js +2 -8
  3. package/Store/Diff/diffAsync.d.ts +9 -8
  4. package/Store/Diff/diffAsync.js +1 -15
  5. package/Store/Diff/diffSync.d.ts +4 -6
  6. package/Store/Diff/diffSync.js +4 -10
  7. package/Store/Diff/diffTree.d.ts +4 -10
  8. package/Store/Diff/diffTree.js +96 -189
  9. package/Store/Diff/diffWorker.js +5 -4
  10. package/Store/Store/store.d.ts +0 -14
  11. package/Store/Store/store.js +0 -31
  12. package/Store/Store/storeAsync.d.ts +0 -20
  13. package/Store/Store/storeAsync.js +0 -49
  14. package/Store/Store/storeAsyncWriter.d.ts +0 -15
  15. package/Store/Store/storeAsyncWriter.js +0 -52
  16. package/Store/Store/storeSync.d.ts +0 -15
  17. package/Store/Store/storeSync.js +0 -33
  18. package/Store/Store/storeSyncWriter.d.ts +0 -12
  19. package/Store/Store/storeSyncWriter.js +0 -41
  20. package/Store/Store/storeWriter.d.ts +0 -9
  21. package/Store/Store/storeWriter.js +0 -30
  22. package/Store/Tree/observableComputed.d.ts +0 -4
  23. package/Store/Tree/observableComputed.js +0 -45
  24. package/Store/Tree/observableNode.d.ts +2 -0
  25. package/Store/Tree/observableNode.js +186 -131
  26. package/Store/Tree/observableScope.js +16 -12
  27. package/Store/index.d.ts +0 -4
  28. package/Store/index.js +1 -9
  29. package/Utils/array.d.ts +1 -0
  30. package/Utils/array.js +15 -0
  31. package/Utils/decorators.d.ts +8 -8
  32. package/Utils/decorators.js +77 -165
  33. package/Utils/emitter.d.ts +2 -1
  34. package/Utils/emitter.js +20 -11
  35. package/Utils/json.d.ts +8 -3
  36. package/Utils/json.js +116 -96
  37. package/Utils/jsonDeepClone.d.ts +1 -0
  38. package/Utils/jsonDeepClone.js +20 -0
  39. package/Utils/router.d.ts +0 -23
  40. package/Utils/router.js +0 -116
  41. package/jTemplates.js +1 -1
  42. package/jTemplates.js.map +1 -1
  43. package/package.json +1 -1
  44. package/web.export.d.ts +1 -1
  45. package/web.export.js +1 -4
@@ -6,10 +6,8 @@ export declare class Component<D = void, T = void, E = void> {
6
6
  private componentEvents;
7
7
  private scope;
8
8
  private templates;
9
- private decoratorMap;
10
9
  get Injector(): import("../Utils/injector").Injector;
11
10
  get Destroyed(): boolean;
12
- get DecoratorMap(): Map<string, any>;
13
11
  protected get Scope(): ObservableScope<D>;
14
12
  protected get Data(): D;
15
13
  protected get NodeRef(): INodeRefBase;
package/Node/component.js CHANGED
@@ -10,16 +10,12 @@ class Component {
10
10
  componentEvents;
11
11
  scope;
12
12
  templates;
13
- decoratorMap;
14
13
  get Injector() {
15
14
  return this.nodeRef.injector;
16
15
  }
17
16
  get Destroyed() {
18
17
  return this.nodeRef.destroyed;
19
18
  }
20
- get DecoratorMap() {
21
- return this.decoratorMap;
22
- }
23
19
  get Scope() {
24
20
  return this.scope;
25
21
  }
@@ -37,13 +33,11 @@ class Component {
37
33
  this.componentEvents = componentEvents;
38
34
  this.scope = new observableScope_1.ObservableScope(data);
39
35
  this.templates = templates || {};
40
- this.decoratorMap = new Map();
41
36
  }
42
37
  Template() {
43
38
  return [];
44
39
  }
45
- Bound() {
46
- }
40
+ Bound() { }
47
41
  Fire(event, data) {
48
42
  var eventCallback = this.componentEvents && this.componentEvents[event];
49
43
  eventCallback && eventCallback(data);
@@ -64,7 +58,7 @@ exports.Component = Component;
64
58
  class WebComponent extends HTMLElement {
65
59
  constructor() {
66
60
  super();
67
- const shadowRoot = this.attachShadow({ mode: 'open' });
61
+ const shadowRoot = this.attachShadow({ mode: "open" });
68
62
  const node = componentFunction({});
69
63
  Attach(shadowRoot, node);
70
64
  }
@@ -1,17 +1,18 @@
1
- import { IDiffResponse } from "./diffTree";
2
- export declare class DiffAsync {
1
+ import { IDiffTree } from "./diffTree";
2
+ import { JsonDiffResult } from "../../Utils/json";
3
+ type IDiffTreeAsync = {
4
+ [property in keyof IDiffTree]: (...args: Parameters<IDiffTree[property]>) => Promise<ReturnType<IDiffTree[property]>>;
5
+ };
6
+ export declare class DiffAsync implements IDiffTreeAsync {
3
7
  private workerQueue;
4
8
  constructor(keyFunc?: {
5
9
  (val: any): string;
6
10
  });
7
- static GetKeyRef(key: string): string;
8
- static ReadKeyRef(ref: string): string;
9
- DiffPath(path: string, value: any): Promise<IDiffResponse>;
11
+ DiffPath(path: string, value: any): Promise<JsonDiffResult>;
10
12
  DiffBatch(data: Array<{
11
13
  path: string;
12
14
  value: any;
13
- }>): Promise<IDiffResponse>;
14
- UpdatePath(path: string, value: any): Promise<void>;
15
- GetPath(path: string): Promise<any>;
15
+ }>): Promise<JsonDiffResult>;
16
16
  Destroy(): void;
17
17
  }
18
+ export {};
@@ -1,21 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.DiffAsync = void 0;
4
- const diffTree_1 = require("./diffTree");
5
4
  const workerQueue_1 = require("./workerQueue");
6
5
  const diffWorker_1 = require("./diffWorker");
7
- const diffCnstr = (0, diffTree_1.DiffTreeScope)();
8
6
  class DiffAsync {
9
7
  workerQueue;
10
8
  constructor(keyFunc) {
11
9
  this.workerQueue = new workerQueue_1.WorkerQueue(diffWorker_1.DiffWorker.Create());
12
- this.workerQueue.Push({ method: "create", arguments: [keyFunc.toString()] });
13
- }
14
- static GetKeyRef(key) {
15
- return diffCnstr.GetKeyRef(key);
16
- }
17
- static ReadKeyRef(ref) {
18
- return diffCnstr.ReadKeyRef(ref);
10
+ this.workerQueue.Push({ method: "create", arguments: keyFunc ? [keyFunc.toString()] : [] });
19
11
  }
20
12
  async DiffPath(path, value) {
21
13
  return await this.workerQueue.Push({ method: "diffpath", arguments: [path, value] });
@@ -23,12 +15,6 @@ class DiffAsync {
23
15
  async DiffBatch(data) {
24
16
  return await this.workerQueue.Push({ method: "diffbatch", arguments: [data] });
25
17
  }
26
- async UpdatePath(path, value) {
27
- await this.workerQueue.Push({ method: "updatepath", arguments: [path, value] });
28
- }
29
- async GetPath(path) {
30
- return await this.workerQueue.Push({ method: "getpath", arguments: [path] });
31
- }
32
18
  Destroy() {
33
19
  this.workerQueue.Destroy();
34
20
  }
@@ -1,14 +1,12 @@
1
- export declare class DiffSync {
1
+ import { IDiffTree } from "./diffTree";
2
+ export declare class DiffSync implements IDiffTree {
2
3
  private diffTree;
3
4
  constructor(keyFunc?: {
4
5
  (val: any): string;
5
6
  });
6
- static GetKeyRef(key: string): string;
7
- static ReadKeyRef(ref: string): string;
8
- DiffPath(path: string, value: any): import("./diffTree").IDiffResponse;
7
+ DiffPath(path: string, value: any): import("../../Utils/json").JsonDiffResult;
9
8
  DiffBatch(data: Array<{
10
9
  path: string;
11
10
  value: any;
12
- }>): import("./diffTree").IDiffResponse;
13
- UpdatePath(path: string, value: any): void;
11
+ }>): import("../../Utils/json").JsonDiffResult;
14
12
  }
@@ -1,27 +1,21 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.DiffSync = void 0;
4
+ const jsonDeepClone_1 = require("../../Utils/jsonDeepClone");
4
5
  const diffTree_1 = require("./diffTree");
5
- const diffCnstr = (0, diffTree_1.DiffTreeScope)();
6
+ const diffCnstr = (0, diffTree_1.DiffTreeFactory)();
6
7
  class DiffSync {
7
8
  diffTree;
8
9
  constructor(keyFunc) {
9
10
  this.diffTree = new diffCnstr(keyFunc);
10
11
  }
11
- static GetKeyRef(key) {
12
- return diffCnstr.GetKeyRef(key);
13
- }
14
- static ReadKeyRef(ref) {
15
- return diffCnstr.ReadKeyRef(ref);
16
- }
17
12
  DiffPath(path, value) {
13
+ value = (0, jsonDeepClone_1.JsonDeepClone)(value);
18
14
  return this.diffTree.DiffPath(path, value);
19
15
  }
20
16
  DiffBatch(data) {
17
+ data = (0, jsonDeepClone_1.JsonDeepClone)(data);
21
18
  return this.diffTree.DiffBatch(data);
22
19
  }
23
- UpdatePath(path, value) {
24
- this.diffTree.UpdatePath(path, value);
25
- }
26
20
  }
27
21
  exports.DiffSync = DiffSync;
@@ -1,24 +1,18 @@
1
+ import { JsonDiffFactoryResult, JsonDiffResult } from "../../Utils/json";
1
2
  export interface IDiffMethod {
2
3
  method: "create" | "diffpath" | "diffbatch" | "updatepath" | "getpath";
3
4
  arguments: Array<any>;
4
5
  }
5
- export type IDiffResponse = {
6
- path: string;
7
- value: any;
8
- }[];
9
6
  export interface IDiffTree {
10
7
  DiffBatch(data: Array<{
11
8
  path: string;
12
9
  value: any;
13
- }>): IDiffResponse;
14
- DiffPath(path: string, value: any): IDiffResponse;
15
- UpdatePath(path: string, value: any): void;
10
+ }>): JsonDiffResult;
11
+ DiffPath(path: string, value: any): JsonDiffResult;
16
12
  }
17
13
  export interface IDiffTreeConstructor {
18
14
  new (keyFunc?: {
19
15
  (val: any): string;
20
16
  }): IDiffTree;
21
- GetKeyRef(key: string): string;
22
- ReadKeyRef(ref: string): string;
23
17
  }
24
- export declare function DiffTreeScope(worker?: boolean): IDiffTreeConstructor;
18
+ export declare function DiffTreeFactory(jsonDiffFactory?: () => JsonDiffFactoryResult, worker?: boolean): IDiffTreeConstructor;
@@ -1,230 +1,137 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.DiffTreeScope = DiffTreeScope;
4
- function DiffTreeScope(worker) {
3
+ exports.DiffTreeFactory = DiffTreeFactory;
4
+ function DiffTreeFactory(jsonDiffFactory, worker) {
5
+ const { JsonDiff, JsonType } = jsonDiffFactory();
5
6
  const ctx = this;
6
7
  if (ctx && worker) {
7
8
  let diffTree = null;
8
9
  ctx.onmessage = function (event) {
9
- var data = event.data;
10
+ const data = event.data;
10
11
  switch (data.method) {
11
- case "create":
12
- var keyFunc = data.arguments[0] ? eval(data.arguments[0]) : undefined;
12
+ case "create": {
13
+ const keyFunc = data.arguments[0]
14
+ ? eval(data.arguments[0])
15
+ : undefined;
13
16
  diffTree = new DiffTree(keyFunc);
14
17
  ctx.postMessage(null);
15
18
  break;
16
- case "diffpath":
17
- var diff = diffTree.DiffPath(data.arguments[0], data.arguments[1]);
19
+ }
20
+ case "diffpath": {
21
+ const diff = diffTree.DiffPath(data.arguments[0], data.arguments[1]);
18
22
  ctx.postMessage(diff);
19
23
  break;
20
- case "diffbatch":
21
- var diff = diffTree.DiffBatch(data.arguments[0]);
24
+ }
25
+ case "diffbatch": {
26
+ const diff = diffTree.DiffBatch(data.arguments[0]);
22
27
  ctx.postMessage(diff);
23
28
  break;
24
- case "updatepath":
25
- diffTree.UpdatePath(data.arguments[0], data.arguments[1]);
26
- ctx.postMessage(null);
27
- break;
28
- case "getpath":
29
- var ret = diffTree.GetPath(data.arguments[0]);
29
+ }
30
+ case "getpath": {
31
+ const ret = diffTree.GetPath(data.arguments[0]);
30
32
  ctx.postMessage(ret);
31
33
  break;
34
+ }
32
35
  }
33
36
  };
34
37
  }
35
- const jsonConstructor = {}.constructor;
36
- function IsValue(value) {
37
- if (!value)
38
- return true;
39
- return !(jsonConstructor === value.constructor || Array.isArray(value));
38
+ function FlattenValue(root, value, keyFunc) {
39
+ const type = JsonType(value);
40
+ switch (type) {
41
+ case "array":
42
+ const typedArray = value;
43
+ for (let x = 0; x < typedArray.length; x++)
44
+ FlattenValue(root, typedArray[x], keyFunc);
45
+ break;
46
+ case "object":
47
+ const typedObject = value;
48
+ const key = keyFunc(typedObject);
49
+ if (key)
50
+ root[key] = typedObject;
51
+ const keys = Object.keys(typedObject);
52
+ for (let x = 0; x < keys.length; x++)
53
+ FlattenValue(root, typedObject[keys[x]], keyFunc);
54
+ }
55
+ return root;
40
56
  }
41
- let Type;
42
- (function (Type) {
43
- Type[Type["Value"] = 0] = "Value";
44
- Type[Type["Object"] = 1] = "Object";
45
- Type[Type["Array"] = 2] = "Array";
46
- })(Type || (Type = {}));
47
- function TypeOf(value) {
48
- if (!value)
49
- return Type.Value;
50
- if (jsonConstructor === value.constructor)
51
- return Type.Object;
52
- if (Array.isArray(value))
53
- return Type.Array;
54
- return Type.Value;
57
+ function GetPathValue(source, path) {
58
+ if (path === "")
59
+ return source;
60
+ const parts = path.split(".");
61
+ let curr = source;
62
+ for (let x = 0; x < parts.length; x++)
63
+ curr = curr[parts[x]];
64
+ return curr;
55
65
  }
56
- function JsonDiffRecursive(path, newValue, oldValue, resp) {
57
- if (newValue === oldValue)
58
- return false;
59
- const newType = TypeOf(newValue);
60
- const oldType = TypeOf(oldValue);
61
- const changedPathLength = resp.length;
62
- let allChildrenChanged = true;
63
- if (newType === oldType)
64
- switch (newType) {
65
- case Type.Array: {
66
- allChildrenChanged = JsonDiffArrays(path, newValue, oldValue, resp);
67
- break;
68
- }
69
- case Type.Object: {
70
- allChildrenChanged = JsonDiffObjects(path, newValue, oldValue, resp);
71
- break;
72
- }
73
- }
74
- if (allChildrenChanged) {
75
- resp.splice(changedPathLength);
76
- resp.push({
77
- path,
78
- value: newValue
79
- });
80
- return true;
81
- }
82
- return false;
66
+ function SetPathValue(source, path, value) {
67
+ if (path.length === 0)
68
+ return;
69
+ let curr = source;
70
+ let x = 0;
71
+ for (; x < path.length - 1; x++)
72
+ curr = curr[path[x]];
73
+ curr[path[x]] = value;
83
74
  }
84
- function JsonDiffArrays(path, newValue, oldValue, resp) {
85
- let allChildrenChanged = true;
86
- if (newValue.length !== oldValue.length)
87
- resp.push({
88
- path: path ? `${path}.length` : 'length',
89
- value: newValue.length
90
- });
91
- if (newValue.length > 0 || oldValue.length > 0) {
92
- for (let y = 0; y < newValue.length; y++) {
93
- const arrayPath = path ? `${path}.${y}` : `${y}`;
94
- allChildrenChanged = JsonDiffRecursive(arrayPath, newValue[y], oldValue[y], resp) && allChildrenChanged;
95
- }
96
- }
97
- else
98
- allChildrenChanged = false;
99
- return allChildrenChanged;
75
+ function ResolveKeyPath(source, path, keyFunc) {
76
+ const parts = path.split('.');
77
+ const pathValues = new Array(parts.length - 1);
78
+ let curr = source;
79
+ for (let x = 0; x < parts.length - 1; x++) {
80
+ curr = curr[parts[x]];
81
+ pathValues[x] = curr;
82
+ }
83
+ let y = pathValues.length - 1;
84
+ for (; y >= 0 && !(JsonType(pathValues[y]) === 'object' && keyFunc(pathValues[y])); y--) { }
85
+ if (y >= 0) {
86
+ const key = keyFunc(pathValues[y]);
87
+ parts.splice(0, y + 1, key);
88
+ return parts.join('.');
89
+ }
90
+ return path;
100
91
  }
101
- function JsonDiffObjects(path, newValue, oldValue, resp) {
102
- let allChildrenChanged = true;
103
- const newKeys = Object.keys(newValue);
104
- const oldKeys = Object.keys(oldValue);
105
- if (newKeys.length === 0 && oldKeys.length === 0) {
106
- return false;
107
- }
108
- if (newKeys.length >= oldKeys.length) {
109
- let newKeyIndex = 0;
110
- let oldKeyIndex = 0;
111
- while (newKeyIndex < newKeys.length) {
112
- const childPath = path ? `${path}.${newKeys[newKeyIndex]}` : newKeys[newKeyIndex];
113
- if (oldKeyIndex < oldKeys.length && newKeys[newKeyIndex] === oldKeys[oldKeyIndex]) {
114
- allChildrenChanged =
115
- JsonDiffRecursive(childPath, newValue[newKeys[newKeyIndex]], oldValue[oldKeys[oldKeyIndex]], resp) &&
116
- allChildrenChanged;
117
- oldKeyIndex++;
118
- }
119
- else if (newValue[newKeys[newKeyIndex]] !== undefined) {
120
- resp.push({
121
- path: childPath,
122
- value: newValue[newKeys[newKeyIndex]]
123
- });
124
- }
125
- newKeyIndex++;
92
+ function UpdateSource(source, path, value, keyFunc) {
93
+ const diffResult = [];
94
+ if (keyFunc) {
95
+ const keyPath = ResolveKeyPath(source, path, keyFunc);
96
+ if (keyPath !== path) {
97
+ const keyDiffResult = UpdateSource(source, keyPath, value, keyFunc);
98
+ diffResult.push(...keyDiffResult);
126
99
  }
127
- if (oldKeyIndex < oldKeys.length)
128
- allChildrenChanged = true;
129
100
  }
130
- return allChildrenChanged;
131
- }
132
- function BreakUpValue(path, parent, keyFunc, prop, map) {
133
- const value = prop ? parent[prop] : parent;
134
- const isValue = IsValue(value);
135
- if (!map && isValue)
136
- return new Map([[path, value]]);
137
- map = map || new Map();
138
- if (isValue)
139
- return map;
140
- const key = keyFunc ? keyFunc(value) : null;
141
- const keyRef = key && DiffTree.GetKeyRef(key);
142
- if (key && key !== path) {
143
- if (prop)
144
- parent[prop] = keyRef;
145
- BreakUpValue(key, value, keyFunc, null, map);
101
+ const sourceValue = GetPathValue(source, path);
102
+ JsonDiff(value, sourceValue, path, diffResult);
103
+ if (keyFunc) {
104
+ let flattened = {};
105
+ flattened = FlattenValue(flattened, value, keyFunc);
106
+ const keys = Object.keys(flattened);
107
+ for (let x = 0; x < keys.length; x++)
108
+ JsonDiff(flattened[keys[x]], source[keys[x]], keys[x], diffResult);
146
109
  }
147
- else {
148
- for (const subProp in value) {
149
- const childPath = `${path}.${subProp}`;
150
- BreakUpValue(childPath, value, keyFunc, subProp, map);
151
- }
110
+ const filteredDiffResult = diffResult.filter((diff) => diff.value !== undefined);
111
+ for (let x = 0; x < filteredDiffResult.length; x++) {
112
+ SetPathValue(source, filteredDiffResult[x].path, filteredDiffResult[x].value);
152
113
  }
153
- if (!prop)
154
- map.set(path, key === path ? value : keyRef || value);
155
- return map;
114
+ return diffResult;
156
115
  }
157
116
  class DiffTree {
158
117
  keyFunc;
159
- rootStateMap = new Map();
118
+ rootState = { root: null };
160
119
  constructor(keyFunc) {
161
120
  this.keyFunc = keyFunc;
162
121
  }
163
- static GetKeyRef(key) {
164
- return `___DiffTreeKeyRef.${key}`;
165
- }
166
- static ReadKeyRef(ref) {
167
- if (!ref)
168
- return undefined;
169
- var matches = ref.match(/^___DiffTreeKeyRef\.([^.]+$)/);
170
- if (!matches)
171
- return undefined;
172
- return matches[1];
173
- }
174
122
  DiffBatch(data) {
175
- var resp = [];
176
- ;
177
- for (var x = 0; x < data.length; x++)
178
- this.RunDiff(data[x].path, data[x].value, resp);
179
- return resp;
123
+ const results = data
124
+ .map(({ path, value }) => this.DiffPath(path, value))
125
+ .flat(1);
126
+ return results;
180
127
  }
181
128
  DiffPath(path, value) {
182
- var resp = [];
183
- this.RunDiff(path, value, resp);
184
- return resp;
185
- }
186
- UpdatePath(path, value) {
187
- this.SetPathValue(path, value);
129
+ path = (path && `root.${path}`) || "root";
130
+ return UpdateSource(this.rootState, path, value, this.keyFunc);
188
131
  }
189
132
  GetPath(path) {
190
- return this.GetPathValue(path);
191
- }
192
- RunDiff(path, value, diffResp) {
193
- var breakupMap = this.GetBreakUpMap(path, value);
194
- var resp = diffResp || [];
195
- breakupMap.forEach((value, key) => {
196
- var currentValue = key.split(".").reduce((pre, curr, index) => {
197
- if (index === 0)
198
- return this.rootStateMap.get(curr);
199
- return pre && pre[curr];
200
- }, null);
201
- JsonDiffRecursive(key, value, currentValue, resp);
202
- });
203
- for (var x = 0; x < resp.length; x++)
204
- this.SetPathValue(resp[x].path, resp[x].value);
205
- }
206
- GetPathValue(path) {
207
- var parts = path.split(".");
208
- var curr = this.rootStateMap.get(parts[0]);
209
- for (var x = 1; x < parts.length; x++)
210
- curr = curr && curr[parts[x]];
211
- return curr;
212
- }
213
- SetPathValue(path, value) {
214
- var parts = path.split(".");
215
- if (parts.length === 1)
216
- this.rootStateMap.set(parts[0], value);
217
- else {
218
- var curr = this.rootStateMap.get(parts[0]);
219
- for (var x = 1; x < parts.length - 1; x++)
220
- curr = curr[parts[x]];
221
- curr[parts[parts.length - 1]] = value;
222
- }
223
- }
224
- GetBreakUpMap(path, value) {
225
- if (!this.keyFunc)
226
- return new Map([[path, value]]);
227
- return BreakUpValue(path, value, this.keyFunc);
133
+ path = (path && `root.${path}`) || "root";
134
+ return GetPathValue(this.rootState, path);
228
135
  }
229
136
  }
230
137
  return DiffTree;
@@ -1,14 +1,15 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.DiffWorker = void 0;
4
+ const json_1 = require("../../Utils/json");
4
5
  const diffTree_1 = require("./diffTree");
5
6
  var DiffWorker;
6
7
  (function (DiffWorker) {
7
- var workerConstructor = null;
8
- var workerParameter = null;
9
- if (typeof Worker !== 'undefined') {
8
+ let workerConstructor = null;
9
+ let workerParameter = null;
10
+ if (typeof Worker !== "undefined") {
10
11
  workerConstructor = Worker;
11
- workerParameter = URL.createObjectURL(new Blob([`(${diffTree_1.DiffTreeScope}).call(this, true)`]));
12
+ workerParameter = URL.createObjectURL(new Blob([`(${diffTree_1.DiffTreeFactory}).call(this, (${json_1.JsonDiffFactory}), true)`]));
12
13
  }
13
14
  function Create() {
14
15
  if (!workerConstructor)
@@ -1,14 +0,0 @@
1
- import { StoreWriter } from "./storeWriter";
2
- export declare class Store<T> {
3
- private observableTree;
4
- private storeWriter;
5
- private rootScope;
6
- get Root(): import("..").ObservableScope<T>;
7
- constructor(init?: T);
8
- Action(action: {
9
- (root: T, writer: StoreWriter): void;
10
- }): void;
11
- Write(data: T): void;
12
- Merge(data: Partial<T>): void;
13
- Destroy(): void;
14
- }
@@ -1,31 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Store = void 0;
4
- const observableTree_1 = require("../Tree/observableTree");
5
- const storeWriter_1 = require("./storeWriter");
6
- class Store {
7
- observableTree = new observableTree_1.ObservableTree();
8
- storeWriter = new storeWriter_1.StoreWriter(this.observableTree);
9
- rootScope = this.observableTree.Scope("ROOT", root => root);
10
- get Root() {
11
- return this.rootScope;
12
- }
13
- constructor(init) {
14
- if (init)
15
- this.Write(init);
16
- }
17
- Action(action) {
18
- var proxy = this.observableTree.Get("ROOT");
19
- action(proxy, this.storeWriter);
20
- }
21
- Write(data) {
22
- this.Action((root, writer) => writer.Write(root, data));
23
- }
24
- Merge(data) {
25
- this.Action((root, writer) => writer.Merge(root, data));
26
- }
27
- Destroy() {
28
- this.rootScope.Destroy();
29
- }
30
- }
31
- exports.Store = Store;
@@ -1,20 +0,0 @@
1
- import { StoreAsyncWriter } from "./storeAsyncWriter";
2
- export declare class StoreAsync {
3
- private idFunc;
4
- private diffAsync;
5
- private observableTree;
6
- private asyncWriter;
7
- private asyncQueue;
8
- constructor(idFunc: {
9
- (val: any): string;
10
- }, init?: any);
11
- Scope<T, R>(id: string, func: {
12
- (val: T): R;
13
- }): import("..").ObservableScope<T | R>;
14
- Action<T>(id: string, action: {
15
- (val: T, writer: StoreAsyncWriter): Promise<void>;
16
- }): Promise<void>;
17
- Write(data: any): Promise<void>;
18
- Merge(id: string, data: any): Promise<void>;
19
- Destroy(): void;
20
- }
@@ -1,49 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.StoreAsync = void 0;
4
- const observableTree_1 = require("../Tree/observableTree");
5
- const diffAsync_1 = require("../Diff/diffAsync");
6
- const storeAsyncWriter_1 = require("./storeAsyncWriter");
7
- const asyncQueue_1 = require("../../Utils/asyncQueue");
8
- class StoreAsync {
9
- idFunc;
10
- diffAsync;
11
- observableTree;
12
- asyncWriter;
13
- asyncQueue;
14
- constructor(idFunc, init) {
15
- this.idFunc = idFunc;
16
- this.diffAsync = new diffAsync_1.DiffAsync(this.idFunc);
17
- this.observableTree = new observableTree_1.ObservableTree(diffAsync_1.DiffAsync.ReadKeyRef);
18
- this.asyncWriter = new storeAsyncWriter_1.StoreAsyncWriter(this.idFunc, this.diffAsync, this.observableTree);
19
- this.asyncQueue = new asyncQueue_1.AsyncQueue();
20
- if (init) {
21
- var id = this.idFunc(init);
22
- this.observableTree.Write(id, init);
23
- this.Write(init);
24
- }
25
- }
26
- Scope(id, func) {
27
- return this.observableTree.Scope(id, func);
28
- }
29
- async Action(id, action) {
30
- await this.asyncQueue.Next(async () => {
31
- await action(id && this.observableTree.Get(id), this.asyncWriter);
32
- });
33
- }
34
- async Write(data) {
35
- await this.Action(null, async (val, writer) => {
36
- await writer.Write(val, data);
37
- });
38
- }
39
- async Merge(id, data) {
40
- await this.Action(id, async (val, writer) => {
41
- await writer.Merge(val, data);
42
- });
43
- }
44
- Destroy() {
45
- this.asyncQueue.Stop();
46
- this.diffAsync.Destroy();
47
- }
48
- }
49
- exports.StoreAsync = StoreAsync;