domql 1.6.8 → 1.6.9
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 +1 -1
- package/src/element/state.js +17 -3
- package/src/element/update.js +10 -2
package/package.json
CHANGED
package/src/element/state.js
CHANGED
|
@@ -1,7 +1,18 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
3
|
import { triggerEventOn } from '@domql/event'
|
|
4
|
-
import {
|
|
4
|
+
import {
|
|
5
|
+
is,
|
|
6
|
+
isObject,
|
|
7
|
+
exec,
|
|
8
|
+
isFunction,
|
|
9
|
+
arrayContainsOtherArray,
|
|
10
|
+
isObjectLike,
|
|
11
|
+
isArray,
|
|
12
|
+
removeFromArray,
|
|
13
|
+
removeFromObject,
|
|
14
|
+
isNot
|
|
15
|
+
} from '@domql/utils'
|
|
5
16
|
import { deepClone, overwriteShallow, overwriteDeep } from '../utils'
|
|
6
17
|
import { create } from '.'
|
|
7
18
|
|
|
@@ -179,7 +190,7 @@ const getChildStateInKey = (stateKey, parentState) => {
|
|
|
179
190
|
const createInheritedState = function (element, parent) {
|
|
180
191
|
const __elementRef = element.__ref
|
|
181
192
|
let stateKey = __elementRef.__state
|
|
182
|
-
if (!stateKey) return element.state
|
|
193
|
+
if (!stateKey || isNot(stateKey)('number', 'string')) return element.state
|
|
183
194
|
|
|
184
195
|
let parentState = parent.state
|
|
185
196
|
if (stateKey.includes('../')) {
|
|
@@ -206,7 +217,10 @@ export const createState = function (element, parent, opts) {
|
|
|
206
217
|
const skip = (opts && opts.skip) ? opts.skip : false
|
|
207
218
|
let { state, __ref: __elementRef } = element
|
|
208
219
|
|
|
209
|
-
if (isFunction(state))
|
|
220
|
+
if (isFunction(state)) {
|
|
221
|
+
__elementRef.__state = state
|
|
222
|
+
state = element.state = exec(state, element)
|
|
223
|
+
}
|
|
210
224
|
|
|
211
225
|
if (is(state)('string', 'number')) {
|
|
212
226
|
__elementRef.__state = state
|
package/src/element/update.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
3
|
import { window } from '@domql/globals'
|
|
4
|
-
import { isFunction, isNumber, isObject, isString } from '@domql/utils'
|
|
4
|
+
import { exec, isFunction, isNumber, isObject, isString } 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'
|
|
@@ -158,13 +158,21 @@ const checkIfOnUpdate = (element, options) => {
|
|
|
158
158
|
const inheritStateUpdates = (element, options) => {
|
|
159
159
|
const { __ref } = element
|
|
160
160
|
const stateKey = __ref.__state
|
|
161
|
-
const { parent } = element
|
|
161
|
+
const { parent, state } = element
|
|
162
|
+
|
|
163
|
+
if (options.preventUpdateTriggerStateUpdate) return
|
|
162
164
|
|
|
163
165
|
if (!stateKey && !__ref.__hasRootState) {
|
|
164
166
|
element.state = (parent && parent.state) || {}
|
|
165
167
|
return
|
|
166
168
|
}
|
|
167
169
|
|
|
170
|
+
if (isFunction(stateKey)) {
|
|
171
|
+
const execState = exec(stateKey, element)
|
|
172
|
+
state.update(execState, { preventUpdateTriggerStateUpdate: true, ...options })
|
|
173
|
+
return false
|
|
174
|
+
}
|
|
175
|
+
|
|
168
176
|
const parentState = (parent && parent.state) || {}
|
|
169
177
|
const keyInParentState = parentState[stateKey]
|
|
170
178
|
|