@domql/element 2.31.29 → 2.31.31

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/create.js CHANGED
@@ -91,12 +91,11 @@ export const create = async (
91
91
  return await onlyResolveExtends(element, parent, key, options)
92
92
  }
93
93
 
94
+ await triggerEventOn('eventStart', element, options)
94
95
  await triggerEventOn('start', element, options)
95
96
 
96
97
  switchDefaultOptions(element, parent, options)
97
-
98
98
  addCaching(element, parent, options)
99
-
100
99
  addMethods(element, parent, options)
101
100
 
102
101
  createScope(element, parent, options)
@@ -137,6 +136,7 @@ export const create = async (
137
136
  addElementIntoParentChildren(element, parent)
138
137
 
139
138
  await triggerEventOn('complete', element, options)
139
+ await triggerEventOn('eventComplete', element, options)
140
140
 
141
141
  return element
142
142
  }
@@ -67,6 +67,7 @@ const create = async (element, parent2, key, options = import_options.OPTIONS.cr
67
67
  if (options.onlyResolveExtends) {
68
68
  return await onlyResolveExtends(element, parent2, key, options);
69
69
  }
70
+ await (0, import_event.triggerEventOn)("eventStart", element, options);
70
71
  await (0, import_event.triggerEventOn)("start", element, options);
71
72
  switchDefaultOptions(element, parent2, options);
72
73
  addCaching(element, parent2, options);
@@ -91,6 +92,7 @@ const create = async (element, parent2, key, options = import_options.OPTIONS.cr
91
92
  await renderElement(element, parent2, options, attachOptions);
92
93
  addElementIntoParentChildren(element, parent2);
93
94
  await (0, import_event.triggerEventOn)("complete", element, options);
95
+ await (0, import_event.triggerEventOn)("eventComplete", element, options);
94
96
  return element;
95
97
  };
96
98
  const createBasedOnType = (element, parent2, key, options) => {
@@ -332,7 +332,7 @@ function call(fnKey, ...args) {
332
332
  }
333
333
  return result;
334
334
  } catch (error2) {
335
- console.error(`Error calling '${fnKey}'`);
335
+ console.error(`Error calling function: '${fnKey}'`);
336
336
  throw new Error(error2);
337
337
  }
338
338
  }
@@ -48,31 +48,22 @@ const update = async function(params = {}, opts) {
48
48
  const calleeElementCache = opts == null ? void 0 : opts.calleeElement;
49
49
  const options = (0, import_utils.deepClone)(
50
50
  (0, import_utils.isObject)(opts) ? (0, import_utils2.deepMerge)(opts, UPDATE_DEFAULT_OPTIONS) : UPDATE_DEFAULT_OPTIONS,
51
- { exclude: ["calleeElement"] }
51
+ { exclude: ["calleeElement", "updatingCalleeElement"] }
52
52
  );
53
53
  const element = this;
54
- options.calleeElement = calleeElementCache || this;
54
+ options.calleeElement = calleeElementCache;
55
55
  const { parent, node, key } = element;
56
56
  const { excludes, preventInheritAtCurrentState } = options;
57
57
  let ref = element.__ref;
58
58
  if (!ref) ref = element.__ref = {};
59
- if (this === options.calleeElement && !options.allowStorm) {
60
- if (ref.__selfCallIteration === void 0) ref.__selfCallIteration = 0;
61
- else ref.__selfCallIteration++;
62
- if (ref.__selfCallIteration > 100) {
63
- ref.__selfCallIteration = 0;
64
- return this.error("Potential self calling loop in update detected", opts);
65
- }
66
- const stormTimeout = setTimeout(() => {
67
- ref.__selfCallIteration = 0;
68
- clearTimeout(stormTimeout);
69
- }, 350);
70
- }
71
59
  const [snapshotOnCallee, calleeElement, snapshotHasUpdated] = captureSnapshot(
72
60
  element,
73
61
  options
74
62
  );
75
63
  if (snapshotHasUpdated) return;
64
+ if (checkIfStorm(element, options)) return;
65
+ if (!options.preventListeners)
66
+ await (0, import_event.triggerEventOn)("eventStart", element, options);
76
67
  if (!options.preventListeners)
77
68
  await (0, import_event.triggerEventOnUpdate)("startUpdate", params, element, options);
78
69
  if (preventInheritAtCurrentState && preventInheritAtCurrentState.__element === element)
@@ -160,7 +151,36 @@ const update = async function(params = {}, opts) {
160
151
  }) : await childUpdateCall();
