j-templates 7.0.71 → 7.0.72

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.
@@ -23,15 +23,14 @@ function CreateDynamicScope(getFunction, greedy, value) {
23
23
  dirty: false,
24
24
  destroyed: false,
25
25
  getFunction,
26
- setCallback: function () {
27
- return OnSet(scope);
28
- },
26
+ setCallback: null,
29
27
  value,
30
28
  emitter: emitter_1.Emitter.Create(),
31
29
  emitters: null,
32
30
  onDestroyed: null,
33
31
  calcScopes: null,
34
32
  };
33
+ scope.setCallback = OnSet.bind(scope);
35
34
  return scope;
36
35
  }
37
36
  /**
@@ -80,18 +79,15 @@ function OnSetQueued(scope) {
80
79
  * @param scope The scope to mark for update.
81
80
  * @returns true if the scope is static or destroyed, false if queued or non-greedy scope emitted.
82
81
  */
83
- function OnSet(scope) {
84
- if (scope.type === "static" || scope.destroyed)
85
- return true;
86
- if (scope.dirty)
87
- return false;
88
- scope.dirty = true;
89
- if (scope.greedy) {
90
- OnSetQueued(scope);
82
+ function OnSet() {
83
+ if (this.dirty)
84
+ return;
85
+ this.dirty = true;
86
+ if (this.greedy) {
87
+ OnSetQueued(this);
91
88
  return;
92
89
  }
93
- emitter_1.Emitter.Emit(scope.emitter, scope);
94
- return false;
90
+ emitter_1.Emitter.Emit(this.emitter, this);
95
91
  }
96
92
  /**
97
93
  * Registers an emitter using SAME_STRATEGY.
@@ -401,9 +397,9 @@ function DestroyAllScopes(scopes) {
401
397
  function DestroyScope(scope) {
402
398
  if (!scope || scope.type === "static")
403
399
  return;
404
- emitter_1.Emitter.Clear(scope.emitter);
405
- const scopes = scope.calcScopes && Object.values(scope.calcScopes);
406
- scopes && DestroyAllScopes(scopes);
400
+ emitter_1.Emitter.Destroy(scope.emitter);
401
+ for (const key in scope.calcScopes)
402
+ DestroyScope(scope.calcScopes[key]);
407
403
  scope.calcScopes = null;
408
404
  for (let x = 0; x < scope.emitters.length; x++)
409
405
  emitter_1.Emitter.Remove(scope.emitters[x], scope.setCallback);
@@ -513,9 +509,10 @@ var ObservableScope;
513
509
  * @param scope The scope to mark for update.
514
510
  */
515
511
  function Update(scope) {
516
- if (!scope)
512
+ if (!scope || scope.type === "static")
517
513
  return;
518
- OnSet(scope);
514
+ // OnSet(scope);
515
+ scope.setCallback();
519
516
  }
520
517
  ObservableScope.Update = Update;
521
518
  /**
@@ -1,10 +1,11 @@
1
- export type EmitterCallback<T extends readonly any[] = any[]> = (...args: T) => boolean | void;
1
+ export type EmitterCallback<T extends readonly any[] = any[]> = (...args: T) => void;
2
2
  export type Emitter = [number, ...EmitterCallback[]];
3
3
  export declare namespace Emitter {
4
4
  function Create(): Emitter;
5
5
  function GetId(emitter: Emitter): number;
6
6
  function On(emitter: Emitter, callback: EmitterCallback): void;
7
7
  function Emit(emitter: Emitter, ...args: any[]): void;
8
+ function Destroy(emitter: Emitter): void;
8
9
  function Remove(emitter: Emitter, callback: EmitterCallback): void;
9
10
  function Clear(emitter: Emitter): void;
10
11
  function Distinct(emitters: Emitter[]): void;
package/Utils/emitter.js CHANGED
@@ -19,17 +19,26 @@ var Emitter;
19
19
  }
20
20
  Emitter.On = On;
21
21
  function Emit(emitter, ...args) {
22
+ if (emitter[0] === -1)
23
+ return;
22
24
  let writePos = 1;
23
25
  for (let x = 1; x < emitter.length; x++) {
24
- if (emitter[x] !== null &&
25
- emitter[x](...args) !== true)
26
+ if (emitter[x] !== null) {
27
+ emitter[x](...args);
26
28
  emitter[writePos++] = emitter[x];
29
+ }
27
30
  }
28
31
  if (writePos < emitter.length)
29
32
  emitter.splice(writePos);
30
33
  }
31
34
  Emitter.Emit = Emit;
35
+ function Destroy(emitter) {
36
+ emitter[0] = -1;
37
+ }
38
+ Emitter.Destroy = Destroy;
32
39
  function Remove(emitter, callback) {
40
+ if (emitter[0] === -1)
41
+ return;
33
42
  const index = emitter.indexOf(callback);
34
43
  if (index >= 1)
35
44
  emitter[index] = null;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "j-templates",
3
- "version": "7.0.71",
3
+ "version": "7.0.72",
4
4
  "description": "j-templates",
5
5
  "license": "MIT",
6
6
  "repository": "https://github.com/TypesInCode/jTemplates",