j-templates 5.0.36 → 5.0.38

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.
@@ -14,8 +14,8 @@ class Store {
14
14
  return this.rootScope;
15
15
  }
16
16
  Action(action) {
17
- var node = this.observableTree.GetNode("ROOT");
18
- action(node.Proxy, this.storeWriter);
17
+ var proxy = this.observableTree.Get("ROOT");
18
+ action(proxy, this.storeWriter);
19
19
  }
20
20
  Write(data) {
21
21
  this.Action((root, writer) => writer.Write(root, data));
@@ -25,7 +25,6 @@ class Store {
25
25
  }
26
26
  Destroy() {
27
27
  this.rootScope.Destroy();
28
- this.observableTree.Destroy();
29
28
  }
30
29
  }
31
30
  exports.Store = Store;
@@ -10,7 +10,7 @@ export declare class StoreAsync {
10
10
  }, init?: any);
11
11
  Scope<T, R>(id: string, func: {
12
12
  (val: T): R;
13
- }): import("..").ObservableScope<R>;
13
+ }): import("..").ObservableScope<T | R>;
14
14
  Action<T>(id: string, action: {
15
15
  (val: T, writer: StoreAsyncWriter): Promise<void>;
16
16
  }): Promise<void>;
@@ -22,10 +22,7 @@ class StoreAsync {
22
22
  }
23
23
  async Action(id, action) {
24
24
  await this.asyncQueue.Next(async () => {
25
- var node;
26
- if (id)
27
- node = this.observableTree.GetNode(id);
28
- await action(node && node.Proxy, this.asyncWriter);
25
+ await action(id && this.observableTree.Get(id), this.asyncWriter);
29
26
  });
30
27
  }