161
152
  }
162
153
  }
163
- if (!preventUpdateListener) await (0, import_event.triggerEventOn)("update", element, options);
154
+ if (!options.preventListeners) {
155
+ if (!preventUpdateListener) await (0, import_event.triggerEventOn)("update", element, options);
156
+ await (0, import_event.triggerEventOn)("eventComplete", element, options);
157
+ }
158
+ };
159
+ const checkIfStorm = (element, options) => {
160
+ let ref = element.__ref;
161
+ if (!options.updatingCalleeElement) options.updatingCalleeElement = element;
162
+ if (ref.__stormAbortion && !options.allowStorm) {
163
+ const stormAbortion = setTimeout(() => {
164
+ delete ref.__stormAbortion;
165
+ clearTimeout(stormAbortion);
166
+ }, 1e3);
167
+ element.error("Potential storm update detected", options);
168
+ return true;
169
+ }
170
+ if (element === options.updatingCalleeElement && !options.allowStorm) {
171
+ if (ref.__selfCallIteration === void 0) ref.__selfCallIteration = 0;
172
+ else ref.__selfCallIteration++;
173
+ if (ref.__selfCallIteration > 100) {
174
+ ref.__selfCallIteration = 0;
175
+ ref.__stormAbortion = true;
176
+ element.error("Potential self calling loop in update detected", options);
177
+ return true;
178
+ }
179
+ const stormTimeout = setTimeout(() => {
180
+ ref.__selfCallIteration = 0;
181
+ clearTimeout(stormTimeout);
182
+ }, 350);
183
+ }
164
184
  };
