@jinntec/fore 0.25.0 → 1.0.0-2

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.
Files changed (41) hide show
  1. package/README.md +75 -22
  2. package/dist/fore-all.js +11 -11
  3. package/dist/fore.js +1 -1
  4. package/index.js +5 -1
  5. package/package.json +17 -6
  6. package/resources/fore.css +121 -4
  7. package/resources/toastify.css +3 -1
  8. package/src/DependencyNotifyingDomFacade.js +9 -1
  9. package/src/ForeElementMixin.js +83 -12
  10. package/src/actions/abstract-action.js +101 -27
  11. package/src/actions/fx-action.js +4 -2
  12. package/src/actions/fx-append.js +21 -18
  13. package/src/actions/fx-confirm.js +22 -0
  14. package/src/actions/fx-dispatch.js +10 -2
  15. package/src/actions/fx-insert.js +35 -30
  16. package/src/actions/fx-message.js +7 -1
  17. package/src/actions/fx-send.js +1 -1
  18. package/src/actions/fx-setvalue.js +2 -9
  19. package/src/dep_graph.js +9 -0
  20. package/src/drawdown.js +172 -0
  21. package/src/fore.js +126 -18
  22. package/src/functions/fx-function.js +2 -2
  23. package/src/fx-bind.js +11 -7
  24. package/src/fx-fore.js +283 -67
  25. package/src/fx-header.js +20 -0
  26. package/src/fx-instance.js +54 -10
  27. package/src/fx-model.js +175 -38
  28. package/src/fx-submission.js +235 -53
  29. package/src/getInScopeContext.js +2 -3
  30. package/src/ui/abstract-control.js +23 -44
  31. package/src/ui/fx-alert.js +20 -19
  32. package/src/ui/fx-container.js +9 -4
  33. package/src/ui/fx-control.js +92 -37
  34. package/src/ui/fx-inspector.js +44 -0
  35. package/src/ui/fx-items.js +104 -20
  36. package/src/ui/fx-output.js +92 -3
  37. package/src/ui/fx-repeat.js +87 -80
  38. package/src/ui/fx-repeatitem.js +38 -48
  39. package/src/ui/fx-trigger.js +49 -27
  40. package/src/xpath-evaluation.js +533 -235
  41. package/src/xpath-util.js +50 -12
package/src/fx-model.js CHANGED
@@ -16,11 +16,13 @@ export class FxModel extends HTMLElement {
16
16
  this.instances = [];
17
17
  this.modelItems = [];
18
18
  this.defaultContext = {};
19
+ this.changed = [];
19
20
 
20
21
  // this.mainGraph = new DepGraph(false);
21
22
  this.inited = false;
22
23
  this.modelConstructed = false;
23
24
  this.attachShadow({ mode: 'open' });
25
+ this.computes = 0;
24
26
  }
25
27
 
26
28
  get formElement() {
@@ -39,7 +41,7 @@ export class FxModel extends HTMLElement {
39
41
  console.log('model-construct-done fired ', e.detail.model.instances);
40
42
  });
41
43
 
42
- // logging
44
+ this.skipUpdate = false;
43
45
  }
44
46
 
45
47
  static lazyCreateModelItem(model, ref, node) {
@@ -83,10 +85,20 @@ export class FxModel extends HTMLElement {
83
85
  return mi;
84
86
  }
85
87
 
88
+ /**
89
+ * modelConstruct starts actual processing of the model by
90
+ *
91
+ * 1. loading instances if present or constructing one
92
+ * 2. calling updateModel to run the model update cycle of rebuild, recalculate and revalidate
93
+ *
94
+ * @event model-construct-done is fired once all instances have be loaded or after generating instance
95
+ *
96
+ */
86
97
  modelConstruct() {
87
98
  console.log('### <<<<< dispatching model-construct >>>>>');
88
99
  this.dispatchEvent(new CustomEvent('model-construct', { detail: this }));
89
100
 
101
+ console.time('instance-loading');
90
102
  const instances = this.querySelectorAll('fx-instance');
91
103
  if (instances.length > 0) {
92
104
  console.group('init instances');
@@ -121,6 +133,7 @@ export class FxModel extends HTMLElement {
121
133
  }),
122
134
  );
123
135
  }
136
+ console.timeEnd('instance-loading');
124
137
  this.inited = true;
125
138
  }
126
139
 