31
28
  async Write(data) {
@@ -41,7 +38,6 @@ class StoreAsync {
41
38
  Destroy() {
42
39
  this.asyncQueue.Stop();
43
40
  this.diffAsync.Destroy();
44
- this.observableTree.Destroy();
45
41
  }
46
42
  }
47
43
  exports.StoreAsync = StoreAsync;
@@ -1,6 +1,5 @@
1
1
  import { DiffAsync } from "../Diff/diffAsync";
2
2
  import { ObservableTree } from "../Tree/observableTree";
3
- import { ObservableProxy } from "../Tree/observableProxy";
4
3
  export declare class StoreAsyncWriter {
5
4
  private idFunc;
6
5
  private diffAsync;
@@ -8,9 +7,9 @@ export declare class StoreAsyncWriter {
8
7
  constructor(idFunc: {
9
8
  (val: any): string;
10
9
  }, diffAsync: DiffAsync, observableTree: ObservableTree);
11
- Write<T>(source: T | ObservableProxy, data: any): Promise<void>;
12
- Merge<T>(source: T | ObservableProxy, data: Partial<T>): Promise<void>;
13
- Push<T>(source: Array<T> | ObservableProxy, data: T): Promise<void>;
14
- Splice<T>(source: Array<T> | ObservableProxy, start: number, deleteCount?: number, ...items: Array<T>): Promise<void>;
10
+ Write<T>(source: T, data: any): Promise<void>;
11
+ Merge<T>(source: T, data: Partial<T>): Promise<void>;
12
+ Push<T>(source: Array<T>, data: T): Promise<void>;
13
+ Splice<T>(source: Array<T>, start: number, deleteCount?: number, ...items: Array<T>): Promise<void>;
15
14
  private ApplyChanges;
16
15
  }
@@ -7,38 +7,34 @@ class StoreAsyncWriter {
7
7
  this.observableTree = observableTree;
8
8
  }
9
9
  async Write(source, data) {
10
- var path;
10
+ let path;
11
11
  if (source) {
12
- var proxy = source;
13
- path = proxy.___node.Path;
12
+ path = this.observableTree.GetPathOf(source);
14
13
  }
15
14
  else {
16
15
  path = this.idFunc(data);
17
16
  if (!path)
18
17
  throw new Error("data must have an id");
19
18
  }
20
- var diff = await this.diffAsync.DiffPath(path, data);
19
+ let diff = await this.diffAsync.DiffPath(path, data);
21
20
  this.ApplyChanges(diff);
22
21
  }
23
22
  async Merge(source, data) {
24
- var proxy = source;
25
- var rootPath = proxy.___node.Path;
26
- var keys = Object.keys(data);
27
- var message = keys.map(key => ({ path: `${rootPath}.${key}`, value: data[key] }));
28
- var diff = await this.diffAsync.DiffBatch(message);
23
+ const rootPath = this.observableTree.GetPathOf(source);
24
+ const keys = Object.keys(data);
25
+ const message = keys.map(key => ({ path: `${rootPath}.${key}`, value: data[key] }));
26
+ const diff = await this.diffAsync.DiffBatch(message);
29
27
  this.ApplyChanges(diff);
30
28
  }
31
29
  async Push(source, data) {
32
- var proxy = source;
33
- var rootPath = proxy.___node.Path;
30
+ const rootPath = this.observableTree.GetPathOf(source);
34
31
  var lengthPath = `${rootPath}.length`;
35
32
  var length = await this.diffAsync.GetPath(lengthPath);
36
33
  var diff = await this.diffAsync.DiffPath(`${rootPath}.${length}`, data);
37
34
  this.ApplyChanges(diff);
38
35
  }
39
36
  async Splice(source, start, deleteCount, ...items) {
40
- var proxy = source;
41
- var rootPath = proxy.___node.Path;
37
+ var rootPath = this.observableTree.GetPathOf(source);
42
38
  var array = await this.diffAsync.GetPath(rootPath);
43
39
  array = array.slice();
44
40
  array.splice(start, deleteCount, ...items);
@@ -16,8 +16,8 @@ class StoreSync {
16
16
  return this.rootScope;
17
17
  }
18
18
  Action(action) {
19
- var node = this.observableTree.GetNode("ROOT");
20
- action(node.Proxy, this.storeWriter);
19
+ var proxy = this.observableTree.Get("ROOT");
20
+ action(proxy, this.storeWriter);
21
21
  }
22
22
  Write(data) {
23
23
  this.Action((root, writer) => writer.Write(root, data));
@@ -27,7 +27,6 @@ class StoreSync {
27
27
  }
28
28
  Destroy() {
29
29
  this.rootScope.Destroy();
30
- this.observableTree.Destroy();
31
30
  }
32
31
  }
33
32
  exports.StoreSync = StoreSync;
@@ -1,13 +1,12 @@
1
1
  import { ObservableTree } from "../Tree/observableTree";
2
- import { ObservableProxy } from "../Tree/observableProxy";
3
2
  import { DiffSync } from "../Diff/diffSync";
4
3
  export declare class StoreSyncWriter {
5
4
  private diffSync;
6
5
  private observableTree;
7
6
  constructor(diffSync: DiffSync, observableTree: ObservableTree);
8
- Write<T>(source: T | ObservableProxy, data: any): void;
9
- Merge<T>(source: T | ObservableProxy, data: Partial<T>): void;
10
- Push<T>(source: Array<T> | ObservableProxy, data: T): void;
11
- Splice<T>(source: Array<T> | ObservableProxy, start: number, deleteCount?: number, ...items: Array<T>): any[];
7
+ Write<T>(source: T, data: any): void;
8
+ Merge<T>(source: T, data: Partial<T>): void;
9
+ Push<T>(source: Array<T>, data: T): void;
10
+ Splice<T>(source: Array<T>, start: number, deleteCount?: number, ...items: Array<T>): void;
12
11
  private ApplyChanges;
13
12
  }
@@ -6,35 +6,30 @@ class StoreSyncWriter {
6
6
  this.observableTree = observableTree;
7
7
  }
8
8
  Write(source, data) {
9
- var proxy = source;
10
- var rootPath = proxy && proxy.___node.Path || "ROOT";
9
+ var rootPath = source && this.observableTree.GetPathOf(source) || "ROOT";
11
10
  var diff = this.diffSync.DiffPath(rootPath, data);
12
11
  this.ApplyChanges(diff);
13
12
  }
14
13
  Merge(source, data) {
15
- var proxy = source;
16
- var rootPath = proxy.___node.Path;
14
+ var rootPath = this.observableTree.GetPathOf(source);
17
15
  var keys = Object.keys(data);
18
16
  var message = keys.map(key => ({ path: `${rootPath}.${key}`, value: data[key] }));
19
17
  var diff = this.diffSync.DiffBatch(message);
20
18
  this.ApplyChanges(diff);
21
19
  }
22
20
  Push(source, data) {
23
- var array = source;
24
- var proxy = source;
25
- var rootPath = proxy.___node.Path;
26
- var length = array.length;
21
+ var rootPath = this.observableTree.GetPathOf(source);
22
+ var length = source.length;
27
23
  this.diffSync.UpdatePath(`${rootPath}.${length}`, data);
28
- proxy.___node.Push(data);
24
+ this.observableTree.Write(`${rootPath}.${length}`, data);
29
25
  }
30
26
  Splice(source, start, deleteCount, ...items) {
31
- var proxy = source;
32
- var rootPath = proxy.___node.Path;
33
- var array = this.observableTree.Get(rootPath);
34
- array = array.map(val => val);
27
+ var rootPath = this.observableTree.GetPathOf(source);
28
+ var proxy = this.observableTree.Get(rootPath);
29
+ const array = proxy.toJSON().slice();
35
30
  array.splice(start, deleteCount, ...items);
36
31
  this.diffSync.UpdatePath(rootPath, array);
37
- return proxy.___node.Splice(start, deleteCount, ...items);
32
+ this.observableTree.Write(rootPath, array);
38
33
  }
39
34
  ApplyChanges(diff) {
40
35
  this.observableTree.WriteAll(diff);
@@ -1,10 +1,9 @@
1
1
  import { ObservableTree } from "../Tree/observableTree";
2
- import { ObservableProxy } from "../Tree/observableProxy";
3
2
  export declare class StoreWriter {
4
3
  private observableTree;
5
4
  constructor(observableTree: ObservableTree);
6
- Write<T>(source: T | ObservableProxy, data: any): void;
7
- Merge<T>(source: T | ObservableProxy, data: Partial<T>): void;
8
- Push<T>(source: Array<T> | ObservableProxy, data: T): void;
9
- Splice<T>(source: Array<T> | ObservableProxy, start: number, deleteCount?: number, ...items: Array<T>): void;
5
+ Write<T>(source: T, data: any): void;
6
+ Merge<T>(source: T, data: Partial<T>): void;
7
+ Push<T>(source: Array<T>, data: T): void;
8
+ Splice<T>(source: Array<T>, start: number, deleteCount?: number, ...items: Array<T>): void;
10
9
  }
@@ -1,31 +1,28 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- const observableProxy_1 = require("../Tree/observableProxy");
4
3
  class StoreWriter {
5
4
  constructor(observableTree) {
6
5
  this.observableTree = observableTree;
7
6
  }
8
7
  Write(source, data) {
9
- var proxy = source;
10
- var rootPath = proxy && proxy.___node.Path || "ROOT";
8
+ const rootPath = source && this.observableTree.GetPathOf(source) || "ROOT";
11
9
  this.observableTree.Write(rootPath, data);
12
10
  }
13
11
  Merge(source, data) {
14
- var proxy = source;
15
- var rootPath = proxy.___node.Path;
16
- if (observableProxy_1.ObservableProxy.TypeOf(data) === observableProxy_1.Type.Value)
17
- this.observableTree.Write(rootPath, data);
18
- else
19
- for (var key in data)
20
- this.observableTree.Write(`${rootPath}.${key}`, data[key]);
12
+ const rootPath = this.observableTree.GetPathOf(source);
13
+ for (const key in data)
14
+ this.observableTree.Write(`${rootPath}.${key}`, data[key]);
21
15
  }
22
16
  Push(source, data) {
23
- var proxy = source;
24
- proxy.___node.Push(data);
17
+ const rootPath = this.observableTree.GetPathOf(source);
18
+ this.observableTree.Write(`${rootPath}.${length}`, data);
25
19
  }
26
20
  Splice(source, start, deleteCount, ...items) {
27
- var proxy = source;
28
- proxy.___node.Splice(start, deleteCount, ...items);
21
+ const json = source.toJSON();
22
+ const copy = json.slice();
23
+ copy.splice(start, deleteCount, ...items);
24
+ const rootPath = this.observableTree.GetPathOf(source);
25
+ this.observableTree.Write(rootPath, copy);
29
26
  }
30
27
  }
31
28
  exports.StoreWriter = StoreWriter;
@@ -131,8 +131,7 @@ function UpdateValue(scope) {
131
131
  return;
132
132
  scope.dirty = false;
133
133
  var value = null;
134
- var emitters = WatchAction(() => value = scope.getFunction());
135
- UpdateEmitters(scope, emitters);
134
+ var emitters = scope.getFunction && WatchAction(() => value = scope.getFunction());
136
135
  if (scope.async)
137
136
  Promise.resolve(value).then(val => {
138
137
  scope.value = val;
@@ -140,6 +139,7 @@ function UpdateValue(scope) {
140
139
  });
141
140
  else
142
141
  scope.value = value;
142
+ UpdateEmitters(scope, emitters);
143
143
  }
144
144
  function DestroyScope(scope) {
145
145
  if (!scope)
@@ -1,24 +1,33 @@
1
- import { ObservableNode } from "./observableNode";
2
- import { ObservableScope } from "./observableScope";
1
+ import { ObservableScope } from "../Tree/observableScope";
3
2
  export declare class ObservableTree {
4
3
  private valuePathResolver?;
4
+ private undefinedScope;
5
+ private scopeCache;
6
+ private leafScopeCache;
7
+ private proxyCache;
8
+ private pathCache;
5
9
  private rootStateMap;
6
- private rootNodeMap;
7
10
  constructor(valuePathResolver?: {
8
- (value: string): string;
11
+ (value: string): string | undefined;
9
12
  });
13
+ Get<O>(path: string): O;
14
+ GetPathOf(value: any): string;
15
+ Scope<O, R = O>(path: string, callback?: {
16
+ (obj: O): R;
17
+ }): ObservableScope<O | R>;
10
18
  Write(path: string, value: any): void;
11
19
  WriteAll(data: Array<{
12
20
  path: string;
13
21
  value: any;
14
22
  }>): void;
15
- Get<O>(path?: string): O;
16
- GetNode(path: string): ObservableNode;
17
- Delete(path: string): void;
18
- Destroy(): void;
19
- Scope<O, R = O>(path: string, func?: {
20
- (val: O): R;
21
- }): ObservableScope<R>;
23
+ private GetParentScope;
24
+ private GetPropertyScope;
25
+ private GetValueProxy;
26
+ private ObjectProxyGetter;
27
+ private CreateObjectProxy;
28
+ private ArrayProxyGetter;
29
+ private CreateArrayProxy;
30
+ private CreateProxy;
22
31
  private WritePath;
23
- private UpdatePathNode;
32
+ private UpdatePathCache;
24
33
  }
@@ -1,91 +1,215 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- const observableNode_1 = require("./observableNode");
4
- const observableProxy_1 = require("./observableProxy");
5
- const observableScope_1 = require("./observableScope");
3
+ const observableScope_1 = require("../Tree/observableScope");
4
+ var Type;
5
+ (function (Type) {
6
+ Type[Type["Value"] = 0] = "Value";
7
+ Type[Type["Object"] = 1] = "Object";
8
+ Type[Type["Array"] = 2] = "Array";
9
+ })(Type || (Type = {}));
10
+ const jsonConstructor = {}.constructor;
11
+ function TypeOf(value) {
12
+ if (!value)
13
+ return Type.Value;
14
+ if (jsonConstructor === value.constructor)
15
+ return Type.Object;
16
+ if (Array.isArray(value))
17
+ return Type.Array;
18
+ return Type.Value;
19
+ }
6
20
  class ObservableTree {
7
21
  constructor(valuePathResolver) {
8
22
  this.valuePathResolver = valuePathResolver;
23
+ this.undefinedScope = observableScope_1.ObservableScope.Create(function () { return undefined; });
24
+ this.scopeCache = new WeakMap();
25
+ this.leafScopeCache = new WeakMap();
26
+ this.proxyCache = new WeakMap();
27
+ this.pathCache = new WeakMap();
9
28
  this.rootStateMap = new Map();
10
- this.rootNodeMap = new Map();
11
- }
12
- Write(path, value) {
13
- this.WritePath(path, value);
14
- this.UpdatePathNode(path);
15
- }
16
- WriteAll(data) {
17
- for (var x = 0; x < data.length; x++)
18
- this.WritePath(data[x].path, data[x].value);
19
- for (var y = 0; y < data.length; y++)
20
- this.UpdatePathNode(data[y].path);
29
+ this.ObjectProxyGetter = (value, prop) => {
30
+ function toJSON() {
31
+ return value;
32
+ }
33
+ ;
34
+ switch (prop) {
35
+ case "toJSON":
36
+ return toJSON;
37
+ default:
38
+ if (typeof prop === 'symbol')
39
+ return value[prop];
40
+ return observableScope_1.ObservableScope.Value(this.GetPropertyScope(value, prop));
41
+ }
42
+ };
43
+ this.ArrayProxyGetter = (value, prop) => {
44
+ function toJSON() {
45
+ return value;
46
+ }
47
+ ;
48
+ switch (prop) {
49
+ case "toJSON":
50
+ return toJSON;
51
+ default:
52
+ if (typeof prop === 'symbol')
53
+ return value[prop];
54
+ if (isNaN(parseInt(prop))) {
55
+ const ret = value[prop];
56
+ if (typeof ret === 'function') {
57
+ const copy = value.map((val, index) => observableScope_1.ObservableScope.Value(this.GetPropertyScope(value, index.toString())));
58
+ return ret.bind(copy);
59
+ }
60
+ return ret;
61
+ }
62
+ return observableScope_1.ObservableScope.Value(this.GetPropertyScope(value, prop));
63
+ }
64
+ };
21
65
  }
22
66
  Get(path) {
23
- return path.split(".").reduce((pre, curr, index) => {
24
- if (index === 0)
25
- return this.rootStateMap.get(curr);
26
- return pre && pre[curr];
27
- }, null);
28
- }
29
- GetNode(path) {
30
- return path.split(".").reduce((pre, curr, index) => {
67
+ const val = path.split(".").reduce((pre, curr, index) => {
31
68
  if (index === 0) {
32
- var ret = this.rootNodeMap.get(curr);
33
- if (!ret) {
34
- ret = new observableNode_1.ObservableNode(this, curr, null, this.valuePathResolver);
35
- this.rootNodeMap.set(curr, ret);
36
- }
37
- return ret;
69
+ let value = this.rootStateMap.get(curr);
70
+ const scope = this.GetParentScope(value);
71
+ return observableScope_1.ObservableScope.Value(scope);
38
72
  }
39
- return pre.EnsureChild(curr);
73
+ return pre && pre[curr];
40
74
  }, null);
75
+ return val;
41
76
  }
42
- Delete(path) {
43
- var node = this.GetNode(path);
44
- node.Destroy();
45
- }
46
- Destroy() {
47
- this.rootStateMap.clear();
48
- this.rootNodeMap.forEach(node => node.Destroy());
49
- this.rootNodeMap.clear();
77
+ GetPathOf(value) {
78
+ if (value.toJSON && typeof value.toJSON === 'function')
79
+ value = value.toJSON();
80
+ return this.pathCache.get(value);
50
81
  }
51
- Scope(path, func) {
82
+ Scope(path, callback) {
52
83
  return new observableScope_1.ObservableScope(() => {
53
- var node = this.GetNode(path);
54
- return func && func(node.Proxy) || node.Proxy;
84
+ const obj = this.Get(path);
85
+ return callback && callback(obj) || obj;
55
86
  });
56
87
  }
57
- WritePath(path, value) {
58
- var pathParts = path.split(".");
59
- var rootPart = pathParts[0];
60
- if (pathParts.length === 1)
61
- this.rootStateMap.set(rootPart, value);
62
- else {
63
- var curValue = this.rootStateMap.get(rootPart);
64
- for (var x = 1; x < pathParts.length - 1; x++) {
65
- if (!curValue)
66
- throw new Error("Unable to write path: " + path + ". Falsey value found at: " + pathParts.slice(0, x).join("."));
67
- curValue = curValue[pathParts[x]];
68
- }
69
- if (!curValue)
70
- throw new Error("Unable to write path: " + path + ". Falsey value found at: " + pathParts.slice(0, x).join("."));
71
- curValue[pathParts[x]] = value;
88
+ Write(path, value) {
89
+ const scope = this.WritePath(path, value);
90
+ observableScope_1.ObservableScope.Update(scope);
91
+ }
92
+ WriteAll(data) {
93
+ const scopeSet = new Set();
94
+ for (var x = 0; x < data.length; x++) {
95
+ const scope = this.WritePath(data[x].path, data[x].value);
96
+ scopeSet.add(scope);
72
97
  }
98
+ scopeSet.forEach(scope => observableScope_1.ObservableScope.Update(scope));
73
99
  }
74
- UpdatePathNode(path) {
75
- var node = this.GetNode(path);
76
- node.Update();
77
- if (node.Parent && node.Parent.Type === observableProxy_1.Type.Array) {
78
- node.Parent.ArrayUpdate();
79
- if (node.Key === 'length') {
80
- var index = node.Value;
81
- var childNode = node.Parent.Children.get(index.toString());
82
- while (childNode) {
83
- childNode.Destroy();
84
- index++;
85
- childNode = node.Parent.Children.get(index.toString());
100
+ GetParentScope(value) {
101
+ const type = TypeOf(value);
102
+ if (type === Type.Value) {
103
+ if (this.valuePathResolver && typeof value === 'string') {
104
+ const path = this.valuePathResolver(value);
105
+ if (path) {
106
+ const val = this.rootStateMap.get(path);
107
+ return this.GetParentScope(val);
86
108
  }
87
109
  }
110
+ return value === undefined ? this.undefinedScope : observableScope_1.ObservableScope.Create(value);
111
+ }
112
+ let scope = this.scopeCache.get(value);
113
+ if (!scope) {
114
+ scope = observableScope_1.ObservableScope.Create(() => this.GetValueProxy(value));
115
+ this.scopeCache.set(value, scope);
116
+ }
117
+ return scope;
118
+ }
119
+ GetPropertyScope(parent, prop) {
120
+ const value = parent[prop];
121
+ const type = TypeOf(value);
122
+ if (type === Type.Value) {
123
+ let leafScopes = this.leafScopeCache.get(parent) || {};
124
+ leafScopes[prop] = leafScopes[prop] || observableScope_1.ObservableScope.Create(() => {
125
+ const parentScope = this.scopeCache.get(parent);
126
+ const parentValue = observableScope_1.ObservableScope.Value(parentScope);
127
+ const parentJson = parentValue.toJSON();
128
+ const currentValue = parentJson[prop];
129
+ let path;
130
+ if (this.valuePathResolver && typeof currentValue === 'string' && (path = this.valuePathResolver(currentValue)))
131
+ return this.Get(path);
132
+ return currentValue;
133
+ });
134
+ this.leafScopeCache.set(parent, leafScopes);
135
+ return leafScopes[prop];
136
+ }
137
+ else {
138
+ let scope = this.scopeCache.get(value);
139
+ if (!scope) {
140
+ scope = observableScope_1.ObservableScope.Create(() => {
141
+ const parentScope = this.scopeCache.get(parent);
142
+ const parentValue = observableScope_1.ObservableScope.Value(parentScope);
143
+ const parentJson = parentValue.toJSON();
144
+ const currentValue = parentJson[prop];
145
+ return this.GetValueProxy(currentValue);
146
+ });
147
+ this.scopeCache.set(value, scope);
148
+ }
149
+ return scope;
150
+ }
151
+ }
152
+ GetValueProxy(value) {
153
+ let proxy = this.proxyCache.get(value);
154
+ if (!proxy) {
155
+ proxy = this.CreateProxy(value);
156
+ this.proxyCache.set(value, proxy);
157
+ }
158
+ return proxy;
159
+ }
160
+ CreateObjectProxy(value) {
161
+ return new Proxy(value, {
162
+ get: this.ObjectProxyGetter
163
+ });
164
+ }
165
+ CreateArrayProxy(value) {
166
+ return new Proxy(value, {
167
+ get: this.ArrayProxyGetter
168
+ });
169
+ }
170
+ CreateProxy(value) {
171
+ const type = TypeOf(value);
172
+ switch (type) {
173
+ case Type.Object:
174
+ return this.CreateObjectProxy(value);
175
+ case Type.Array:
176
+ return this.CreateArrayProxy(value);
177
+ default:
178
+ return value;
88
179
  }
89
180
  }
181
+ WritePath(path, value) {
182
+ this.UpdatePathCache(path, value);
183
+ const pathParts = path.split(".");
184
+ if (pathParts.length === 1) {
185
+ const currentValue = this.rootStateMap.get(pathParts[0]);
186
+ this.rootStateMap.set(pathParts[0], value);
187
+ return currentValue === undefined ? this.undefinedScope : this.scopeCache.get(currentValue);
188
+ }
189
+ let parentValue;
190
+ let x = 0;
191
+ for (; x < pathParts.length - 1 && (x === 0 || parentValue); x++) {
192
+ if (x === 0)
193
+ parentValue = this.rootStateMap.get(pathParts[x]);
194
+ else
195
+ parentValue = parentValue && parentValue[pathParts[x]];
196
+ }
197
+ if (!parentValue)
198
+ throw new Error("Unable to write path: " + path + ". Falsey value found at: " + pathParts.slice(0, x).join("."));
199
+ const prop = pathParts[x];
200
+ parentValue[prop] = value;
201
+ const leafScopes = this.leafScopeCache.get(parentValue);
202
+ return leafScopes && leafScopes[prop] || this.scopeCache.get(parentValue);
203
+ }
204
+ UpdatePathCache(path, value) {
205
+ const type = TypeOf(value);
206
+ if (type === Type.Value)
207
+ return;
208
+ this.pathCache.set(value, path);
209
+ const keys = Object.keys(value);
210
+ for (let x = 0; x < keys.length; x++)
211
+ this.UpdatePathCache(`${path}.${keys[x]}`, value[keys[x]]);
212
+ return value;
213
+ }
90
214
  }
91
215
  exports.ObservableTree = ObservableTree;
@@ -7,7 +7,7 @@ class AsyncQueue {
7
7
  this.queue = list_1.List.Create();
8
8
  }
9
9
  Next(callback) {
10
- const ret = new Promise(async function (resolve, reject) {
10
+ const ret = new Promise((resolve, reject) => {
11
11
  list_1.List.Add(this.queue, async function () {
12
12
  try {
13
13
  const ret = await callback();
package/Utils/thread.d.ts CHANGED
@@ -13,4 +13,4 @@ export declare function Thread(callback: {
13
13
  }): void;
14
14
  export declare function ThreadAsync(callback: {
15
15
  (): void;
16
- }): Promise<unknown>;
16
+ }): Promise<void>;