165
185
  const captureSnapshot = (element, options) => {
166
186
  const ref = element.__ref;
@@ -244,24 +264,13 @@ const checkIfOnUpdate = (element, parent, options) => {
244
264
  const inheritStateUpdates = async (element, options) => {
245
265
  const { __ref: ref } = element;
246
266
  const stateKey = ref.__state;
247
- const { parent, state } = element;
248
- const { preventUpdateTriggerStateUpdate, isHoisted, execStateFunction } = options;
267
+ const { parent } = element;
268
+ const { preventUpdateTriggerStateUpdate } = options;
249
269
  if (preventUpdateTriggerStateUpdate) return;
250
270
  if (!stateKey && !ref.__hasRootState) {
251
271
  element.state = parent && parent.state || {};
252
272
  return;
253
273
  }
254
- const shouldForceFunctionState = (0, import_utils.isFunction)(stateKey) && !isHoisted && execStateFunction;
255
- if (shouldForceFunctionState) {
256
- const execState = (0, import_utils.exec)(stateKey, element);
257
- state.set(execState, {
258
- ...options,
259
- preventUpdate: true,
260
- preventStateUpdateListener: false,
261
- updatedByStateFunction: true
262
- });
263
- return;
264
- }
265
274
  const keyInParentState = (0, import_state.findInheritedState)(element, element.parent);
266
275
  if (!keyInParentState || options.preventInheritedStateUpdate) return;
267
276
  if (!options.preventBeforeStateUpdateListener && !options.preventListeners) {
@@ -63,6 +63,7 @@ const create = async (element, parent2, key, options = OPTIONS.create || {}, att
63
63
  if (options.onlyResolveExtends) {
64
64
  return await onlyResolveExtends(element, parent2, key, options);
65
65
  }
66
+ await triggerEventOn("eventStart", element, options);
66
67
  await triggerEventOn("start", element, options);
67
68
  switchDefaultOptions(element, parent2, options);
68
69
  addCaching(element, parent2, options);
@@ -87,6 +88,7 @@ const create = async (element, parent2, key, options = OPTIONS.create || {}, att
87
88
  await renderElement(element, parent2, options, attachOptions);
88
89
  addElementIntoParentChildren(element, parent2);
89
90
  await triggerEventOn("complete", element, options);
91
+ await triggerEventOn("eventComplete", element, options);
90
92
  return element;
91
93
  };
92
94
  const createBasedOnType = (element, parent2, key, options) => {
@@ -291,7 +291,7 @@ function call(fnKey, ...args) {
291
291
  }
292
292
  return result;
293
293
  } catch (error2) {
294
- console.error(`Error calling '${fnKey}'`);
294
+ console.error(`Error calling function: '${fnKey}'`);
295
295
  throw new Error(error2);
296
296
  }
297
297
  }
@@ -42,31 +42,22 @@ const update = async function(params = {}, opts) {
42
42
  const calleeElementCache = opts == null ? void 0 : opts.calleeElement;
43
43
  const options = deepClone(
44
44
  isObject(opts) ? deepMerge(opts, UPDATE_DEFAULT_OPTIONS) : UPDATE_DEFAULT_OPTIONS,
45
- { exclude: ["calleeElement"] }
45
+ { exclude: ["calleeElement", "updatingCalleeElement"] }
46
46
  );
47
47
  const element = this;
48
- options.calleeElement = calleeElementCache || this;
48
+ options.calleeElement = calleeElementCache;
49
49
  const { parent, node, key } = element;
50
50
  const { excludes, preventInheritAtCurrentState } = options;
51
51
  let ref = element.__ref;
52
52
  if (!ref) ref = element.__ref = {};
53
- if (this === options.calleeElement && !options.allowStorm) {
54
- if (ref.__selfCallIteration === void 0) ref.__selfCallIteration = 0;
55
- else ref.__selfCallIteration++;
56
- if (ref.__selfCallIteration > 100) {
57
- ref.__selfCallIteration = 0;
58
- return this.error("Potential self calling loop in update detected", opts);
59
- }
60
- const stormTimeout = setTimeout(() => {
61
- ref.__selfCallIteration = 0;
62
- clearTimeout(stormTimeout);
63
- }, 350);
64
- }
65
53
  const [snapshotOnCallee, calleeElement, snapshotHasUpdated] = captureSnapshot(
66
54
  element,
67
55
  options
68
56
  );
69
57
  if (snapshotHasUpdated) return;
58
+ if (checkIfStorm(element, options)) return;
59
+ if (!options.preventListeners)
60
+ await triggerEventOn("eventStart", element, options);
70
61
  if (!options.preventListeners)
71
62
  await triggerEventOnUpdate("startUpdate", params, element, options);
72
63
  if (preventInheritAtCurrentState && preventInheritAtCurrentState.__element === element)
@@ -154,7 +145,36 @@ const update = async function(params = {}, opts) {
154
145
  }) : await childUpdateCall();
155
146
  }
156
147
  }
157
- if (!preventUpdateListener) await triggerEventOn("update", element, options);
148
+ if (!options.preventListeners) {
149
+ if (!preventUpdateListener) await triggerEventOn("update", element, options);
150
+ await triggerEventOn("eventComplete", element, options);
151
+ }
152
+ };
153
+ const checkIfStorm = (element, options) => {
154
+ let ref = element.__ref;
155
+ if (!options.updatingCalleeElement) options.updatingCalleeElement = element;
156
+ if (ref.__stormAbortion && !options.allowStorm) {
157
+ const stormAbortion = setTimeout(() => {
158
+ delete ref.__stormAbortion;
159
+ clearTimeout(stormAbortion);
160
+ }, 1e3);
161
+ element.error("Potential storm update detected", options);
162
+ return true;
163
+ }
164
+ if (element === options.updatingCalleeElement && !options.allowStorm) {
165
+ if (ref.__selfCallIteration === void 0) ref.__selfCallIteration = 0;
166
+ else ref.__selfCallIteration++;
167
+ if (ref.__selfCallIteration > 100) {
168
+ ref.__selfCallIteration = 0;
169
+ ref.__stormAbortion = true;
170
+ element.error("Potential self calling loop in update detected", options);
171
+ return true;
172
+ }
173
+ const stormTimeout = setTimeout(() => {
174
+ ref.__selfCallIteration = 0;
175
+ clearTimeout(stormTimeout);
176
+ }, 350);
177
+ }
158
178
  };
159
179
  const captureSnapshot = (element, options) => {
160
180
  const ref = element.__ref;
@@ -238,24 +258,13 @@ const checkIfOnUpdate = (element, parent, options) => {
238
258
  const inheritStateUpdates = async (element, options) => {
239
259
  const { __ref: ref } = element;
240
260
  const stateKey = ref.__state;
241
- const { parent, state } = element;
242
- const { preventUpdateTriggerStateUpdate, isHoisted, execStateFunction } = options;
261
+ const { parent } = element;
262
+ const { preventUpdateTriggerStateUpdate } = options;
243
263
  if (preventUpdateTriggerStateUpdate) return;
244
264
  if (!stateKey && !ref.__hasRootState) {
245
265
  element.state = parent && parent.state || {};
246
266
  return;
247
267
  }
248
- const shouldForceFunctionState = isFunction(stateKey) && !isHoisted && execStateFunction;
249
- if (shouldForceFunctionState) {
250
- const execState = exec(stateKey, element);
251
- state.set(execState, {
252
- ...options,
253
- preventUpdate: true,
254
- preventStateUpdateListener: false,
255
- updatedByStateFunction: true
256
- });
257
- return;
258
- }
259
268
  const keyInParentState = findInheritedState(element, element.parent);
260
269
  if (!keyInParentState || options.preventInheritedStateUpdate) return;
261
270
  if (!options.preventBeforeStateUpdateListener && !options.preventListeners) {
package/methods/index.js CHANGED
@@ -377,7 +377,7 @@ export function call(fnKey, ...args) {
377
377
  // Return synchronous results directly
378
378
  return result
379
379
  } catch (error) {
380
- console.error(`Error calling '${fnKey}'`)
380
+ console.error(`Error calling function: '${fnKey}'`)
381
381
  throw new Error(error)
382
382
  }
383
383
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@domql/element",
3
- "version": "2.31.29",
3
+ "version": "2.31.31",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "module": "index.js",
@@ -27,12 +27,12 @@
27
27
  "prepublish": "npx rimraf -I dist && npm run build && npm run copy:package:cjs"
28
28
  },
29
29
  "dependencies": {
30
- "@domql/event": "^2.31.29",
31
- "@domql/render": "^2.31.29",
32
- "@domql/state": "^2.31.29",
33
- "@domql/utils": "^2.31.29"
30
+ "@domql/event": "^2.31.31",
31
+ "@domql/render": "^2.31.31",
32
+ "@domql/state": "^2.31.31",
33
+ "@domql/utils": "^2.31.31"
34
34
  },
35
- "gitHead": "d3448573587cb660e73fd460beb38707643c8e5c",
35
+ "gitHead": "a87c7ae3e84fbab1a9ee130d6d03f384e94260ab",
36
36
  "devDependencies": {
37
37
  "@babel/core": "^7.27.1"
38
38
  }
package/update.js CHANGED
@@ -56,38 +56,27 @@ export const update = async function (params = {}, opts) {
56
56
  isObject(opts)
57
57
  ? deepMerge(opts, UPDATE_DEFAULT_OPTIONS)
58
58
  : UPDATE_DEFAULT_OPTIONS,
59
- { exclude: ['calleeElement'] }
59
+ { exclude: ['calleeElement', 'updatingCalleeElement'] }
60
60
  )
61
61
  const element = this
62
- options.calleeElement = calleeElementCache || this
62
+ options.calleeElement = calleeElementCache
63
63
  const { parent, node, key } = element
64
64
  const { excludes, preventInheritAtCurrentState } = options
65
65
 
66
66
  let ref = element.__ref
67
67
  if (!ref) ref = element.__ref = {}
68
68
 
69
- // self calling is detected
70
- if (this === options.calleeElement && !options.allowStorm) {
71
- if (ref.__selfCallIteration === undefined) ref.__selfCallIteration = 0
72
- else ref.__selfCallIteration++
73
- // prevent storm
74
- if (ref.__selfCallIteration > 100) {
75
- ref.__selfCallIteration = 0
76
- return this.error('Potential self calling loop in update detected', opts)
77
- }
78
- // make storm detection time based
79
- const stormTimeout = setTimeout(() => {
80
- ref.__selfCallIteration = 0
81
- clearTimeout(stormTimeout)
82
- }, 350)
83
- }
84
-
85
69
  const [snapshotOnCallee, calleeElement, snapshotHasUpdated] = captureSnapshot(
86
70
  element,
87
71
  options
88
72
  )
89
73
  if (snapshotHasUpdated) return
90
74
 
75
+ if (checkIfStorm(element, options)) return
76
+
77
+ if (!options.preventListeners)
78
+ await triggerEventOn('eventStart', element, options)
79
+
91
80
  if (!options.preventListeners)
92
81
  await triggerEventOnUpdate('startUpdate', params, element, options)
93
82
 
@@ -231,7 +220,44 @@ export const update = async function (params = {}, opts) {
231
220
  }
232
221
  }
233
222
 
234
- if (!preventUpdateListener) await triggerEventOn('update', element, options)
223
+ if (!options.preventListeners) {
224
+ if (!preventUpdateListener) await triggerEventOn('update', element, options)
225
+ await triggerEventOn('eventComplete', element, options)
226
+ }
227
+ }
228
+
229
+ const checkIfStorm = (element, options) => {
230
+ let ref = element.__ref
231
+
232
+ if (!options.updatingCalleeElement) options.updatingCalleeElement = element
233
+
234
+ if (ref.__stormAbortion && !options.allowStorm) {
235
+ // make storm abourtion time based
236
+ const stormAbortion = setTimeout(() => {
237
+ delete ref.__stormAbortion
238
+ clearTimeout(stormAbortion)
239
+ }, 1000)
240
+ element.error('Potential storm update detected', options)
241
+ return true
242
+ }
243
+
244
+ // self calling is detected
245
+ if (element === options.updatingCalleeElement && !options.allowStorm) {
246
+ if (ref.__selfCallIteration === undefined) ref.__selfCallIteration = 0
247
+ else ref.__selfCallIteration++
248
+ // prevent storm
249
+ if (ref.__selfCallIteration > 100) {
250
+ ref.__selfCallIteration = 0
251
+ ref.__stormAbortion = true
252
+ element.error('Potential self calling loop in update detected', options)
253
+ return true
254
+ }
255
+ // make storm detection time based
256
+ const stormTimeout = setTimeout(() => {
257
+ ref.__selfCallIteration = 0
258
+ clearTimeout(stormTimeout)
259
+ }, 350)
260
+ }
235
261
  }
236
262
 
237
263
  const captureSnapshot = (element, options) => {
@@ -345,7 +371,6 @@ const checkIfOnUpdate = (element, parent, options) => {
345
371
  * @param {Object} options - Configuration options for state update inheritance.
346
372
  * @param {boolean} [options.preventUpdateTriggerStateUpdate] - If true, prevent triggering state updates.
347
373
  * @param {boolean} [options.isHoisted] - Whether the state is hoisted.
348
- * @param {boolean} [options.execStateFunction] - Execute the state functions.
349
374
  * @param {boolean} [options.stateFunctionOverwrite] - If true, overwrite (not merge) current state with what function returns.
350
375
  * @param {boolean} [options.preventInheritedStateUpdate] - If true, prevent inheriting state updates.
351
376
  * @param {boolean} [options.preventBeforeStateUpdateListener] - If true, prevent the 'beforeStateUpdate' event listener.
@@ -355,9 +380,8 @@ const checkIfOnUpdate = (element, parent, options) => {
355
380
  const inheritStateUpdates = async (element, options) => {
356
381
  const { __ref: ref } = element
357
382
  const stateKey = ref.__state
358
- const { parent, state } = element
359
- const { preventUpdateTriggerStateUpdate, isHoisted, execStateFunction } =
360
- options
383
+ const { parent } = element
384
+ const { preventUpdateTriggerStateUpdate } = options
361
385
 
362
386
  if (preventUpdateTriggerStateUpdate) return
363
387
 
@@ -367,20 +391,6 @@ const inheritStateUpdates = async (element, options) => {
367
391
  return
368
392
  }
369
393
 
370
- // If state is function, decide execution and apply setting a current state
371
- const shouldForceFunctionState =
372
- isFunction(stateKey) && !isHoisted && execStateFunction
373
- if (shouldForceFunctionState) {
374
- const execState = exec(stateKey, element)
375
- state.set(execState, {
376
- ...options,
377
- preventUpdate: true,
378
- preventStateUpdateListener: false,
379
- updatedByStateFunction: true
380
- })
381
- return
382
- }
383
-
384
394
  // If state is string, find its value in the state tree
385
395
  const keyInParentState = findInheritedState(element, element.parent)
386
396
  if (!keyInParentState || options.preventInheritedStateUpdate) return