domql 1.6.15 → 1.6.16

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "domql",
3
3
  "description": "DOM rendering Javascript framework at early stage.",
4
- "version": "1.6.15",
4
+ "version": "1.6.16",
5
5
  "repository": "https://github.com/domql/domql",
6
6
  "publishConfig": {
7
7
  "registry": "https://registry.npmjs.org"
@@ -204,40 +204,41 @@ const checkIf = (element, parent) => {
204
204
  }
205
205
 
206
206
  const addCaching = (element, parent) => {
207
- const { __ref } = element
208
- let { __ref: __parentRef } = parent
207
+ const { __ref: ref } = element
208
+ let { __ref: parentRef } = parent
209
209
 
210
210
  // enable TRANSFORM in data
211
211
  if (!element.transform) element.transform = {}
212
212
 
213
213
  // enable CACHING
214
- if (!__ref.__cached) __ref.__cached = {}
214
+ if (!ref.__cached) ref.__cached = {}
215
+ if (!ref.__defineCache) ref.__defineCache = {}
215
216
 
216
217
  // enable EXEC
217
- if (!__ref.__exec) __ref.__exec = {}
218
+ if (!ref.__exec) ref.__exec = {}
218
219
 
219
220
  // enable CLASS CACHING
220
- if (!__ref.__class) __ref.__class = {}
221
- if (!__ref.__classNames) __ref.__classNames = {}
221
+ if (!ref.__class) ref.__class = {}
222
+ if (!ref.__classNames) ref.__classNames = {}
222
223
 
223
224
  // enable CLASS CACHING
224
- if (!__ref.__attr) __ref.__attr = {}
225
+ if (!ref.__attr) ref.__attr = {}
225
226
 
226
227
  // enable CHANGES storing
227
- if (!__ref.__changes) __ref.__changes = []
228
+ if (!ref.__changes) ref.__changes = []
228
229
 
229
230
  // enable CHANGES storing
230
- if (!__ref.__children) __ref.__children = []
231
+ if (!ref.__children) ref.__children = []
231
232
 
232
233
  // Add _root element property
233
234
  const hasRoot = parent && parent.key === ':root'
234
- if (!__ref.__root) __ref.__root = hasRoot ? element : __parentRef.__root
235
+ if (!ref.__root) ref.__root = hasRoot ? element : parentRef.__root
235
236
 
236
237
  // set the PATH array
237
238
  if (ENV === 'test' || ENV === 'development') {
238
- if (!__parentRef) __parentRef = parent.__ref = {}
239
- if (!__parentRef.__path) __parentRef.__path = []
240
- __ref.__path = __parentRef.__path.concat(element.key)
239
+ if (!parentRef) parentRef = parent.ref = {}
240
+ if (!parentRef.__path) parentRef.__path = []
241
+ ref.__path = parentRef.__path.concat(element.key)
241
242
  }
242
243
  }
243
244
 
@@ -1,35 +1,36 @@
1
1
  'use strict'
2
2
 
3
3
  import { isObject, exec, isFunction, isNumber, isString } from '@domql/utils'
4
- import { overwrite } from '../utils'
4
+ import { METHODS_EXL, overwrite } from '../utils'
5
5
  import { isMethod } from '@domql/methods'
6
6
 
7
7
  export const throughInitialExec = element => {
8
- const { __ref } = element
9
- const { __exec } = __ref
8
+ const { __ref: ref } = element
10
9
  for (const param in element) {
11
10
  const prop = element[param]
12
11
  if (isFunction(prop) && !isMethod(param)) {
13
- __exec[param] = prop
12
+ ref.__exec[param] = prop
14
13
  element[param] = prop(element, element.state)
15
14
  }
16
15
  }
17
16
  }
18
17
 
19
- export const throughUpdatedExec = (element, options) => {
20
- const { __ref } = element
21
- const { __exec, __cached } = __ref
18
+ export const throughUpdatedExec = (element, options = { excludes: METHODS_EXL }) => {
19
+ const { __ref: ref } = element
22
20
  const changes = {}
23
21
 
24
- for (const param in __exec) {
22
+ for (const param in ref.__exec) {
25
23
  const prop = element[param]
26
- const newExec = __exec[param](element, element.state)
27
24
 
28
- // if element is string
29
- if (prop && prop.node && (isString(newExec) || isNumber(newExec))) {
25
+ const isDefinedParam = ref.__defineCache[param]
26
+ if (isDefinedParam) continue
27
+
28
+ const newExec = ref.__exec[param](element, element.state)
29
+ const execReturnsString = isString(newExec) || isNumber(newExec)
30
+ if (prop && prop.node && execReturnsString) {
30
31
  overwrite(prop, { text: newExec }, options)
31
32
  } else if (newExec !== prop) {
32
- __cached[param] = changes[param] = prop
33
+ ref.__cached[param] = changes[param] = prop
33
34
  element[param] = newExec
34
35
  }
35
36
  }
@@ -38,32 +39,34 @@ export const throughUpdatedExec = (element, options) => {
38
39
  }
39
40
 
40
41
  export const throughInitialDefine = (element) => {
41
- const { define, context, __ref } = element
42
- const { __exec, __cached } = __ref
42
+ const { define, context, __ref: ref } = element
43
43
 
44
- let obj = {}
45
- if (isObject(define)) obj = { ...define }
46
- if (context && isObject(context.define)) obj = { ...obj, ...context.define }
44
+ let defineObj = {}
45
+ const hasGlobalDefine = context && isObject(context.define)
46
+ if (isObject(define)) defineObj = { ...define }
47
+ if (hasGlobalDefine) defineObj = { ...defineObj, ...context.define }
47
48
 
48
- for (const param in obj) {
49
- let prop = element[param]
49
+ for (const param in defineObj) {
50
+ let elementProp = element[param]
50
51
 
51
- if (isFunction(prop) && !isMethod(param)) {
52
- __exec[param] = prop
53
- const execParam = prop = exec(prop, element)
54
- if (execParam) element[param] = execParam
52
+ if (isFunction(elementProp) && !isMethod(param)) {
53
+ ref.__exec[param] = elementProp
54
+ const execParam = elementProp = exec(elementProp, element)
55
+
56
+ if (execParam) {
57
+ elementProp = element[param] = execParam.parse ? execParam.parse() : execParam
58
+ ref.__defineCache[param] = elementProp
59
+ }
55
60
  }
56
61
 
57
- __cached[param] = prop
58
- const execParam = obj[param](prop, element, element.state)
62
+ const execParam = defineObj[param](elementProp, element, element.state)
59
63
  if (execParam) element[param] = execParam
60
64
  }
61
65
  return element
62
66
  }
63
67
 
64
68
  export const throughUpdatedDefine = (element) => {
65
- const { context, define, __ref } = element
66
- const { __exec, __cached } = __ref
69
+ const { context, define, __ref: ref } = element
67
70
  const changes = {}
68
71
 
69
72
  let obj = {}
@@ -71,9 +74,9 @@ export const throughUpdatedDefine = (element) => {
71
74
  if (isObject(context && context.define)) obj = { ...obj, ...context.define }
72
75
 
73
76
  for (const param in obj) {
74
- const execParam = __exec[param]
75
- if (execParam) __cached[param] = execParam(element, element.state)
76
- const cached = exec(__cached[param], element)
77
+ const execParam = ref.__exec[param]
78
+ if (execParam) ref.__defineCache[param] = execParam(element, element.state)
79
+ const cached = exec(ref.__defineCache[param], element)
77
80
  const newExecParam = obj[param](cached, element, element.state)
78
81
  if (newExecParam) element[param] = newExecParam
79
82
  }
@@ -1,14 +1,14 @@
1
1
  'use strict'
2
2
 
3
3
  import { window } from '@domql/globals'
4
- import { exec, isFunction, isNumber, isObject, isString, overwriteDeep } from '@domql/utils'
4
+ import { exec, isFunction, isNumber, isObject, isString, merge, overwriteDeep } from '@domql/utils'
5
5
  import { applyEvent, triggerEventOn } from '@domql/event'
6
6
  import { isMethod } from '@domql/methods'
7
7
  import { createSnapshotId } from '@domql/key'
8
8
  import { updateProps } from '@domql/props'
9
9
  import { createState } from '@domql/state'
10
10
 
11
- import { METHODS_EXL, merge } from '../utils'
11
+ import { METHODS_EXL } from '../utils'
12
12
  import create from './create'
13
13
  import { throughUpdatedDefine, throughUpdatedExec } from './iterate'
14
14
  import { registry } from './mixins'
@@ -23,13 +23,16 @@ const UPDATE_DEFAULT_OPTIONS = {
23
23
  cleanExec: true,
24
24
  preventRecursive: false,
25
25
  currentSnapshot: false,
26
- calleeElement: false
26
+ calleeElement: false,
27
+ excludes: METHODS_EXL
27
28
  }
28
29
 
29
30
  const update = function (params = {}, options = UPDATE_DEFAULT_OPTIONS) {
30
31
  const element = this
31
32
  const { parent, node, key } = element
32
33
 
34
+ if (!options.excludes) merge(options, UPDATE_DEFAULT_OPTIONS)
35
+
33
36
  let __ref = element.__ref
34
37
  if (!__ref) __ref = element.__ref = {}
35
38
 
@@ -59,7 +62,7 @@ const update = function (params = {}, options = UPDATE_DEFAULT_OPTIONS) {
59
62
  }
60
63
 
61
64
  const overwriteChanges = overwriteDeep(element, params, METHODS_EXL)
62
- const execChanges = throughUpdatedExec(element, UPDATE_DEFAULT_OPTIONS)
65
+ const execChanges = throughUpdatedExec(element, { ignore: UPDATE_DEFAULT_OPTIONS })
63
66
  const definedChanges = throughUpdatedDefine(element)
64
67
 
65
68
  if (options.stackChanges && element.__stackChanges) {
@@ -167,11 +170,11 @@ const inheritStateUpdates = (element, options) => {
167
170
  return
168
171
  }
169
172
 
170
- if (isFunction(stateKey)) {
173
+ if (options.forceStateFunction && isFunction(stateKey)) {
171
174
  const execState = exec(stateKey, element)
172
175
  state.update(execState, {
173
176
  ...options,
174
- skipOverwrite: 'merge',
177
+ skipOverwrite: options.stateFunctionOverwrite,
175
178
  preventUpdateTriggerStateUpdate: true
176
179
  })
177
180
  return false
@@ -12,17 +12,6 @@ export const METHODS_EXL = joinArrays(
12
12
  IGNORE_PROPS_PARAMS
13
13
  )
14
14
 
15
- export const merge = (element, obj) => {
16
- for (const e in obj) {
17
- const elementProp = element[e]
18
- const objProp = obj[e]
19
- if (elementProp === undefined) {
20
- element[e] = objProp
21
- }
22
- }
23
- return element
24
- }
25
-
26
15
  export const deepMerge = (element, extend, exclude = METHODS_EXL) => {
27
16
  for (const e in extend) {
28
17
  if (exclude.includes(e)) continue