@@ -133,33 +146,45 @@ export class FxModel extends HTMLElement {
133
146
  * update action triggering the update cycle
134
147
  */
135
148
  updateModel() {
149
+ console.time('updateModel');
136
150
  this.rebuild();
151
+ if(this.skipUpdate) return;
137
152
  this.recalculate();
138
153
  this.revalidate();
154
+ console.timeEnd('updateModel');
139
155
  }
140
156
 
141
157
  rebuild() {
142
158
  console.group('### rebuild');
143
-
159
+ console.time('rebuild');
144
160
  this.mainGraph = new DepGraph(false);
145
161
  this.modelItems = [];
146
162
 
147
163
  // trigger recursive initialization of the fx-bind elements
148
164
  const binds = this.querySelectorAll('fx-model > fx-bind');
165
+ if(binds.length === 0 ) {
166
+ console.log('skipped model update');
167
+ this.skipUpdate = true;
168
+ return ;
169
+ }
149
170
  binds.forEach(bind => {
150
171
  bind.init(this);
151
172
  });
173
+ console.timeEnd('rebuild');
152
174
 
153
175
  // console.log(`dependencies of a `, this.mainGraph.dependenciesOf("/Q{}data[1]/Q{}a[1]:required"));
154
176
  // console.log(`dependencies of b `, this.mainGraph.dependenciesOf("/Q{}data[1]/Q{}b[1]:required"));
155
177
  console.log(`rebuild mainGraph`, this.mainGraph);
156
178
  console.log(`rebuild mainGraph calc order`, this.mainGraph.overallOrder());
179
+
180
+ this.dispatchEvent(new CustomEvent('rebuild-done', { detail: { maingraph: this.mainGraph } }));
181
+
157
182
  /*
158
- console.log(
159
- `rebuild finished with modelItems ${this.modelItems.length} item(s)`,
160
- this.modelItems,
161
- );
162
- */
183
+ console.log(
184
+ `rebuild finished with modelItems ${this.modelItems.length} item(s)`,
185
+ this.modelItems,
186
+ );
187
+ */
163
188
  console.groupEnd();
164
189
  }
165
190
 
@@ -172,36 +197,66 @@ export class FxModel extends HTMLElement {
172
197
  console.group('### recalculate');
173
198
  console.log('recalculate instances ', this.instances);
174
199
 
175
- const v = this.mainGraph.overallOrder();
176
- v.forEach(path => {
177
- console.log('recalculating path ', path);
178
-
179
- const node = this.mainGraph.getNodeData(path);
180
- // console.log('recalculating node ', node);
181
- const modelItem = this.getModelItem(node);
182
- // console.log('modelitem ', modelItem);
183
-
184
- if (modelItem && path.includes(':')) {
185
- const property = path.split(':')[1];
186
- if (property) {
187
- if (property === 'calculate') {
188
- const expr = modelItem.bind[property];
189
- const compute = evaluateXPath(expr, modelItem.node, this);
190
- modelItem.value = compute;
191
- } else if (property !== 'constraint' && property !== 'type') {
192
- console.log('recalculating property ', property);
193
-
194
- const expr = modelItem.bind[property];
195
- if (expr) {
196
- console.log('recalc expr: ', expr);
197
- const compute = evaluateXPathToBoolean(expr, modelItem.node, this);
198
- modelItem[property] = compute;
199
- console.log(`modelItem computed`, modelItem.required);
200
- }
200
+ console.time('recalculate');
201
+ this.computes = 0;
202
+
203
+ this.subgraph = new DepGraph(false);
204
+ if (this.changed.length !== 0) {
205
+ // ### build the subgraph
206
+ this.changed.forEach(modelItem => {
207
+ this.subgraph.addNode(modelItem.path, modelItem.node);
208
+ // const dependents = this.mainGraph.dependantsOf(modelItem.path, false);
209
+ // this._addSubgraphDependencies(modelItem.path);
210
+ if (this.mainGraph.hasNode(modelItem.path)) {
211
+ // const dependents = this.mainGraph.directDependantsOf(modelItem.path)
212
+
213
+ const all = this.mainGraph.dependantsOf(modelItem.path, false);
214
+ const dependents = all.reverse();
215
+ if (dependents.length !== 0) {
216
+ dependents.forEach(dep => {
217
+ // const subdep = this.mainGraph.dependentsOf(dep,false);
218
+ // subgraph.addDependency(dep, modelItem.path);
219
+ const val = this.mainGraph.getNodeData(dep);
220
+ this.subgraph.addNode(dep, val);
221
+ if (dep.includes(':')) {
222
+ const path = dep.substring(0, dep.indexOf(':'));
223
+ this.subgraph.addNode(path, val);
224
+
225
+ const deps = this.mainGraph.dependentsOf(modelItem.path, false);
226
+ // if we find the dep to be first in list of dependents we are dependent on ourselves not adding edge to modelItem.path
227
+ if (deps.indexOf(dep) !== 0) {
228
+ this.subgraph.addDependency(dep, modelItem.path);
229
+ }
230
+ }
231
+ // subgraph.addDependency(dep,modelItem.path);
232
+ });
201
233
  }
202
234
  }
203
- }
204
- });
235
+ });
236
+
237
+ // ### compute the subgraph
238
+ const ordered = this.subgraph.overallOrder(false);
239
+ ordered.forEach(path => {
240
+ if (this.mainGraph.hasNode(path)) {
241
+ const node = this.mainGraph.getNodeData(path);
242
+ this.compute(node, path);
243
+ }
244
+ });
245
+ this.changed = [];
246
+ console.log('subgraph', this.subgraph);
247
+ this.dispatchEvent(
248
+ new CustomEvent('recalculate-done', { detail: { subgraph: this.subgraph } }),
249
+ );
250
+ } else {
251
+ const v = this.mainGraph.overallOrder(false);
252
+ v.forEach(path => {
253
+ const node = this.mainGraph.getNodeData(path);
254
+ this.compute(node, path);
255
+ });
256
+ }
257
+ console.log(`recalculated ${this.computes} modelItems`);
258
+
259
+ console.timeEnd('recalculate');
205
260
  console.log(
206
261
  `recalculate finished with modelItems ${this.modelItems.length} item(s)`,
207
262
  this.modelItems,
@@ -209,6 +264,86 @@ export class FxModel extends HTMLElement {
209
264
  console.groupEnd();
210
265
  }
211
266
 
267
+ /*
268
+ _addSubgraphDependencies(path){
269
+ const dependents = this.mainGraph.directDependantsOf(path)
270
+
271
+ const alreadyInGraph = this.subgraph.incomingEdges[path];
272
+ // const alreadyInGraph = path in this.subgraph;
273
+ if(dependents.length !== 0 && alreadyInGraph.length === 0){
274
+
275
+ dependents.forEach(dep => {
276
+ // const val= this.mainGraph.getNodeData(dep);
277
+ // this.subgraph.addNode(dep,val);
278
+ if(dep.includes(':')){
279
+ const subpath = dep.substring(0, dep.indexOf(':'));
280
+ // this.subgraph.addNode(subpath,val);
281
+ this.subgraph.addDependency(subpath,dep);
282
+ this.subgraph.addDependency(dep,path);
283
+ /!*
284
+ const subdeps = this.mainGraph.directDependantsOf(path);
285
+ console.log('subdeps',path, subdeps);
286
+ subdeps.forEach(sdep => {
287
+ const sval= this.mainGraph.getNodeData(sdep);
288
+ this.subgraph.addNode(sdep,sval);
289
+ console.log('subdep',sdep);
290
+ });
291
+ *!/
292
+ if(this.subgraph.incomingEdges[dep] === 0){
293
+ this._addSubgraphDependencies(subpath)
294
+ }
295
+
296
+ }
297
+ });
298
+
299
+ }
300
+
301
+ }
302
+ */
303
+
304
+ /**
305
+ * (re-) computes a modelItem.
306
+ * @param node - the node the modelItem is attached to
307
+ * @param path - the canonical XPath of the node
308
+ */
309
+ compute(node, path) {
310
+ const modelItem = this.getModelItem(node);
311
+ if (modelItem && path.includes(':')) {
312
+ const property = path.split(':')[1];
313
+ if (property) {
314
+ /*
315
+ if (property === 'readonly') {
316
+ // make sure that calculated items are always readonly
317
+ if(modelItem.bind['calculate']){
318
+ modelItem.readonly = true;
319
+ }else {
320
+ const expr = modelItem.bind[property];
321
+ const compute = evaluateXPathToBoolean(expr, modelItem.node, this);
322
+ modelItem.readonly = compute;
323
+ }
324
+ }
325
+ */
326
+ if (property === 'calculate') {
327
+ const expr = modelItem.bind[property];
328
+ const compute = evaluateXPath(expr, modelItem.node, this);
329
+ modelItem.value = compute;
330
+ modelItem.readonly = true; // calculated nodes are always readonly
331
+ } else if (property !== 'constraint' && property !== 'type') {
332
+ const expr = modelItem.bind[property];
333
+ if (expr) {
334
+ const compute = evaluateXPathToBoolean(expr, modelItem.node, this);
335
+ modelItem[property] = compute;
336
+ console.log(
337
+ `recalculating path ${path} - Expr:'${expr}' computed`,
338
+ modelItem[property],
339
+ );
340
+ }
341
+ }
342
+ }
343
+ this.computes += 1;
344
+ }
345
+ }
346
+
212
347
  /**
213
348
  * Iterates all modelItems to calculate the validation status.
214
349
  *
@@ -228,6 +363,7 @@ export class FxModel extends HTMLElement {
228
363
  revalidate() {
229
364
  console.group('### revalidate');
230
365
 
366
+ console.time('revalidate');
231
367
  let valid = true;
232
368
  this.modelItems.forEach(modelItem => {
233
369
  // console.log('validating node ', modelItem.node);
@@ -235,9 +371,9 @@ export class FxModel extends HTMLElement {
235
371
  const { bind } = modelItem;
236
372
  if (bind) {
237
373
  /*
238
- todo: investigate why bind is an element when created in fx-bind.init() and an fx-bind object when
239
- created lazily.
240
- */
374
+ todo: investigate why bind is an element when created in fx-bind.init() and an fx-bind object when
375
+ created lazily.
376
+ */
241
377
  if (typeof bind.hasAttribute === 'function' && bind.hasAttribute('constraint')) {
242
378
  const constraint = bind.getAttribute('constraint');
243
379
  if (constraint) {
@@ -257,6 +393,7 @@ export class FxModel extends HTMLElement {
257
393
  }
258
394
  }
259
395
  });
396
+ console.timeEnd('revalidate');
260
397
  console.log('modelItems after revalidate: ', this.modelItems);
261
398
  console.groupEnd();
262
399
  return valid;