j-templates 7.0.69 → 7.0.70
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.
- package/DOM/domNodeConfig.js +5 -4
- package/Node/component.d.ts +0 -8
- package/Node/component.js +1 -42
- package/Node/vNode.js +1 -41
- package/Store/Tree/observableScope.js +109 -67
- package/Utils/decorators.js +0 -10
- package/Utils/emitter.js +1 -19
- package/package.json +1 -1
package/DOM/domNodeConfig.js
CHANGED
|
@@ -169,9 +169,10 @@ exports.DOMNodeConfig = {
|
|
|
169
169
|
target.appendChild(children[x]);
|
|
170
170
|
},
|
|
171
171
|
reconcileChild(target, child) {
|
|
172
|
-
if (target.
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
172
|
+
if (target.firstChild === child)
|
|
173
|
+
return;
|
|
174
|
+
target.appendChild(child);
|
|
175
|
+
while (target.firstChild !== child)
|
|
176
|
+
target.removeChild(target.firstChild);
|
|
176
177
|
},
|
|
177
178
|
};
|
package/Node/component.d.ts
CHANGED
|
@@ -38,14 +38,6 @@ export declare class Component<D = void, T = void, E = {}> {
|
|
|
38
38
|
* Accessor for the component's template collection.
|
|
39
39
|
*/
|
|
40
40
|
protected get Templates(): T;
|
|
41
|
-
/**
|
|
42
|
-
* Creates a new Component instance. Not intended to be overriden.
|
|
43
|
-
*
|
|
44
|
-
* @param data - Initial data or a factory function returning data/promise.
|
|
45
|
-
* @param templates - Template definitions for rendering.
|
|
46
|
-
* @param vNode - The underlying virtual node instance.
|
|
47
|
-
* @param componentEvents - Optional event callbacks.
|
|
48
|
-
*/
|
|
49
41
|
constructor(vNode: vNodeType, config: vComponentConfig<D, E>, templates: T);
|
|
50
42
|
/**
|
|
51
43
|
* Returns the component's rendered vNode(s).
|
package/Node/component.js
CHANGED
|
@@ -48,32 +48,9 @@ class Component {
|
|
|
48
48
|
get Templates() {
|
|
49
49
|
return this.templates;
|
|
50
50
|
}
|
|
51
|
-
/**
|
|
52
|
-
* Creates a new Component instance. Not intended to be overriden.
|
|
53
|
-
*
|
|
54
|
-
* @param data - Initial data or a factory function returning data/promise.
|
|
55
|
-
* @param templates - Template definitions for rendering.
|
|
56
|
-
* @param vNode - The underlying virtual node instance.
|
|
57
|
-
* @param componentEvents - Optional event callbacks.
|
|
58
|
-
*/
|
|
59
|
-
/* constructor(
|
|
60
|
-
data: D | (() => D | Promise<D>),
|
|
61
|
-
templates: T,
|
|
62
|
-
private vNode: vNodeType,
|
|
63
|
-
private componentEvents: ComponentEvents<E>,
|
|
64
|
-
) {
|
|
65
|
-
if (typeof data === "function")
|
|
66
|
-
this.scope = new ObservableScope<D>(data as () => D | Promise<D>);
|
|
67
|
-
else this.scope = new ObservableScope<D>(() => data);
|
|
68
|
-
|
|
69
|
-
this.templates = templates || ({} as T);
|
|
70
|
-
} */
|
|
71
51
|
constructor(vNode, config, templates) {
|
|
72
52
|
this.vNode = vNode;
|
|
73
53
|
const { data, on } = config;
|
|
74
|
-
/* if (typeof data === "function")
|
|
75
|
-
this.scope = new ObservableScope<D>(data as () => D | Promise<D>);
|
|
76
|
-
else this.scope = new ObservableScope<D>(() => data); */
|
|
77
54
|
if (typeof data === "function")
|
|
78
55
|
this.scope = Store_1.ObservableScope.Create(data);
|
|
79
56
|
else
|
|
@@ -119,30 +96,13 @@ class Component {
|
|
|
119
96
|
}
|
|
120
97
|
}
|
|
121
98
|
exports.Component = Component;
|
|
122
|
-
/* type ComponentConstructor<D, T, E> = {
|
|
123
|
-
new (
|
|
124
|
-
data: D | (() => D | Promise<D>),
|
|
125
|
-
templates: T,
|
|
126
|
-
vNode: vNodeType,
|
|
127
|
-
componentEvents: ComponentEvents<E>,
|
|
128
|
-
): Component<D, T, E>;
|
|
129
|
-
}; */
|
|
130
99
|
(function (Component) {
|
|
131
100
|
/**
|
|
132
101
|
* Function wraps the Component as a function that can be used to create vNode objects
|
|
133
102
|
* and generate templates.
|
|
134
103
|
*/
|
|
135
|
-
function ToFunction(type,
|
|
136
|
-
// constructor: ComponentConstructor<D, T, E>,
|
|
137
|
-
constructor, namespace) {
|
|
104
|
+
function ToFunction(type, constructor, namespace) {
|
|
138
105
|
return function (config, templates) {
|
|
139
|
-
/* const { data, on, props } = config;
|
|
140
|
-
|
|
141
|
-
class ConcreteComponent extends constructor {
|
|
142
|
-
constructor(vnode: vNodeType) {
|
|
143
|
-
super(data, templates, vnode, on);
|
|
144
|
-
}
|
|
145
|
-
} */
|
|
146
106
|
function ComponentFactory(vnode) {
|
|
147
107
|
return new constructor(vnode, config, templates);
|
|
148
108
|
}
|
|
@@ -151,7 +111,6 @@ exports.Component = Component;
|
|
|
151
111
|
namespace: namespace ?? null,
|
|
152
112
|
props: config.props,
|
|
153
113
|
componentFactory: ComponentFactory,
|
|
154
|
-
// componentConstructor: ConcreteComponent,
|
|
155
114
|
};
|
|
156
115
|
return vNode_1.vNode.Create(definition);
|
|
157
116
|
};
|
package/Node/vNode.js
CHANGED
|
@@ -14,7 +14,6 @@ var vNode;
|
|
|
14
14
|
return {
|
|
15
15
|
definition,
|
|
16
16
|
type: definition.type,
|
|
17
|
-
// injector: definition.componentConstructor
|
|
18
17
|
injector: definition.componentFactory
|
|
19
18
|
? injector_1.Injector.Scope(injector_1.Injector.Current(), function () {
|
|
20
19
|
return new injector_1.Injector();
|
|
@@ -95,9 +94,7 @@ var vNode;
|
|
|
95
94
|
vNode.Attach = Attach;
|
|
96
95
|
})(vNode || (exports.vNode = vNode = {}));
|
|
97
96
|
function InitNode(vnode) {
|
|
98
|
-
const { type, namespace, props, attrs, on, data,
|
|
99
|
-
// componentConstructor,
|
|
100
|
-
componentFactory, children, childrenArray, } = vnode.definition;
|
|
97
|
+
const { type, namespace, props, attrs, on, data, componentFactory, children, childrenArray, } = vnode.definition;
|
|
101
98
|
const node = (vnode.node =
|
|
102
99
|
vnode.definition.node ?? nodeConfig_1.NodeConfig.createNode(type, namespace));
|
|
103
100
|
vnode.definition = null;
|
|
@@ -105,11 +102,8 @@ function InitNode(vnode) {
|
|
|
105
102
|
const assignProperties = nodeConfig_1.NodeConfig.createPropertyAssignment(node);
|
|
106
103
|
if (typeof props === "function") {
|
|
107
104
|
const scope = Store_1.ObservableScope.Create(props);
|
|
108
|
-
// const [value, scope] = ObservableScope.CreateIf(props as () => any);
|
|
109
|
-
// if (scope) {
|
|
110
105
|
vnode.scopes.push(scope);
|
|
111
106
|
Store_1.ObservableScope.Watch(scope, ScheduledAssignment(assignProperties));
|
|
112
|
-
// }
|
|
113
107
|
assignProperties(Store_1.ObservableScope.Value(scope));
|
|
114
108
|
}
|
|
115
109
|
else
|
|
@@ -119,11 +113,8 @@ function InitNode(vnode) {
|
|
|
119
113
|
const assignEvents = nodeConfig_1.NodeConfig.createEventAssignment(node);
|
|
120
114
|
if (typeof on === "function") {
|
|
121
115
|
const scope = Store_1.ObservableScope.Create(on);
|
|
122
|
-
// const [value, scope] = ObservableScope.CreateIf(on);
|
|
123
|
-
// if (scope) {
|
|
124
116
|
vnode.scopes.push(scope);
|
|
125
117
|
Store_1.ObservableScope.Watch(scope, ScheduledAssignment(assignEvents));
|
|
126
|
-
// }
|
|
127
118
|
assignEvents(Store_1.ObservableScope.Value(scope));
|
|
128
119
|
}
|
|
129
120
|
else
|
|
@@ -133,19 +124,14 @@ function InitNode(vnode) {
|
|
|
133
124
|
const assignAttributes = nodeConfig_1.NodeConfig.createAttributeAssignment(node);
|
|
134
125
|
if (typeof attrs === "function") {
|
|
135
126
|
const scope = Store_1.ObservableScope.Create(attrs);
|
|
136
|
-
// const [value, scope] = ObservableScope.CreateIf(attrs);
|
|
137
|
-
// if (scope) {
|
|
138
127
|
vnode.scopes.push(scope);
|
|
139
128
|
Store_1.ObservableScope.Watch(scope, ScheduledAssignment(assignAttributes));
|
|
140
|
-
//}
|
|
141
129
|
assignAttributes(Store_1.ObservableScope.Value(scope));
|
|
142
130
|
}
|
|
143
131
|
else
|
|
144
132
|
assignAttributes(attrs);
|
|
145
133
|
}
|
|
146
|
-
// if (componentConstructor) {
|
|
147
134
|
if (componentFactory) {
|
|
148
|
-
// vnode.component = new componentConstructor(vnode);
|
|
149
135
|
vnode.component = componentFactory(vnode);
|
|
150
136
|
vnode.component.Bound();
|
|
151
137
|
function componentChildren() {
|
|
@@ -171,7 +157,6 @@ function Children(vnode, children, data) {
|
|
|
171
157
|
return;
|
|
172
158
|
const startChildren = vnode.children;
|
|
173
159
|
const newChildren = Store_1.ObservableScope.Value(scope);
|
|
174
|
-
// AssignChildren(vnode, scope);
|
|
175
160
|
if (startChildren !== newChildren) {
|
|
176
161
|
vnode.children = newChildren;
|
|
177
162
|
UpdateChildren(vnode);
|
|
@@ -179,21 +164,7 @@ function Children(vnode, children, data) {
|
|
|
179
164
|
}));
|
|
180
165
|
}
|
|
181
166
|
vnode.children = Store_1.ObservableScope.Value(childrenScope);
|
|
182
|
-
// AssignChildren(vnode, childrenScope);
|
|
183
167
|
}
|
|
184
|
-
/* function AssignChildren(
|
|
185
|
-
vnode: vNodeType,
|
|
186
|
-
childrenScope: IObservableScope<
|
|
187
|
-
[
|
|
188
|
-
any,
|
|
189
|
-
vNodeType[],
|
|
190
|
-
IObservableScope<string | vNodeType | vNodeType[]> | null,
|
|
191
|
-
][]
|
|
192
|
-
>,
|
|
193
|
-
) {
|
|
194
|
-
const children = ObservableScope.Peek(childrenScope);
|
|
195
|
-
vnode.children = children;
|
|
196
|
-
} */
|
|
197
168
|
const DEFAULT_DATA = [undefined];
|
|
198
169
|
function DefaultData() {
|
|
199
170
|
return DEFAULT_DATA;
|
|
@@ -302,7 +273,6 @@ function EvaluateNextNodesLarge(injector, getNextChildren, nextData, nodeArray)
|
|
|
302
273
|
if (currentChildIndex !== -1) {
|
|
303
274
|
const currentChild = currentChildren[currentChildIndex];
|
|
304
275
|
currentChildren[currentChildIndex] = null;
|
|
305
|
-
// if (currentChild[2]) {
|
|
306
276
|
const scope = currentChild[2];
|
|
307
277
|
const value = scope.value;
|
|
308
278
|
const updatedValue = Store_1.ObservableScope.Value(scope);
|
|
@@ -310,13 +280,7 @@ function EvaluateNextNodesLarge(injector, getNextChildren, nextData, nodeArray)
|
|
|
310
280
|
vNode.DestroyAll(currentChild[1]);
|
|
311
281
|
currentChild[1] = CreateNodeArray(updatedValue);
|
|
312
282
|
}
|
|
313
|
-
// }
|
|
314
|
-
/* if (currentChild[2]?.dirty) {
|
|
315
|
-
const nextChildren = ObservableScope.Value(currentChild[2]);
|
|
316
|
-
currentChild[1] = CreateNodeArray(nextChildren);
|
|
317
|
-
} */
|
|
318
283
|
nextNodes[x] = currentChild;
|
|
319
|
-
// currentChildren[currentChildIndex] = null;
|
|
320
284
|
if (currentChildIndex === 0)
|
|
321
285
|
dataMap.delete(data);
|
|
322
286
|
}
|
|
@@ -324,9 +288,6 @@ function EvaluateNextNodesLarge(injector, getNextChildren, nextData, nodeArray)
|
|
|
324
288
|
const scope = Store_1.ObservableScope.Create(function () {
|
|
325
289
|
return injector_1.Injector.Scope(injector, getNextChildren, data);
|
|
326
290
|
});
|
|
327
|
-
/* const [nextChildren, scope] = ObservableScope.CreateIf(function () {
|
|
328
|
-
return Injector.Scope(injector, getNextChildren, data);
|
|
329
|
-
}); */
|
|
330
291
|
nextNodes[x] = [
|
|
331
292
|
data,
|
|
332
293
|
CreateNodeArray(Store_1.ObservableScope.Value(scope)),
|
|
@@ -411,7 +372,6 @@ function ScheduledAssignment(assign) {
|
|
|
411
372
|
return;
|
|
412
373
|
scheduled = true;
|
|
413
374
|
nodeConfig_1.NodeConfig.scheduleUpdate(function () {
|
|
414
|
-
// if (scope.destroyed) return;
|
|
415
375
|
scheduled = false;
|
|
416
376
|
const value = Store_1.ObservableScope.Peek(scope);
|
|
417
377
|
assign(value);
|
|
@@ -5,6 +5,7 @@ exports.CalcScope = CalcScope;
|
|
|
5
5
|
const array_1 = require("../../Utils/array");
|
|
6
6
|
const emitter_1 = require("../../Utils/emitter");
|
|
7
7
|
const functions_1 = require("../../Utils/functions");
|
|
8
|
+
const list_1 = require("../../Utils/list");
|
|
8
9
|
/**
|
|
9
10
|
* Creates a dynamic (reactive) observable scope.
|
|
10
11
|
* @template T The type of value stored in the scope.
|
|
@@ -83,44 +84,53 @@ function OnSet(scope) {
|
|
|
83
84
|
emitter_1.Emitter.Emit(scope.emitter, scope);
|
|
84
85
|
return false;
|
|
85
86
|
}
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
*/
|
|
91
|
-
function RegisterEmitter(emitter) {
|
|
92
|
-
if (watchState === null)
|
|
93
|
-
return;
|
|
94
|
-
if (watchState.emitterIndex !== null &&
|
|
95
|
-
watchState.emitters[watchState.emitterIndex] === emitter) {
|
|
96
|
-
watchState.emitterIndex++;
|
|
97
|
-
return;
|
|
98
|
-
}
|
|
99
|
-
else if (watchState.emitterIndex !== null) {
|
|
100
|
-
const index = watchState.emitterIndex;
|
|
101
|
-
watchState.emitterIndex = null;
|
|
102
|
-
watchState.emitters = watchState.emitters.slice(0, index);
|
|
103
|
-
}
|
|
104
|
-
if (watchState.emitterIds) {
|
|
105
|
-
if (!watchState.emitterIds.has(emitter[0])) {
|
|
106
|
-
watchState.emitters.push(emitter);
|
|
107
|
-
watchState.emitterIds.add(emitter[0]);
|
|
108
|
-
}
|
|
87
|
+
function RegisterSame(state, emitter) {
|
|
88
|
+
if (state.emitterIndex < state.emitters.length &&
|
|
89
|
+
state.emitters[state.emitterIndex] === emitter) {
|
|
90
|
+
state.emitterIndex++;
|
|
109
91
|
return;
|
|
110
92
|
}
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
93
|
+
state.emitters = state.emitters.slice(0, state.emitterIndex);
|
|
94
|
+
state.emitters.push(emitter);
|
|
95
|
+
state.emitterIndex = -1;
|
|
96
|
+
state.strategy = PUSH_STRATEGY;
|
|
97
|
+
}
|
|
98
|
+
function RegisterPush(state, emitter) {
|
|
99
|
+
state.emitters.push(emitter);
|
|
100
|
+
if (state.emitters.length > 50) {
|
|
101
|
+
const idSet = (state.emitterIds = new Set([state.emitters[0][0]]));
|
|
114
102
|
let writePos = 0;
|
|
115
|
-
for (let x = 1; x <
|
|
116
|
-
if (!idSet.has(
|
|
117
|
-
|
|
118
|
-
idSet.add(
|
|
103
|
+
for (let x = 1; x < state.emitters.length; x++) {
|
|
104
|
+
if (!idSet.has(state.emitters[x][0])) {
|
|
105
|
+
state.emitters[++writePos] = state.emitters[x];
|
|
106
|
+
idSet.add(state.emitters[x][0]);
|
|
119
107
|
}
|
|
120
108
|
}
|
|
121
109
|
writePos++;
|
|
122
|
-
if (writePos <
|
|
123
|
-
|
|
110
|
+
if (writePos < state.emitters.length)
|
|
111
|
+
state.emitters.splice(writePos);
|
|
112
|
+
state.strategy = DISTINCT_STRATEGY;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
function RegisterDistinct(state, emitter) {
|
|
116
|
+
if (!state.emitterIds.has(emitter[0])) {
|
|
117
|
+
state.emitters.push(emitter);
|
|
118
|
+
state.emitterIds.add(emitter[0]);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
function RegisterEmitter(emitter) {
|
|
122
|
+
if (watchState === null)
|
|
123
|
+
return;
|
|
124
|
+
switch (watchState.strategy) {
|
|
125
|
+
case SAME_STRATEGY:
|
|
126
|
+
RegisterSame(watchState, emitter);
|
|
127
|
+
break;
|
|
128
|
+
case PUSH_STRATEGY:
|
|
129
|
+
RegisterPush(watchState, emitter);
|
|
130
|
+
break;
|
|
131
|
+
case DISTINCT_STRATEGY:
|
|
132
|
+
RegisterDistinct(watchState, emitter);
|
|
133
|
+
break;
|
|
124
134
|
}
|
|
125
135
|
}
|
|
126
136
|
/**
|
|
@@ -144,7 +154,33 @@ function GetScopeValue(scope) {
|
|
|
144
154
|
ExecuteScope(scope);
|
|
145
155
|
return scope.value;
|
|
146
156
|
}
|
|
157
|
+
const SAME_STRATEGY = 1;
|
|
158
|
+
const PUSH_STRATEGY = 2;
|
|
159
|
+
const DISTINCT_STRATEGY = 3;
|
|
160
|
+
const SHRINK_STRATEGY = 4;
|
|
147
161
|
let watchState = null;
|
|
162
|
+
const watchPool = list_1.List.Create();
|
|
163
|
+
function CreateWatchState() {
|
|
164
|
+
return (list_1.List.Pop(watchPool) ?? {
|
|
165
|
+
emitterIndex: 0,
|
|
166
|
+
value: null,
|
|
167
|
+
emitters: null,
|
|
168
|
+
emitterIds: null,
|
|
169
|
+
currentCalc: null,
|
|
170
|
+
nextCalc: null,
|
|
171
|
+
strategy: PUSH_STRATEGY,
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
function ReturnWatchState(state) {
|
|
175
|
+
state.emitterIndex = 0;
|
|
176
|
+
state.value = null;
|
|
177
|
+
state.emitters = null;
|
|
178
|
+
state.emitterIds = null;
|
|
179
|
+
state.currentCalc = null;
|
|
180
|
+
state.nextCalc = null;
|
|
181
|
+
state.strategy = PUSH_STRATEGY;
|
|
182
|
+
list_1.List.Push(watchPool, state);
|
|
183
|
+
}
|
|
148
184
|
/**
|
|
149
185
|
* Executes a callback while tracking all scope and emitter dependencies.
|
|
150
186
|
* Creates a watch context that records what was accessed during execution.
|
|
@@ -152,22 +188,21 @@ let watchState = null;
|
|
|
152
188
|
* @param currentCalc Optional map of existing calc scopes to reuse.
|
|
153
189
|
* @returns The watch state containing tracked dependencies and result.
|
|
154
190
|
*/
|
|
155
|
-
function WatchFunction(callback, currentCalc
|
|
191
|
+
function WatchFunction(callback, currentCalc, initialEmitters) {
|
|
156
192
|
const parent = watchState;
|
|
157
|
-
watchState =
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
currentCalc: currentCalc,
|
|
163
|
-
nextCalc: null,
|
|
164
|
-
};
|
|
193
|
+
watchState = CreateWatchState();
|
|
194
|
+
watchState.emitters = initialEmitters ?? [];
|
|
195
|
+
watchState.currentCalc = currentCalc;
|
|
196
|
+
if (initialEmitters !== null)
|
|
197
|
+
watchState.strategy = SAME_STRATEGY;
|
|
165
198
|
watchState.value = callback();
|
|
166
199
|
const resultState = watchState;
|
|
167
200
|
watchState = parent;
|
|
168
|
-
if (resultState.
|
|
169
|
-
resultState.emitterIndex < resultState.emitters.length)
|
|
201
|
+
if (resultState.strategy === SAME_STRATEGY &&
|
|
202
|
+
resultState.emitterIndex < resultState.emitters.length) {
|
|
170
203
|
resultState.emitters = resultState.emitters.slice(0, resultState.emitterIndex);
|
|
204
|
+
resultState.strategy = SHRINK_STRATEGY;
|
|
205
|
+
}
|
|
171
206
|
return resultState;
|
|
172
207
|
}
|
|
173
208
|
/**
|
|
@@ -178,8 +213,7 @@ function WatchFunction(callback, currentCalc = null, initialEmitters = []) {
|
|
|
178
213
|
function ExecuteScope(scope) {
|
|
179
214
|
scope.dirty = false;
|
|
180
215
|
const state = WatchFunction(scope.getFunction, scope.calcScopes, scope.emitters);
|
|
181
|
-
|
|
182
|
-
UpdateEmitters(scope, state.emitters, !!state.emitterIds);
|
|
216
|
+
UpdateEmitters(scope, state.emitters, state.strategy);
|
|
183
217
|
const calcScopes = state.currentCalc;
|
|
184
218
|
scope.calcScopes = state.nextCalc;
|
|
185
219
|
for (const key in calcScopes)
|
|
@@ -191,6 +225,7 @@ function ExecuteScope(scope) {
|
|
|
191
225
|
});
|
|
192
226
|
else
|
|
193
227
|
scope.value = state.value;
|
|
228
|
+
ReturnWatchState(state);
|
|
194
229
|
}
|
|
195
230
|
/**
|
|
196
231
|
* Creates a scope from a function, choosing between static and dynamic based on dependencies.
|
|
@@ -202,19 +237,22 @@ function ExecuteScope(scope) {
|
|
|
202
237
|
*/
|
|
203
238
|
function ExecuteFunction(callback, greedy, allowStatic) {
|
|
204
239
|
const async = (0, functions_1.IsAsync)(callback);
|
|
205
|
-
const state = WatchFunction(callback);
|
|
206
|
-
if (!allowStatic || async || state.emitters
|
|
240
|
+
const state = WatchFunction(callback, null, null);
|
|
241
|
+
if (!allowStatic || async || state.emitters !== null) {
|
|
207
242
|
const scope = CreateDynamicScope(callback, greedy, async ? null : state.value);
|
|
208
243
|
scope.calcScopes = state.nextCalc;
|
|
209
|
-
UpdateEmitters(scope, state.emitters,
|
|
244
|
+
UpdateEmitters(scope, state.emitters, state.strategy);
|
|
210
245
|
if (async)
|
|
211
246
|
state.value.then(function (result) {
|
|
212
247
|
scope.value = result;
|
|
213
248
|
emitter_1.Emitter.Emit(scope.emitter, scope);
|
|
214
249
|
});
|
|
250
|
+
ReturnWatchState(state);
|
|
215
251
|
return scope;
|
|
216
252
|
}
|
|
217
|
-
|
|
253
|
+
const value = state.value;
|
|
254
|
+
ReturnWatchState(state);
|
|
255
|
+
return CreateStaticScope(value);
|
|
218
256
|
}
|
|
219
257
|
/**
|
|
220
258
|
* Creates a computed scope that acts as a gatekeeper for parent scope emissions.
|
|
@@ -254,27 +292,31 @@ function CalcScope(callback, idOverride) {
|
|
|
254
292
|
* @param right The new list of emitters to track.
|
|
255
293
|
* @param distinct Whether emitters are already unique (sorted and deduplicated).
|
|
256
294
|
*/
|
|
257
|
-
function UpdateEmitters(scope, right,
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
emitter_1.Emitter.On(right[x], scope.setCallback);
|
|
262
|
-
scope.emitters = right;
|
|
263
|
-
return;
|
|
264
|
-
}
|
|
265
|
-
if (right.length === 0) {
|
|
266
|
-
if (scope.emitters.length > 0) {
|
|
267
|
-
for (let x = 0; x < scope.emitters.length; x++)
|
|
295
|
+
function UpdateEmitters(scope, right, strategy) {
|
|
296
|
+
switch (strategy) {
|
|
297
|
+
case SHRINK_STRATEGY: {
|
|
298
|
+
for (let x = right.length; x < scope.emitters.length; x++)
|
|
268
299
|
emitter_1.Emitter.Remove(scope.emitters[x], scope.setCallback);
|
|
269
|
-
|
|
300
|
+
break;
|
|
270
301
|
}
|
|
271
|
-
|
|
302
|
+
case PUSH_STRATEGY:
|
|
303
|
+
case DISTINCT_STRATEGY:
|
|
304
|
+
strategy === PUSH_STRATEGY
|
|
305
|
+
? emitter_1.Emitter.Distinct(right)
|
|
306
|
+
: emitter_1.Emitter.Sort(right);
|
|
307
|
+
if (scope.emitters === null || scope.emitters.length === 0) {
|
|
308
|
+
for (let x = 0; x < right.length; x++)
|
|
309
|
+
emitter_1.Emitter.On(right[x], scope.setCallback);
|
|
310
|
+
}
|
|
311
|
+
else {
|
|
312
|
+
(0, array_1.ReconcileSortedEmitters)(scope.emitters, right, function (emitter) {
|
|
313
|
+
emitter_1.Emitter.On(emitter, scope.setCallback);
|
|
314
|
+
}, function (emitter) {
|
|
315
|
+
emitter_1.Emitter.Remove(emitter, scope.setCallback);
|
|
316
|
+
});
|
|
317
|
+
}
|
|
318
|
+
break;
|
|
272
319
|
}
|
|
273
|
-
(0, array_1.ReconcileSortedEmitters)(scope.emitters, right, function (emitter) {
|
|
274
|
-
emitter_1.Emitter.On(emitter, scope.setCallback);
|
|
275
|
-
}, function (emitter) {
|
|
276
|
-
emitter_1.Emitter.Remove(emitter, scope.setCallback);
|
|
277
|
-
});
|
|
278
320
|
scope.emitters = right;
|
|
279
321
|
}
|
|
280
322
|
/**
|
package/Utils/decorators.js
CHANGED
|
@@ -20,9 +20,7 @@ exports.Scope = Scope;
|
|
|
20
20
|
exports.Watch = Watch;
|
|
21
21
|
exports.Inject = Inject;
|
|
22
22
|
exports.Destroy = Destroy;
|
|
23
|
-
// import { Component } from "../Node/component";
|
|
24
23
|
const observableScope_1 = require("../Store/Tree/observableScope");
|
|
25
|
-
// import { ElementNodeRefTypes } from "../Node/nodeRef.types";
|
|
26
24
|
const observableNode_1 = require("../Store/Tree/observableNode");
|
|
27
25
|
const Store_1 = require("../Store");
|
|
28
26
|
/**
|
|
@@ -365,14 +363,6 @@ function WatchDecorator(target, propertyKey, descriptor, scopeFunction) {
|
|
|
365
363
|
observableScope_1.ObservableScope.Watch(scope, function (scope) {
|
|
366
364
|
instance[propertyKey](observableScope_1.ObservableScope.Value(scope));
|
|
367
365
|
});
|
|
368
|
-
/* const [value, scope] = ObservableScope.CreateIf(scopeFunctionWrapper, true);
|
|
369
|
-
if (scope) {
|
|
370
|
-
const propertyMap = GetScopeMapForInstance(this);
|
|
371
|
-
propertyMap[propertyKey as string] = [scope, undefined];
|
|
372
|
-
ObservableScope.Watch(scope, function (scope) {
|
|
373
|
-
(instance as any)[propertyKey](ObservableScope.Value(scope));
|
|
374
|
-
});
|
|
375
|
-
} */
|
|
376
366
|
instance[propertyKey](observableScope_1.ObservableScope.Value(scope));
|
|
377
367
|
return instance;
|
|
378
368
|
}
|
package/Utils/emitter.js
CHANGED
|
@@ -42,11 +42,6 @@ var Emitter;
|
|
|
42
42
|
function Distinct(emitters) {
|
|
43
43
|
if (emitters.length < 2)
|
|
44
44
|
return;
|
|
45
|
-
// emitters.length < 51 ? DistinctSmall(emitters) : DistinctLarge(emitters);
|
|
46
|
-
DistinctSmall(emitters);
|
|
47
|
-
}
|
|
48
|
-
Emitter.Distinct = Distinct;
|
|
49
|
-
function DistinctSmall(emitters) {
|
|
50
45
|
Sort(emitters);
|
|
51
46
|
let writePos = 0;
|
|
52
47
|
for (let x = 1; x < emitters.length; x++) {
|
|
@@ -58,20 +53,7 @@ var Emitter;
|
|
|
58
53
|
if (writePos < emitters.length)
|
|
59
54
|
emitters.splice(writePos);
|
|
60
55
|
}
|
|
61
|
-
|
|
62
|
-
let writePos = 0;
|
|
63
|
-
const ids = new Set();
|
|
64
|
-
for (let x = 0; x < emitters.length; x++) {
|
|
65
|
-
const id = emitters[x][0];
|
|
66
|
-
if (!ids.has(id)) {
|
|
67
|
-
ids.add(id);
|
|
68
|
-
emitters[writePos++] = emitters[x];
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
if (writePos < emitters.length)
|
|
72
|
-
emitters.splice(writePos);
|
|
73
|
-
Sort(emitters);
|
|
74
|
-
}
|
|
56
|
+
Emitter.Distinct = Distinct;
|
|
75
57
|
function Sort(emitters) {
|
|
76
58
|
if (emitters.length < 11)
|
|
77
59
|
(0, array_1.InsertionSortTuples)(emitters);
|