j-templates 7.0.44 → 7.0.46

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.
@@ -3,6 +3,7 @@ export declare const IS_OBSERVABLE_NODE = "____isObservableNode";
3
3
  export declare const GET_OBSERVABLE_VALUE = "____getObservableValue";
4
4
  export declare const GET_TO_JSON = "toJSON";
5
5
  export declare namespace ObservableNode {
6
+ function BypassProxy(value: boolean): void;
6
7
  function Create<T>(value: T): T;
7
8
  function Touch(value: unknown, prop?: string | number): void;
8
9
  function ApplyDiff(rootNode: any, diffResult: JsonDiffResult): void;
@@ -4,6 +4,7 @@ exports.ObservableNode = exports.GET_TO_JSON = exports.GET_OBSERVABLE_VALUE = ex
4
4
  const json_1 = require("../../Utils/json");
5
5
  const jsonType_1 = require("../../Utils/jsonType");
6
6
  const observableScope_1 = require("./observableScope");
7
+ let bypassProxy = false;
7
8
  exports.IS_OBSERVABLE_NODE = "____isObservableNode";
8
9
  exports.GET_OBSERVABLE_VALUE = "____getObservableValue";
9
10
  exports.GET_TO_JSON = "toJSON";
@@ -146,6 +147,8 @@ function CreateProxyFactory(alias) {
146
147
  const scope = scopeCache.get(array);
147
148
  array = observableScope_1.ObservableScope.Value(scope);
148
149
  const arrayValue = array[prop];
150
+ if (bypassProxy)
151
+ return arrayValue;
149
152
  if (typeof prop === "symbol")
150
153
  return arrayValue;
151
154
  if (typeof arrayValue === "function")
@@ -221,6 +224,8 @@ function CreateProxyFactory(alias) {
221
224
  case exports.GET_OBSERVABLE_VALUE:
222
225
  return object;
223
226
  default: {
227
+ if (bypassProxy)
228
+ return object[prop];
224
229
  return GetAccessorValue(object, prop);
225
230
  }
226
231
  }
@@ -259,6 +264,10 @@ function CreateProxyFactory(alias) {
259
264
  const DefaultCreateProxy = CreateProxyFactory();
260
265
  var ObservableNode;
261
266
  (function (ObservableNode) {
267
+ function BypassProxy(value) {
268
+ bypassProxy = value;
269
+ }
270
+ ObservableNode.BypassProxy = BypassProxy;
262
271
  function Create(value) {
263
272
  return DefaultCreateProxy(value);
264
273
  }
@@ -6,6 +6,7 @@ const array_1 = require("../../Utils/array");
6
6
  const distinctArray_1 = require("../../Utils/distinctArray");
7
7
  const emitter_1 = require("../../Utils/emitter");
8
8
  const functions_1 = require("../../Utils/functions");
9
+ const observableNode_1 = require("./observableNode");
9
10
  class ObservableScopeValue {
10
11
  get Value() {
11
12
  return ObservableScope.Value(this.scope);
@@ -65,7 +66,7 @@ function CalcScope(callback) {
65
66
  if (watchState !== null)
66
67
  watchState[1].push({
67
68
  getFunction: callback,
68
- value
69
+ value,
69
70
  });
70
71
  return value;
71
72
  }
@@ -157,11 +158,13 @@ function CalcScope(callback) {
157
158
  function DirtyScope(scope) {
158
159
  if (scope.dirty || !scope.getFunction)
159
160
  return;
161
+ observableNode_1.ObservableNode.BypassProxy(true);
160
162
  let dirty = scope.calcFunctions.length === 0;
161
163
  for (let x = 0; !dirty && x < scope.calcFunctions.length; x++) {
162
164
  const calc = scope.calcFunctions[x];
163
165
  dirty = dirty || calc.value !== calc.getFunction();
164
166
  }
167
+ observableNode_1.ObservableNode.BypassProxy(false);
165
168
  scope.dirty = dirty;
166
169
  if (!scope.dirty)
167
170
  return;
@@ -171,10 +174,10 @@ function DirtyScope(scope) {
171
174
  else
172
175
  emitter_1.Emitter.Emit(scope.emitter, scope);
173
176
  }
174
- const scopeQueue = new Set();
177
+ const scopeQueue = distinctArray_1.DistinctArray.Create();
175
178
  function ProcessScopeQueue() {
176
- const scopes = Array.from(scopeQueue);
177
- scopeQueue.clear();
179
+ const scopes = distinctArray_1.DistinctArray.Get(scopeQueue);
180
+ distinctArray_1.DistinctArray.Clear(scopeQueue);
178
181
  for (let x = 0; x < scopes.length; x++)
179
182
  DirtyScope(scopes[x]);
180
183
  }
@@ -182,9 +185,9 @@ function OnSet(scope) {
182
185
  if (scope.destroyed)
183
186
  return true;
184
187
  if (scope.async || scope.calcFunctions.length > 0) {
185
- if (scopeQueue.size === 0)
188
+ if (distinctArray_1.DistinctArray.Size(scopeQueue) === 0)
186
189
  queueMicrotask(ProcessScopeQueue);
187
- scopeQueue.add(scope);
190
+ distinctArray_1.DistinctArray.Push(scopeQueue, scope);
188
191
  return;
189
192
  }
190
193
  DirtyScope(scope);
@@ -4,7 +4,9 @@ export type DistinctArray<T> = {
4
4
  array: T[];
5
5
  };
6
6
  export declare namespace DistinctArray {
7
- function Create<T>(id: (value: T) => unknown): DistinctArray<T>;
7
+ function Create<T>(id?: (value: T) => unknown): DistinctArray<T>;
8
8
  function Push<T>(distinctArr: DistinctArray<T>, value: T): void;
9
9
  function Get<T>({ array }: DistinctArray<T>): T[];
10
+ function Size<T>(distinct: DistinctArray<T>): number;
11
+ function Clear<T>(distinct: DistinctArray<T>): void;
10
12
  }
@@ -3,11 +3,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.DistinctArray = void 0;
4
4
  var DistinctArray;
5
5
  (function (DistinctArray) {
6
- function Create(id) {
6
+ function Create(id = (val) => val) {
7
7
  return {
8
8
  id,
9
9
  distinct: null,
10
- array: []
10
+ array: [],
11
11
  };
12
12
  }
13
13
  DistinctArray.Create = Create;
@@ -18,7 +18,9 @@ var DistinctArray;
18
18
  break;
19
19
  case 1: {
20
20
  if (distinctArr.distinct === null) {
21
- distinctArr.distinct = new Set([distinctArr.id(distinctArr.array[0])]);
21
+ distinctArr.distinct = new Set([
22
+ distinctArr.id(distinctArr.array[0]),
23
+ ]);
22
24
  }
23
25
  }
24
26
  default: {
@@ -35,4 +37,13 @@ var DistinctArray;
35
37
  return array;
36
38
  }
37
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;
38
49
  })(DistinctArray || (exports.DistinctArray = DistinctArray = {}));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "j-templates",
3
- "version": "7.0.44",
3
+ "version": "7.0.46",
4
4
  "description": "j-templates",
5
5
  "license": "MIT",
6
6
  "repository": "https://github.com/TypesInCode/jTemplates",