j-templates 7.0.53 → 7.0.54

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.
@@ -8,13 +8,14 @@ function CreateAssignment(target, createAssignment) {
8
8
  if (next === last)
9
9
  return;
10
10
  last = next;
11
- const nextKeys = next && Object.keys(next);
12
- for (let x = 0; nextKeys && x < nextKeys.length; x++) {
13
- const key = nextKeys[x];
14
- writeTo[key] ??= createAssignment(target, key);
11
+ for (const key in writeTo) {
12
+ writeTo[key](next);
13
+ }
14
+ for (const key in next) {
15
+ if (!Object.hasOwn(writeTo, key)) {
16
+ writeTo[key] = createAssignment(target, key);
17
+ writeTo[key](next);
18
+ }
15
19
  }
16
- const writeFunctions = Object.values(writeTo);
17
- for (let x = 0; x < writeFunctions.length; x++)
18
- writeFunctions[x](next);
19
20
  };
20
21
  }
@@ -1,4 +1 @@
1
1
  export declare function CreateEventAssignment(target: HTMLElement, event: string): (next: any) => void;
2
- export declare function AssignEvents(target: HTMLElement, eventMap: {
3
- [event: string]: any;
4
- }): void;
@@ -1,7 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.CreateEventAssignment = CreateEventAssignment;
4
- exports.AssignEvents = AssignEvents;
5
4
  function CreateEventAssignment(target, event) {
6
5
  let lastEvent;
7
6
  return function (next) {
@@ -13,8 +12,3 @@ function CreateEventAssignment(target, event) {
13
12
  lastEvent = nextEvent;
14
13
  };
15
14
  }
16
- function AssignEvents(target, eventMap) {
17
- const entries = Object.entries(eventMap);
18
- for (let x = 0; x < entries.length; x++)
19
- target.addEventListener(entries[x][0], entries[x][1]);
20
- }
@@ -1,7 +1 @@
1
- export declare function CreateNodeValueAssignment(target: HTMLElement): (value: string) => void;
2
- export declare function CreatePropertyAssignment(target: any): ((next: {
3
- nodeValue: string;
4
- }) => void) | ((next: {
5
- [prop: string]: any;
6
- }) => void);
7
- export declare function AssignProperties(target: any, next: any): void;
1
+ export declare function CreateRootPropertyAssignment(target: HTMLElement, property: string): (next: any) => void;
@@ -1,34 +1,65 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.CreateNodeValueAssignment = CreateNodeValueAssignment;
4
- exports.CreatePropertyAssignment = CreatePropertyAssignment;
5
- exports.AssignProperties = AssignProperties;
3
+ exports.CreateRootPropertyAssignment = CreateRootPropertyAssignment;
6
4
  const json_1 = require("../Utils/json");
7
- function CreateNodeValueAssignment(target) {
8
- let lastValue = target.nodeValue;
9
- return function AssignNodeValue(value) {
10
- if (value !== lastValue) {
11
- target.nodeValue = value;
12
- lastValue = value;
5
+ const createAssignment_1 = require("./createAssignment");
6
+ function CreatePropertyAssignment(target, property) {
7
+ let lastValue;
8
+ let jsonType;
9
+ let childAssignment;
10
+ return function (next) {
11
+ const nextValue = next && next[property];
12
+ if (nextValue === lastValue)
13
+ return;
14
+ jsonType ??= (0, json_1.JsonType)(nextValue);
15
+ switch (jsonType) {
16
+ case "value":
17
+ target[property] = nextValue;
18
+ break;
19
+ default: {
20
+ const childTarget = target[property];
21
+ childAssignment ??= (0, createAssignment_1.CreateAssignment)(childTarget, CreateRootPropertyAssignment);
22
+ childAssignment(nextValue);
23
+ }
13
24
  }
14
25
  };
15
26
  }
16
- function WalkValue(next, callback, index = 0, parent = "") {
17
- const entries = Object.entries(next);
18
- for (let x = 0; x < entries.length; x++) {
19
- const [key, value] = entries[x];
20
- const type = (0, json_1.JsonType)(value);
21
- switch (type) {
22
- case "object":
23
- index = WalkValue(value, callback, index, `${parent}${key}.`);
27
+ function CreateRootPropertyAssignment(target, property) {
28
+ let lastValue;
29
+ let jsonType;
30
+ let childAssignment;
31
+ return function (next) {
32
+ const nextValue = next && next[property];
33
+ if (nextValue === lastValue)
34
+ return;
35
+ switch (property) {
36
+ case "nodeValue": {
37
+ AssignNodeValue(target, nextValue);
38
+ break;
39
+ }
40
+ case "className": {
41
+ AssignClassName(target, nextValue);
24
42
  break;
25
- default:
26
- callback(`${parent}${key}`, value, index);
27
- index++;
43
+ }
44
+ case "value": {
45
+ AssignValue(target, nextValue);
28
46
  break;
47
+ }
48
+ default: {
49
+ jsonType ??= (0, json_1.JsonType)(nextValue);
50
+ switch (jsonType) {
51
+ case "value":
52
+ target[property] = nextValue;
53
+ break;
54
+ default: {
55
+ const childTarget = target[property];
56
+ childAssignment ??= (0, createAssignment_1.CreateAssignment)(childTarget, CreatePropertyAssignment);
57
+ childAssignment(nextValue);
58
+ }
59
+ }
60
+ }
29
61
  }
30
- }
31
- return index;
62
+ };
32
63
  }
33
64
  function AssignNodeValue(target, value) {
34
65
  target.nodeValue = value;
@@ -43,53 +74,3 @@ function AssignValue(target, value) {
43
74
  function AssignClassName(target, value) {
44
75
  target.className = value;
45
76
  }
46
- function GetAssignmentFunction(path) {
47
- switch (path) {
48
- case "nodeValue":
49
- return AssignNodeValue;
50
- case "value":
51
- return AssignValue;
52
- case "className":
53
- return AssignClassName;
54
- default:
55
- return new Function("t", "v", `t.${path} = v;`);
56
- }
57
- }
58
- function CreatePropertyAssignment(target) {
59
- if (target.nodeType === Node.TEXT_NODE) {
60
- return function (next) {
61
- AssignNodeValue(target, next.nodeValue);
62
- };
63
- }
64
- const last = [
65
- ["", null, null],
66
- ];
67
- function WalkCallback(path, value, index) {
68
- if (index >= last.length || last[index][0] !== path) {
69
- last[index] = [path, value, GetAssignmentFunction(path)];
70
- last[index][2](target, value);
71
- }
72
- else if (last[index][1] !== value) {
73
- last[index][1] = value;
74
- last[index][2](target, value);
75
- }
76
- }
77
- return function AssignProperty(next) {
78
- if (next === null) {
79
- for (let x = 0; x < last.length; x++)
80
- last[x][2] !== null && last[x][2](target, null);
81
- if (last.length > 0)
82
- last.splice(0);
83
- return;
84
- }
85
- const endIndex = WalkValue(next, WalkCallback);
86
- if (endIndex < last.length)
87
- last.splice(endIndex);
88
- };
89
- }
90
- function AssignProperties(target, next) {
91
- WalkValue(next, function (path, value) {
92
- const assignment = GetAssignmentFunction(path);
93
- assignment(target, value);
94
- });
95
- }
@@ -6,7 +6,6 @@ const list_1 = require("../Utils/list");
6
6
  const createPropertyAssignment_1 = require("./createPropertyAssignment");
7
7
  const createEventAssignment_1 = require("./createEventAssignment");
8
8
  const createAssignment_1 = require("./createAssignment");
9
- const createPropertyAssignment_2 = require("./createPropertyAssignment");
10
9
  const createAttributeAssignment_1 = require("./createAttributeAssignment");
11
10
  let pendingUpdates = list_1.List.Create();
12
11
  let updateScheduled = false;
@@ -98,9 +97,6 @@ exports.DOMNodeConfig = {
98
97
  remove(target) {
99
98
  target && target.parentNode && target.parentNode.removeChild(target);
100
99
  },
101
- createTextAssignment(target) {
102
- return (0, createPropertyAssignment_1.CreateNodeValueAssignment)(target);
103
- },
104
100
  setText(target, text) {
105
101
  target.nodeValue = text;
106
102
  },
@@ -111,17 +107,11 @@ exports.DOMNodeConfig = {
111
107
  target.setAttribute(attribute, value);
112
108
  },
113
109
  createPropertyAssignment(target) {
114
- return (0, createPropertyAssignment_2.CreatePropertyAssignment)(target);
115
- },
116
- assignProperties(target, next) {
117
- (0, createPropertyAssignment_1.AssignProperties)(target, next);
110
+ return (0, createAssignment_1.CreateAssignment)(target, createPropertyAssignment_1.CreateRootPropertyAssignment);
118
111
  },
119
112
  createEventAssignment(target) {
120
113
  return (0, createAssignment_1.CreateAssignment)(target, createEventAssignment_1.CreateEventAssignment);
121
114
  },
122
- assignEvents(target, next) {
123
- (0, createEventAssignment_1.AssignEvents)(target, next);
124
- },
125
115
  createAttributeAssignment(target) {
126
116
  return (0, createAssignment_1.CreateAssignment)(target, createAttributeAssignment_1.CreateAttributeAssignment);
127
117
  },
@@ -20,19 +20,14 @@ export interface INodeConfig {
20
20
  removeChild(root: any, child: any): void;
21
21
  remove(target: any): void;
22
22
  fireEvent(target: any, event: string, data: any): void;
23
- createTextAssignment(target: any): {
24
- (next: string): void;
25
- };
26
23
  createPropertyAssignment(target: any): {
27
24
  (next: any): void;
28
25
  };
29
- assignProperties(target: any, next: any): void;
30
26
  createEventAssignment(target: any): {
31
27
  (next: {
32
28
  [event: string]: (event: Event) => void;
33
29
  }): void;
34
30
  };
35
- assignEvents(target: any, next: any): void;
36
31
  createAttributeAssignment(target: any): {
37
32
  (next: {
38
33
  [attribute: string]: string;
@@ -56,9 +56,11 @@ function WatchScope(scope) {
56
56
  const emitters = watchState[0];
57
57
  UpdateEmitters(scope, emitters);
58
58
  const calcScopes = watchState[1];
59
- const calcScopeValues = calcScopes && Object.values(calcScopes);
60
- for (let x = 0; calcScopeValues && x < calcScopeValues.length; x++)
61
- calcScopeValues[x] && ObservableScope.Destroy(calcScopeValues[x]);
59
+ if (calcScopes) {
60
+ const calcScopeValues = Object.values(calcScopes);
61
+ for (let x = 0; x < calcScopeValues.length; x++)
62
+ calcScopeValues[x] && ObservableScope.Destroy(calcScopeValues[x]);
63
+ }
62
64
  scope.calcScopes = watchState[2];
63
65
  watchState = parent;
64
66
  return value;
@@ -175,7 +177,7 @@ function DirtyScope(scope) {
175
177
  else if (scope.calc) {
176
178
  const startValue = scope.value;
177
179
  UpdateValue(scope);
178
- startValue !== scope.value && emitter_1.Emitter.Emit(scope.emitter);
180
+ startValue !== scope.value && emitter_1.Emitter.Emit(scope.emitter, scope);
179
181
  }
180
182
  else
181
183
  emitter_1.Emitter.Emit(scope.emitter, scope);
package/Utils/emitter.js CHANGED
@@ -19,16 +19,14 @@ var Emitter;
19
19
  }
20
20
  Emitter.On = On;
21
21
  function Emit(emitter, ...args) {
22
- let removed = false;
22
+ let writePos = 1;
23
23
  for (let x = 1; x < emitter.length; x++) {
24
- if (emitter[x] === null ||
25
- emitter[x](...args) === true) {
26
- removed = true;
27
- emitter[x] = null;
28
- }
24
+ if (emitter[x] !== null &&
25
+ emitter[x](...args) !== true)
26
+ emitter[writePos++] = emitter[x];
29
27
  }
30
- if (removed)
31
- (0, array_1.RemoveNulls)(emitter);
28
+ if (writePos < emitter.length)
29
+ emitter.splice(writePos);
32
30
  }
33
31
  Emitter.Emit = Emit;
34
32
  function Remove(emitter, callback) {
@@ -49,31 +47,27 @@ var Emitter;
49
47
  Emitter.Distinct = Distinct;
50
48
  function DistinctSmall(emitters) {
51
49
  Sort(emitters);
52
- let lastId = emitters[0][0];
53
- let remove = false;
50
+ let writePos = 1;
54
51
  for (let x = 1; x < emitters.length; x++) {
55
- const id = emitters[x][0];
56
- if (lastId === emitters[x][0]) {
57
- emitters[x] = null;
58
- remove = true;
52
+ if (emitters[x][0] !== emitters[writePos - 1][0]) {
53
+ emitters[writePos++] = emitters[x];
59
54
  }
60
- lastId = id;
61
55
  }
62
- remove && (0, array_1.RemoveNulls)(emitters);
56
+ if (writePos < emitters.length)
57
+ emitters.splice(writePos);
63
58
  }
64
59
  function DistinctLarge(emitters) {
65
- let remove = false;
60
+ let writePos = 0;
66
61
  const ids = new Set();
67
62
  for (let x = 0; x < emitters.length; x++) {
68
63
  const id = emitters[x][0];
69
- if (!ids.has(id))
64
+ if (!ids.has(id)) {
70
65
  ids.add(id);
71
- else {
72
- emitters[x] = null;
73
- remove = true;
66
+ emitters[writePos++] = emitters[x];
74
67
  }
75
68
  }
76
- remove && (0, array_1.RemoveNulls)(emitters);
69
+ if (writePos < emitters.length)
70
+ emitters.splice(writePos);
77
71
  Sort(emitters);
78
72
  }
79
73
  function Sort(emitters) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "j-templates",
3
- "version": "7.0.53",
3
+ "version": "7.0.54",
4
4
  "description": "j-templates",
5
5
  "license": "MIT",
6
6
  "repository": "https://github.com/TypesInCode/jTemplates",