@domql/element 2.28.41 → 2.28.44

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.
@@ -18,7 +18,11 @@ import { isMethod } from "./methods/index.js";
18
18
  import { updateProps } from "./props/index.js";
19
19
  import { createState, findInheritedState } from "@domql/state";
20
20
  import { create } from "./create.js";
21
- import { throughExecProps, throughUpdatedDefine, throughUpdatedExec } from "./iterate.js";
21
+ import {
22
+ throughExecProps,
23
+ throughUpdatedDefine,
24
+ throughUpdatedExec
25
+ } from "./iterate.js";
22
26
  import { REGISTRY } from "./mixins/index.js";
23
27
  import { applyParam } from "./utils/applyParam.js";
24
28
  import { OPTIONS } from "./cache/options.js";
@@ -36,17 +40,25 @@ const UPDATE_DEFAULT_OPTIONS = {
36
40
  };
37
41
  const update = async function(params = {}, opts) {
38
42
  const calleeElementCache = opts == null ? void 0 : opts.calleeElement;
39
- const options = deepClone(isObject(opts) ? deepMerge(opts, UPDATE_DEFAULT_OPTIONS) : UPDATE_DEFAULT_OPTIONS, { exclude: ["calleeElement"] });
43
+ const options = deepClone(
44
+ isObject(opts) ? deepMerge(opts, UPDATE_DEFAULT_OPTIONS) : UPDATE_DEFAULT_OPTIONS,
45
+ { exclude: ["calleeElement"] }
46
+ );
40
47
  options.calleeElement = calleeElementCache;
41
48
  const element = this;
42
49
  const { parent, node, key } = element;
43
50
  const { excludes, preventInheritAtCurrentState } = options;
44
51
  let ref = element.__ref;
45
52
  if (!ref) ref = element.__ref = {};
46
- const [snapshotOnCallee, calleeElement, snapshotHasUpdated] = captureSnapshot(element, options);
53
+ const [snapshotOnCallee, calleeElement, snapshotHasUpdated] = captureSnapshot(
54
+ element,
55
+ options
56
+ );
47
57
  if (snapshotHasUpdated) return;
48
- if (!options.preventListeners) await triggerEventOnUpdate("startUpdate", params, element, options);
49
- if (preventInheritAtCurrentState && preventInheritAtCurrentState.__element === element) return;
58
+ if (!options.preventListeners)
59
+ await triggerEventOnUpdate("startUpdate", params, element, options);
60
+ if (preventInheritAtCurrentState && preventInheritAtCurrentState.__element === element)
61
+ return;
50
62
  if (!excludes) merge(options, UPDATE_DEFAULT_OPTIONS);
51
63
  if (isString(params) || isNumber(params)) {
52
64
  params = { text: params };
@@ -62,13 +74,18 @@ const update = async function(params = {}, opts) {
62
74
  if (props) updateProps(props, element, parent);
63
75
  }
64
76
  if (!options.preventBeforeUpdateListener && !options.preventListeners) {
65
- const beforeUpdateReturns = await triggerEventOnUpdate("beforeUpdate", params, element, options);
77
+ const beforeUpdateReturns = await triggerEventOnUpdate(
78
+ "beforeUpdate",
79
+ params,
80
+ element,
81
+ options
82
+ );
66
83
  if (beforeUpdateReturns === false) return element;
67
84
  }
68
85
  overwriteDeep(element, params, { exclude: METHODS_EXL });
69
86
  throughExecProps(element);
70
- throughUpdatedExec(element, { ignore: UPDATE_DEFAULT_OPTIONS });
71
- throughUpdatedDefine(element);
87
+ await throughUpdatedExec(element, { ignore: UPDATE_DEFAULT_OPTIONS });
88
+ await throughUpdatedDefine(element);
72
89
  if (!options.isForced && !options.preventListeners) {
73
90
  await triggerEventOn("beforeClassAssign", element, options);
74
91
  }
@@ -87,8 +104,10 @@ const update = async function(params = {}, opts) {
87
104
  preventUpdateAfterCount
88
105
  } = options;
89
106
  if (preventUpdateAfter) {
90
- if (isNumber(preventUpdateAfterCount) && preventUpdateAfter <= preventUpdateAfterCount) return;
91
- else if (options.preventUpdateAfterCount === void 0) options.preventUpdateAfterCount = 1;
107
+ if (isNumber(preventUpdateAfterCount) && preventUpdateAfter <= preventUpdateAfterCount)
108
+ return;
109
+ else if (options.preventUpdateAfterCount === void 0)
110
+ options.preventUpdateAfterCount = 1;
92
111
  else options.preventUpdateAfterCount++;
93
112
  }
94
113
  for (const param in element) {
@@ -97,7 +116,8 @@ const update = async function(params = {}, opts) {
97
116
  const isInPreventUpdate = isArray(preventUpdate) && preventUpdate.includes(param);
98
117
  const isInPreventDefineUpdate = isArray(preventDefineUpdate) && preventDefineUpdate.includes(param);
99
118
  const hasCollection = element.$collection || element.$stateCollection || element.$propsCollection;
100
- if (isUndefined(prop) || isInPreventUpdate || isInPreventDefineUpdate || preventDefineUpdate === true || preventDefineUpdate === param || preventContentUpdate && param === "content" && !hasCollection || (preventStateUpdate && param) === "state" || isMethod(param, element) || isObject(REGISTRY[param]) || isVariant(param)) continue;
119
+ if (isUndefined(prop) || isInPreventUpdate || isInPreventDefineUpdate || preventDefineUpdate === true || preventDefineUpdate === param || preventContentUpdate && param === "content" && !hasCollection || (preventStateUpdate && param) === "state" || isMethod(param, element) || isObject(REGISTRY[param]) || isVariant(param))
120
+ continue;
101
121
  if (preventStateUpdate === "once") options.preventStateUpdate = false;
102
122
  const isElement = await applyParam(param, element, options);
103
123
  if (isElement) {
@@ -140,9 +160,15 @@ const captureSnapshot = (element, options) => {
140
160
  };
141
161
  const checkIfOnUpdate = (element, parent, options) => {
142
162
  var _a, _b, _c;
143
- if (!isFunction(element.if) && !isFunction((_a = element.props) == null ? void 0 : _a.if) || !parent) return;
163
+ if (!isFunction(element.if) && !isFunction((_a = element.props) == null ? void 0 : _a.if) || !parent)
164
+ return;
144
165
  const ref = element.__ref;
145
- const ifPassed = (element.if || ((_b = element.props) == null ? void 0 : _b.if))(element, element.state, element.context, options);
166
+ const ifPassed = (element.if || ((_b = element.props) == null ? void 0 : _b.if))(
167
+ element,
168
+ element.state,
169
+ element.context,
170
+ options
171
+ );
146
172
  const itWasFalse = ref.__if !== true;
147
173
  if (ifPassed) {
148
174
  ref.__if = true;
@@ -165,7 +191,8 @@ const checkIfOnUpdate = (element, parent, options) => {
165
191
  const contentKey = ref.contentElementKey;
166
192
  if (element.$collection || element.$stateCollection || element.$propsCollection) {
167
193
  element.removeContent();
168
- } else if ((_c = element[contentKey]) == null ? void 0 : _c.parseDeep) element[contentKey] = element[contentKey].parseDeep();
194
+ } else if ((_c = element[contentKey]) == null ? void 0 : _c.parseDeep)
195
+ element[contentKey] = element[contentKey].parseDeep();
169
196
  const previousElement = element.previousElement();
170
197
  const previousNode = previousElement == null ? void 0 : previousElement.node;
171
198
  const hasPrevious = previousNode == null ? void 0 : previousNode.parentNode;
@@ -178,7 +205,13 @@ const checkIfOnUpdate = (element, parent, options) => {
178
205
  };
179
206
  delete element.__ref;
180
207
  delete element.parent;
181
- const createdElement = create(element, parent, element.key, OPTIONS.create, attachOptions);
208
+ const createdElement = create(
209
+ element,
210
+ parent,
211
+ element.key,
212
+ OPTIONS.create,
213
+ attachOptions
214
+ );
182
215
  if (options.preventUpdate !== true && element.on && isFunction(element.on.update)) {
183
216
  applyEvent(element.on.update, createdElement, createdElement.state);
184
217
  }
@@ -202,18 +235,33 @@ const inheritStateUpdates = async (element, options) => {
202
235
  const shouldForceFunctionState = isFunction(stateKey) && !isHoisted && execStateFunction;
203
236
  if (shouldForceFunctionState) {
204
237
  const execState = exec(stateKey, element);
205
- state.set(execState, { ...options, preventUpdate: true, preventStateUpdateListener: false, updatedByStateFunction: true });
238
+ state.set(execState, {
239
+ ...options,
240
+ preventUpdate: true,
241
+ preventStateUpdateListener: false,
242
+ updatedByStateFunction: true
243
+ });
206
244
  return;
207
245
  }
208
246
  const keyInParentState = findInheritedState(element, element.parent);
209
247
  if (!keyInParentState || options.preventInheritedStateUpdate) return;
210
248
  if (!options.preventBeforeStateUpdateListener && !options.preventListeners) {
211
- const initStateReturns = await triggerEventOnUpdate("beforeStateUpdate", keyInParentState, element, options);
249
+ const initStateReturns = await triggerEventOnUpdate(
250
+ "beforeStateUpdate",
251
+ keyInParentState,
252
+ element,
253
+ options
254
+ );
212
255
  if (initStateReturns === false) return element;
213
256
  }
214
257
  const newState = await createStateUpdate(element, parent, options);
215
258
  if (!options.preventStateUpdateListener && !options.preventListeners) {
216
- await triggerEventOnUpdate("stateUpdate", newState.parse(), element, options);
259
+ await triggerEventOnUpdate(
260
+ "stateUpdate",
261
+ newState.parse(),
262
+ element,
263
+ options
264
+ );
217
265
  }
218
266
  };
219
267
  const createStateUpdate = async (element, parent, options) => {
package/iterate.js CHANGED
@@ -14,20 +14,23 @@ import {
14
14
  import { METHODS_EXL, overwrite } from './utils/index.js'
15
15
  import { isMethod } from './methods/index.js'
16
16
 
17
- export const throughInitialExec = (element, exclude = {}) => {
17
+ export const throughInitialExec = async (element, exclude = {}) => {
18
18
  const { __ref: ref } = element
19
19
  for (const param in element) {
20
20
  if (exclude[param]) continue
21
21
  const prop = element[param]
22
22
  if (isFunction(prop) && !isMethod(param, element) && !isVariant(param)) {
23
23
  ref.__exec[param] = prop
24
- element[param] = prop(element, element.state, element.context)
24
+ element[param] = await prop(element, element.state, element.context)
25
25
  // if (isComponent)
26
26
  }
27
27
  }
28
28
  }
29
29
 
30
- export const throughUpdatedExec = (element, options = { excludes: METHODS_EXL }) => {
30
+ export const throughUpdatedExec = async (
31
+ element,
32
+ options = { excludes: METHODS_EXL }
33
+ ) => {
31
34
  const { __ref: ref } = element
32
35
  const changes = {}
33
36
 
@@ -37,7 +40,11 @@ export const throughUpdatedExec = (element, options = { excludes: METHODS_EXL })
37
40
  const isDefinedParam = ref.__defineCache[param]
38
41
  if (isDefinedParam) continue
39
42
 
40
- const newExec = ref.__exec[param](element, element.state, element.context)
43
+ const newExec = await ref.__exec[param](
44
+ element,
45
+ element.state,
46
+ element.context
47
+ )
41
48
  const execReturnsString = isString(newExec) || isNumber(newExec)
42
49
  // if (prop && prop.node && execReturnsString) {
43
50
  if (prop && prop.node && execReturnsString) {
@@ -58,11 +65,12 @@ export const throughUpdatedExec = (element, options = { excludes: METHODS_EXL })
58
65
  return changes
59
66
  }
60
67
 
61
- export const throughExecProps = (element) => {
68
+ export const throughExecProps = element => {
62
69
  const { __ref: ref } = element
63
70
  const { props } = element
64
71
  for (const k in props) {
65
- const isDefine = k.startsWith('is') || k.startsWith('has') || k.startsWith('use')
72
+ const isDefine =
73
+ k.startsWith('is') || k.startsWith('has') || k.startsWith('use')
66
74
  const cachedExecProp = ref.__execProps[k]
67
75
  if (isFunction(cachedExecProp)) {
68
76
  props[k] = exec(cachedExecProp, element)
@@ -73,7 +81,7 @@ export const throughExecProps = (element) => {
73
81
  }
74
82
  }
75
83
 
76
- export const throughInitialDefine = (element) => {
84
+ export const throughInitialDefine = async element => {
77
85
  const { define, context, __ref: ref } = element
78
86
 
79
87
  let defineObj = {}
@@ -84,23 +92,34 @@ export const throughInitialDefine = (element) => {
84
92
  for (const param in defineObj) {
85
93
  let elementProp = element[param]
86
94
 
87
- if (isFunction(elementProp) && !isMethod(param, element) && !isVariant(param)) {
95
+ if (
96
+ isFunction(elementProp) &&
97
+ !isMethod(param, element) &&
98
+ !isVariant(param)
99
+ ) {
88
100
  ref.__exec[param] = elementProp
89
- const execParam = elementProp = exec(elementProp, element)
101
+ const execParam = (elementProp = await exec(elementProp, element))
90
102
 
91
103
  if (execParam) {
92
- elementProp = element[param] = execParam.parse ? execParam.parse() : execParam
104
+ elementProp = element[param] = execParam.parse
105
+ ? execParam.parse()
106
+ : execParam
93
107
  ref.__defineCache[param] = elementProp
94
108
  }
95
109
  }
96
110
 
97
- const execParam = defineObj[param](elementProp, element, element.state, element.context)
111
+ const execParam = await defineObj[param](
112
+ elementProp,
113
+ element,
114
+ element.state,
115
+ element.context
116
+ )
98
117
  if (execParam) element[param] = execParam
99
118
  }
100
119
  return element
101
120
  }
102
121
 
103
- export const throughUpdatedDefine = (element) => {
122
+ export const throughUpdatedDefine = async element => {
104
123
  const { context, define, __ref: ref } = element
105
124
  const changes = {}
106
125
 
@@ -110,9 +129,19 @@ export const throughUpdatedDefine = (element) => {
110
129
 
111
130
  for (const param in obj) {
112
131
  const execParam = ref.__exec[param]
113
- if (execParam) ref.__defineCache[param] = execParam(element, element.state, element.context)
114
- const cached = exec(ref.__defineCache[param], element)
115
- const newExecParam = obj[param](cached, element, element.state, element.context)
132
+ if (execParam)
133
+ ref.__defineCache[param] = await execParam(
134
+ element,
135
+ element.state,
136
+ element.context
137
+ )
138
+ const cached = await exec(ref.__defineCache[param], element)
139
+ const newExecParam = await obj[param](
140
+ cached,
141
+ element,
142
+ element.state,
143
+ element.context
144
+ )
116
145
  if (newExecParam) element[param] = newExecParam
117
146
  }
118
147
  return changes
package/methods/index.js CHANGED
@@ -145,10 +145,16 @@ export function setProps (param, options) {
145
145
  return element
146
146
  }
147
147
 
148
- export function getRef () {
148
+ export function getRef (key) {
149
+ if (key) return this.__ref && this.__ref[key]
149
150
  return this.__ref
150
151
  }
151
152
 
153
+ export function getChildren () {
154
+ const __children = this.getRef('__children')
155
+ return __children.map(k => this[k])
156
+ }
157
+
152
158
  export function getPath () {
153
159
  return this.getRef().path
154
160
  }
@@ -354,6 +360,7 @@ export const METHODS = [
354
360
  'lookdown',
355
361
  'lookdownAll',
356
362
  'getRef',
363
+ 'getChildren',
357
364
  'getPath',
358
365
  'setNodeStyles',
359
366
  'spotByPath',
package/node.js CHANGED
@@ -52,10 +52,10 @@ export const createNode = async (element, options) => {
52
52
  throughExecProps(element)
53
53
 
54
54
  // iterate through define
55
- throughInitialDefine(element)
55
+ await throughInitialDefine(element)
56
56
 
57
57
  // iterate through exec
58
- throughInitialExec(element)
58
+ await throughInitialExec(element)
59
59
 
60
60
  if (element.tag !== 'string' && element.tag !== 'fragment') {
61
61
  propagateEventsFromProps(element)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@domql/element",
3
- "version": "2.28.41",
3
+ "version": "2.28.44",
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.28.41",
31
- "@domql/render": "^2.28.41",
32
- "@domql/state": "^2.28.41",
33
- "@domql/utils": "^2.28.41"
30
+ "@domql/event": "^2.28.44",
31
+ "@domql/render": "^2.28.44",
32
+ "@domql/state": "^2.28.44",
33
+ "@domql/utils": "^2.28.44"
34
34
  },
35
- "gitHead": "f3572ee2c95501d529813cc40a381254f51492a6",
35
+ "gitHead": "70519611a6e66b84b628e807c95227a516a40b03",
36
36
  "devDependencies": {
37
37
  "@babel/core": "^7.26.0"
38
38
  }
package/update.js CHANGED
@@ -22,7 +22,11 @@ import { updateProps } from './props/index.js'
22
22
  import { createState, findInheritedState } from '@domql/state'
23
23
 
24
24
  import { create } from './create.js'
25
- import { throughExecProps, throughUpdatedDefine, throughUpdatedExec } from './iterate.js'
25
+ import {
26
+ throughExecProps,
27
+ throughUpdatedDefine,
28
+ throughUpdatedExec
29
+ } from './iterate.js'
26
30
  import { REGISTRY } from './mixins/index.js'
27
31
  import { applyParam } from './utils/applyParam.js'
28
32
  import { OPTIONS } from './cache/options.js'
@@ -43,7 +47,12 @@ const UPDATE_DEFAULT_OPTIONS = {
43
47
 
44
48
  export const update = async function (params = {}, opts) {
45
49
  const calleeElementCache = opts?.calleeElement
46
- const options = deepClone(isObject(opts) ? deepMerge(opts, UPDATE_DEFAULT_OPTIONS) : UPDATE_DEFAULT_OPTIONS, { exclude: ['calleeElement'] })
50
+ const options = deepClone(
51
+ isObject(opts)
52
+ ? deepMerge(opts, UPDATE_DEFAULT_OPTIONS)
53
+ : UPDATE_DEFAULT_OPTIONS,
54
+ { exclude: ['calleeElement'] }
55
+ )
47
56
  options.calleeElement = calleeElementCache
48
57
  const element = this
49
58
  const { parent, node, key } = element
@@ -51,12 +60,20 @@ export const update = async function (params = {}, opts) {
51
60
 
52
61
  let ref = element.__ref
53
62
  if (!ref) ref = element.__ref = {}
54
- const [snapshotOnCallee, calleeElement, snapshotHasUpdated] = captureSnapshot(element, options)
63
+ const [snapshotOnCallee, calleeElement, snapshotHasUpdated] = captureSnapshot(
64
+ element,
65
+ options
66
+ )
55
67
  if (snapshotHasUpdated) return
56
68
 
57
- if (!options.preventListeners) await triggerEventOnUpdate('startUpdate', params, element, options)
69
+ if (!options.preventListeners)
70
+ await triggerEventOnUpdate('startUpdate', params, element, options)
58
71
 
59
- if (preventInheritAtCurrentState && preventInheritAtCurrentState.__element === element) return
72
+ if (
73
+ preventInheritAtCurrentState &&
74
+ preventInheritAtCurrentState.__element === element
75
+ )
76
+ return
60
77
  if (!excludes) merge(options, UPDATE_DEFAULT_OPTIONS)
61
78
 
62
79
  if (isString(params) || isNumber(params)) {
@@ -70,14 +87,20 @@ export const update = async function (params = {}, opts) {
70
87
  if (ifFails) return
71
88
 
72
89
  if (ref.__if && !options.preventPropsUpdate) {
73
- const hasParentProps = parent.props && (parent.props[key] || parent.props.childProps)
90
+ const hasParentProps =
91
+ parent.props && (parent.props[key] || parent.props.childProps)
74
92
  const hasFunctionInProps = ref.__props.filter(v => isFunction(v))
75
93
  const props = params.props || hasParentProps || hasFunctionInProps.length
76
94
  if (props) updateProps(props, element, parent)
77
95
  }
78
96
 
79
97
  if (!options.preventBeforeUpdateListener && !options.preventListeners) {
80
- const beforeUpdateReturns = await triggerEventOnUpdate('beforeUpdate', params, element, options)
98
+ const beforeUpdateReturns = await triggerEventOnUpdate(
99
+ 'beforeUpdate',
100
+ params,
101
+ element,
102
+ options
103
+ )
81
104
  if (beforeUpdateReturns === false) return element
82
105
  }
83
106
 
@@ -86,8 +109,8 @@ export const update = async function (params = {}, opts) {
86
109
 
87
110
  // exec updates
88
111
  throughExecProps(element)
89
- throughUpdatedExec(element, { ignore: UPDATE_DEFAULT_OPTIONS })
90
- throughUpdatedDefine(element)
112
+ await throughUpdatedExec(element, { ignore: UPDATE_DEFAULT_OPTIONS })
113
+ await throughUpdatedDefine(element)
91
114
 
92
115
  if (!options.isForced && !options.preventListeners) {
93
116
  await triggerEventOn('beforeClassAssign', element, options)
@@ -100,13 +123,24 @@ export const update = async function (params = {}, opts) {
100
123
  }
101
124
 
102
125
  const {
103
- preventUpdate, preventDefineUpdate, preventContentUpdate, preventStateUpdate,
104
- preventRecursive, preventUpdateListener, preventUpdateAfter, preventUpdateAfterCount
126
+ preventUpdate,
127
+ preventDefineUpdate,
128
+ preventContentUpdate,
129
+ preventStateUpdate,
130
+ preventRecursive,
131
+ preventUpdateListener,
132
+ preventUpdateAfter,
133
+ preventUpdateAfterCount
105
134
  } = options
106
135
 
107
136
  if (preventUpdateAfter) {
108
- if (isNumber(preventUpdateAfterCount) && preventUpdateAfter <= preventUpdateAfterCount) return
109
- else if (options.preventUpdateAfterCount === undefined) options.preventUpdateAfterCount = 1
137
+ if (
138
+ isNumber(preventUpdateAfterCount) &&
139
+ preventUpdateAfter <= preventUpdateAfterCount
140
+ )
141
+ return
142
+ else if (options.preventUpdateAfterCount === undefined)
143
+ options.preventUpdateAfterCount = 1
110
144
  else options.preventUpdateAfterCount++
111
145
  }
112
146
 
@@ -115,10 +149,15 @@ export const update = async function (params = {}, opts) {
115
149
 
116
150
  if (!Object.hasOwnProperty.call(element, param)) continue
117
151
 
118
- const isInPreventUpdate = isArray(preventUpdate) && preventUpdate.includes(param)
119
- const isInPreventDefineUpdate = isArray(preventDefineUpdate) && preventDefineUpdate.includes(param)
152
+ const isInPreventUpdate =
153
+ isArray(preventUpdate) && preventUpdate.includes(param)
154
+ const isInPreventDefineUpdate =
155
+ isArray(preventDefineUpdate) && preventDefineUpdate.includes(param)
120
156
 
121
- const hasCollection = element.$collection || element.$stateCollection || element.$propsCollection
157
+ const hasCollection =
158
+ element.$collection ||
159
+ element.$stateCollection ||
160
+ element.$propsCollection
122
161
 
123
162
  if (
124
163
  isUndefined(prop) ||
@@ -128,15 +167,19 @@ export const update = async function (params = {}, opts) {
128
167
  preventDefineUpdate === param ||
129
168
  (preventContentUpdate && param === 'content' && !hasCollection) ||
130
169
  (preventStateUpdate && param) === 'state' ||
131
- isMethod(param, element) || isObject(REGISTRY[param]) || isVariant(param)
132
- ) continue
170
+ isMethod(param, element) ||
171
+ isObject(REGISTRY[param]) ||
172
+ isVariant(param)
173
+ )
174
+ continue
133
175
 
134
176
  if (preventStateUpdate === 'once') options.preventStateUpdate = false
135
177
 
136
178
  const isElement = await applyParam(param, element, options)
137
179
  if (isElement) {
138
180
  const { hasDefine, hasContextDefine } = isElement
139
- const canUpdate = isObject(prop) && !hasDefine && !hasContextDefine && !preventRecursive
181
+ const canUpdate =
182
+ isObject(prop) && !hasDefine && !hasContextDefine && !preventRecursive
140
183
  if (!canUpdate) continue
141
184
 
142
185
  const lazyLoad = element.props.lazyLoad || options.lazyLoad
@@ -145,19 +188,23 @@ export const update = async function (params = {}, opts) {
145
188
  options.onEachUpdate(param, element, element.state, element.context)
146
189
  }
147
190
 
148
- const childUpdateCall = async () => await update.call(prop, params[prop], {
149
- ...options,
150
- currentSnapshot: snapshotOnCallee,
151
- calleeElement
152
- })
153
-
154
- lazyLoad ? window.requestAnimationFrame(async () => { // eslint-disable-line
155
- await childUpdateCall()
156
- // handle lazy load
157
- if (!options.preventUpdateListener) {
158
- await triggerEventOn('lazyLoad', element, options)
159
- }
160
- }) : await childUpdateCall()
191
+ const childUpdateCall = async () =>
192
+ await update.call(prop, params[prop], {
193
+ ...options,
194
+ currentSnapshot: snapshotOnCallee,
195
+ calleeElement
196
+ })
197
+
198
+ lazyLoad
199
+ ? window.requestAnimationFrame(async () => {
200
+ // eslint-disable-line
201
+ await childUpdateCall()
202
+ // handle lazy load
203
+ if (!options.preventUpdateListener) {
204
+ await triggerEventOn('lazyLoad', element, options)
205
+ }
206
+ })
207
+ : await childUpdateCall()
161
208
  }
162
209
  }
163
210
 
@@ -185,10 +232,16 @@ const captureSnapshot = (element, options) => {
185
232
  }
186
233
 
187
234
  const checkIfOnUpdate = (element, parent, options) => {
188
- if ((!isFunction(element.if) && !isFunction(element.props?.if)) || !parent) return
235
+ if ((!isFunction(element.if) && !isFunction(element.props?.if)) || !parent)
236
+ return
189
237
 
190
238
  const ref = element.__ref
191
- const ifPassed = (element.if || element.props?.if)(element, element.state, element.context, options)
239
+ const ifPassed = (element.if || element.props?.if)(
240
+ element,
241
+ element.state,
242
+ element.context,
243
+ options
244
+ )
192
245
  const itWasFalse = ref.__if !== true
193
246
 
194
247
  if (ifPassed) {
@@ -214,9 +267,14 @@ const checkIfOnUpdate = (element, parent, options) => {
214
267
 
215
268
  const contentKey = ref.contentElementKey
216
269
 
217
- if (element.$collection || element.$stateCollection || element.$propsCollection) {
270
+ if (
271
+ element.$collection ||
272
+ element.$stateCollection ||
273
+ element.$propsCollection
274
+ ) {
218
275
  element.removeContent()
219
- } else if (element[contentKey]?.parseDeep) element[contentKey] = element[contentKey].parseDeep()
276
+ } else if (element[contentKey]?.parseDeep)
277
+ element[contentKey] = element[contentKey].parseDeep()
220
278
 
221
279
  const previousElement = element.previousElement()
222
280
  const previousNode = previousElement?.node // document.body.contains(previousElement.node)
@@ -234,9 +292,19 @@ const checkIfOnUpdate = (element, parent, options) => {
234
292
 
235
293
  delete element.__ref
236
294
  delete element.parent
237
- const createdElement = create(element, parent, element.key, OPTIONS.create, attachOptions)
295
+ const createdElement = create(
296
+ element,
297
+ parent,
298
+ element.key,
299
+ OPTIONS.create,
300
+ attachOptions
301
+ )
238
302
  // check preventUpdate for an array (Line: 87)
239
- if (options.preventUpdate !== true && element.on && isFunction(element.on.update)) {
303
+ if (
304
+ options.preventUpdate !== true &&
305
+ element.on &&
306
+ isFunction(element.on.update)
307
+ ) {
240
308
  applyEvent(element.on.update, createdElement, createdElement.state)
241
309
  }
242
310
  return createdElement
@@ -265,7 +333,8 @@ const inheritStateUpdates = async (element, options) => {
265
333
  const { __ref: ref } = element
266
334
  const stateKey = ref.__state
267
335
  const { parent, state } = element
268
- const { preventUpdateTriggerStateUpdate, isHoisted, execStateFunction } = options
336
+ const { preventUpdateTriggerStateUpdate, isHoisted, execStateFunction } =
337
+ options
269
338
 
270
339
  if (preventUpdateTriggerStateUpdate) return
271
340
 
@@ -276,10 +345,16 @@ const inheritStateUpdates = async (element, options) => {
276
345
  }
277
346
 
278
347
  // If state is function, decide execution and apply setting a current state
279
- const shouldForceFunctionState = isFunction(stateKey) && !isHoisted && execStateFunction
348
+ const shouldForceFunctionState =
349
+ isFunction(stateKey) && !isHoisted && execStateFunction
280
350
  if (shouldForceFunctionState) {
281
351
  const execState = exec(stateKey, element)
282
- state.set(execState, { ...options, preventUpdate: true, preventStateUpdateListener: false, updatedByStateFunction: true })
352
+ state.set(execState, {
353
+ ...options,
354
+ preventUpdate: true,
355
+ preventStateUpdateListener: false,
356
+ updatedByStateFunction: true
357
+ })
283
358
  return
284
359
  }
285
360
 
@@ -289,7 +364,12 @@ const inheritStateUpdates = async (element, options) => {
289
364
 
290
365
  // Trigger on.beforeStateUpdate event
291
366
  if (!options.preventBeforeStateUpdateListener && !options.preventListeners) {
292
- const initStateReturns = await triggerEventOnUpdate('beforeStateUpdate', keyInParentState, element, options)
367
+ const initStateReturns = await triggerEventOnUpdate(
368
+ 'beforeStateUpdate',
369
+ keyInParentState,
370
+ element,
371
+ options
372
+ )
293
373
  if (initStateReturns === false) return element
294
374
  }
295
375
 
@@ -298,7 +378,12 @@ const inheritStateUpdates = async (element, options) => {
298
378
 
299
379
  // Trigger on.stateUpdate event
300
380
  if (!options.preventStateUpdateListener && !options.preventListeners) {
301
- await triggerEventOnUpdate('stateUpdate', newState.parse(), element, options)
381
+ await triggerEventOnUpdate(
382
+ 'stateUpdate',
383
+ newState.parse(),
384
+ element,
385
+ options
386
+ )
302
387
  }
303
388
  }
304
389