domql 1.6.17 → 1.6.19

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.17",
4
+ "version": "1.6.19",
5
5
  "repository": "https://github.com/domql/domql",
6
6
  "publishConfig": {
7
7
  "registry": "https://registry.npmjs.org"
@@ -25,7 +25,7 @@ import {
25
25
  applyComponentFromContext,
26
26
  applyKeyComponentAsExtend,
27
27
  checkIfKeyIsComponent
28
- } from '../utils/component'
28
+ } from './utils/component'
29
29
  import { removeContentElement } from './remove'
30
30
 
31
31
  const ENV = process.env.NODE_ENV
@@ -126,11 +126,11 @@ const create = (element, parent, key, options = OPTIONS.create || {}) => {
126
126
  if (__ref.__if) createProps(element, parent)
127
127
 
128
128
  // run `on.init`
129
- const initReturns = triggerEventOn('init', element)
129
+ const initReturns = triggerEventOn('init', element, options)
130
130
  if (initReturns === false) return element
131
131
 
132
132
  // run `on.beforeClassAssign`
133
- triggerEventOn('beforeClassAssign', element)
133
+ triggerEventOn('beforeClassAssign', element, options)
134
134
 
135
135
  // generate a CLASS name
136
136
  assignClass(element)
@@ -144,10 +144,10 @@ const create = (element, parent, key, options = OPTIONS.create || {}) => {
144
144
  assignNode(element, parent, key)
145
145
 
146
146
  // run `on.renderRouter`
147
- triggerEventOn('renderRouter', element)
147
+ triggerEventOn('renderRouter', element, options)
148
148
 
149
149
  // run `on.render`
150
- triggerEventOn('render', element)
150
+ triggerEventOn('render', element, options)
151
151
 
152
152
  if (parent.__ref && parent.__ref.__children) parent.__ref.__children.push(element.key)
153
153
 
@@ -193,17 +193,17 @@ const applyContext = (element, parent, options) => {
193
193
  }
194
194
 
195
195
  const checkIf = (element, parent) => {
196
- const { __ref } = element
196
+ const { __ref: ref } = element
197
197
 
198
198
  if (isFunction(element.if)) {
199
199
  // TODO: move as fragment
200
200
  const ifPassed = element.if(element, element.state)
201
201
  if (!ifPassed) {
202
202
  const ifFragment = cacheNode({ tag: 'fragment' })
203
- __ref.__ifFragment = appendNode(ifFragment, parent.node)
204
- delete __ref.__if
205
- } else __ref.__if = true
206
- } else __ref.__if = true
203
+ ref.__ifFragment = appendNode(ifFragment, parent.node)
204
+ delete ref.__if
205
+ } else ref.__if = true
206
+ } else ref.__if = true
207
207
  }
208
208
 
209
209
  const addCaching = (element, parent) => {
@@ -1,7 +1,7 @@
1
1
  'use strict'
2
2
 
3
3
  import { isFunction, exec, isString } from '@domql/utils'
4
- import { getExtendStack, jointStacks, cloneAndMergeArrayExtend, deepMergeExtend, replaceStringsWithComponents } from '../utils'
4
+ import { getExtendStack, jointStacks, cloneAndMergeArrayExtend, deepMergeExtend, replaceStringsWithComponents } from './utils'
5
5
 
6
6
  const ENV = process.env.NODE_ENV
7
7
 
@@ -1,7 +1,7 @@
1
1
  'use strict'
2
2
 
3
3
  import { isObject, exec, isFunction, isNumber, isString } from '@domql/utils'
4
- import { METHODS_EXL, 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 => {
@@ -12,7 +12,7 @@ export default (param, element, node, options) => {
12
12
  // const parsedContent = element.content.parseDeep(['class', 'on', 'tag'])
13
13
  // console.log(parsedContent)
14
14
  // if (!element.content.__ref) element.content.__ref = {}
15
- element.content.update()
15
+ element.content.update({}, options)
16
16
  } else {
17
17
  // if (element.$setCollection || element.$setStateCollection || element.$setPropsCollection) return
18
18
  set.call(element, param, options)
@@ -19,21 +19,21 @@ const ENV = process.env.NODE_ENV
19
19
 
20
20
  export const createNode = (element, options) => {
21
21
  // create and assign a node
22
- let { node, tag, __ref } = element
22
+ let { node, tag, __ref: ref } = element
23
23
 
24
24
  let isNewNode
25
25
 
26
26
  if (!node) {
27
27
  isNewNode = true
28
28
 
29
- if (!__ref.__if) return element
29
+ if (!ref.__if) return element
30
30
 
31
31
  if (tag === 'shadow') {
32
32
  node = element.node = element.parent.node.attachShadow({ mode: 'open' })
33
33
  } else node = element.node = cacheNode(element)
34
34
 
35
35
  // trigger `on.attachNode`
36
- triggerEventOn('attachNode', element)
36
+ triggerEventOn('attachNode', element, options)
37
37
  }
38
38
 
39
39
  // node.dataset // .key = element.key
@@ -43,7 +43,7 @@ export const createNode = (element, options) => {
43
43
  if (isFunction(node.setAttribute)) node.setAttribute('key', element.key)
44
44
  }
45
45
 
46
- if (!__ref.__if) return element
46
+ if (!ref.__if) return element
47
47
 
48
48
  // iterate through all given params
49
49
  if (element.tag !== 'string' || element.tag !== 'fragment') {
@@ -2,13 +2,13 @@
2
2
 
3
3
  import { window } from '@domql/globals'
4
4
  import { exec, isFunction, isNumber, isObject, isString, merge, overwriteDeep } from '@domql/utils'
5
- import { applyEvent, triggerEventOn } from '@domql/event'
5
+ import { applyEvent, triggerEventOn, triggerEventOnUpdate } 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 } 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'
@@ -36,8 +36,8 @@ const update = function (params = {}, options = UPDATE_DEFAULT_OPTIONS) {
36
36
  if (preventInheritAtCurrentState && preventInheritAtCurrentState.__element === element) return
37
37
  if (!excludes) merge(options, UPDATE_DEFAULT_OPTIONS)
38
38
 
39
- let __ref = element.__ref
40
- if (!__ref) __ref = element.__ref = {}
39
+ let ref = element.__ref
40
+ if (!ref) ref = element.__ref = {}
41
41
 
42
42
  const [snapshotOnCallee, calleeElement, snapshotHasUpdated] = captureSnapshot(element, options)
43
43
  if (snapshotHasUpdated) return
@@ -46,21 +46,21 @@ const update = function (params = {}, options = UPDATE_DEFAULT_OPTIONS) {
46
46
  params = { text: params }
47
47
  }
48
48
 
49
- const ifFails = checkIfOnUpdate(element, parent, options,)
49
+ const ifFails = checkIfOnUpdate(element, parent, options)
50
50
  if (ifFails) return
51
51
 
52
52
  const inheritState = inheritStateUpdates(element, options)
53
53
  if (inheritState === false) return
54
54
 
55
- if (__ref.__if && !options.preventPropsUpdate) {
55
+ if (ref.__if && !options.preventPropsUpdate) {
56
56
  const hasParentProps = parent.props && (parent.props[key] || parent.props.childProps)
57
- const hasFunctionInProps = element.__ref.__props.filter(v => isFunction(v))
57
+ const hasFunctionInProps = ref.__props.filter(v => isFunction(v))
58
58
  const props = params.props || hasParentProps || hasFunctionInProps.length
59
59
  if (props) updateProps(props, element, parent)
60
60
  }
61
61
 
62
62
  if (!options.preventInitUpdateListener) {
63
- const initUpdateReturns = triggerEventOn('initUpdate', element, params)
63
+ const initUpdateReturns = triggerEventOnUpdate('initUpdate', params, element, options)
64
64
  if (initUpdateReturns === false) return element
65
65
  }
66
66
 
@@ -73,7 +73,7 @@ const update = function (params = {}, options = UPDATE_DEFAULT_OPTIONS) {
73
73
  element.__stackChanges.push(stackChanges)
74
74
  }
75
75
 
76
- if (!__ref.__if) return false
76
+ if (!ref.__if) return false
77
77
  if (!node) {
78
78
  // return createNode(element, options)
79
79
  return
@@ -109,21 +109,21 @@ const update = function (params = {}, options = UPDATE_DEFAULT_OPTIONS) {
109
109
  }
110
110
  }
111
111
 
112
- if (!options.preventUpdateListener) triggerEventOn('update', element)
112
+ if (!options.preventUpdateListener) triggerEventOn('update', element, options)
113
113
  }
114
114
 
115
115
  const captureSnapshot = (element, options) => {
116
- const __ref = element.__ref
116
+ const ref = element.__ref
117
117
 
118
118
  const { currentSnapshot, calleeElement } = options
119
119
  const isCallee = calleeElement === element
120
120
  if (!calleeElement || isCallee) {
121
121
  const createdStanpshot = snapshot.snapshotId()
122
- __ref.__currentSnapshot = createdStanpshot
122
+ ref.__currentSnapshot = createdStanpshot
123
123
  return [createdStanpshot, element]
124
124
  }
125
125
 
126
- const snapshotOnCallee = calleeElement.__ref.__currentSnapshot
126
+ const snapshotOnCallee = ref.__currentSnapshot
127
127
  if (currentSnapshot < snapshotOnCallee) {
128
128
  return [snapshotOnCallee, calleeElement, true]
129
129
  }
@@ -135,7 +135,7 @@ const checkIfOnUpdate = (element, parent, options) => {
135
135
  if (!isFunction(element.if)) return
136
136
 
137
137
  const ref = element.__ref
138
- const ifPassed = element.if(element, element.state)
138
+ const ifPassed = element.if(element, element.state, element.context)
139
139
  const itWasFalse = ref.__if !== true
140
140
 
141
141
  if (ifPassed) {
@@ -162,43 +162,55 @@ const checkIfOnUpdate = (element, parent, options) => {
162
162
  }
163
163
 
164
164
  const inheritStateUpdates = (element, options) => {
165
- const { __ref } = element
166
- const stateKey = __ref.__state
165
+ const { __ref: ref } = element
166
+ const stateKey = ref.__state
167
167
  const { parent, state } = element
168
168
 
169
- if (options.preventUpdateTriggerStateUpdate) return
169
+ if (options.preventpdateTriggerStateUpdate) return
170
170
 
171
- if (!stateKey && !__ref.__hasRootState) {
171
+ if (!stateKey && !ref.__hasRootState) {
172
172
  element.state = (parent && parent.state) || {}
173
173
  return
174
174
  }
175
175
 
176
- if (options.forceStateFunction && isFunction(stateKey)) {
176
+ const { isHoisted, execStateFunction, stateFunctionOverwrite } = options
177
+ const shouldForceStateUpdate = isFunction(stateKey) && (!isHoisted && execStateFunction && stateFunctionOverwrite)
178
+ if (shouldForceStateUpdate) {
177
179
  const execState = exec(stateKey, element)
178
- state.update(execState, {
180
+ state.set(execState, {
179
181
  ...options,
180
- skipOverwrite: options.stateFunctionOverwrite,
181
- preventUpdateTriggerStateUpdate: true
182
+ preventUpdate: true
182
183
  })
183
- return false
184
+ return
184
185
  }
185
186
 
186
187
  const parentState = (parent && parent.state) || {}
187
188
  const keyInParentState = parentState[stateKey]
188
189
 
189
- if (!keyInParentState) return
190
+ if (!keyInParentState || options.preventInheritedStateUpdate) return
190
191
 
191
- if (!options.preventInitStateUpdateListener && !options.updateByState) {
192
- const initStateReturns = triggerEventOn('initStateUpdated', element, keyInParentState)
192
+ if (!options.preventInitStateUpdateListener) {
193
+ const initStateReturns = triggerEventOnUpdate('initStateUpdated', keyInParentState, element, options)
193
194
  if (initStateReturns === false) return element
194
195
  }
195
196
 
197
+ const newState = createStateUpdate(element, parent, options)
198
+
199
+ if (!options.preventStateUpdateListener) {
200
+ triggerEventOnUpdate('stateUpdated', newState.parse(), element, options)
201
+ }
202
+ }
203
+
204
+ const createStateUpdate = (element, parent, options) => {
205
+ const __stateChildren = element.state.__children
196
206
  const newState = createState(element, parent)
197
207
  element.state = newState
198
-
199
- if (!options.preventStateUpdateListener && !options.updateByState) {
200
- triggerEventOn('stateUpdated', element, newState.parse())
208
+ for (const child in __stateChildren) {
209
+ // check this for inherited states
210
+ if (newState[child]) newState.__children[child] = __stateChildren[child]
211
+ __stateChildren[child].parent = newState
201
212
  }
213
+ return newState
202
214
  }
203
215
 
204
216
  export default update
File without changes
File without changes
File without changes
File without changes