domql 1.6.7 → 1.6.8
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 +29 -16
package/package.json
CHANGED
package/src/element/state.js
CHANGED
|
@@ -6,7 +6,7 @@ import { deepClone, overwriteShallow, overwriteDeep } from '../utils'
|
|
|
6
6
|
import { create } from '.'
|
|
7
7
|
|
|
8
8
|
export const IGNORE_STATE_PARAMS = [
|
|
9
|
-
'update', 'parse', 'clean', 'create', 'destroy', 'remove', 'apply', 'rootUpdate',
|
|
9
|
+
'update', 'parse', 'clean', 'create', 'destroy', 'add', 'remove', 'apply', 'rootUpdate',
|
|
10
10
|
'parent', '__element', '__depends', '__ref', '__children', '__root'
|
|
11
11
|
]
|
|
12
12
|
|
|
@@ -73,15 +73,7 @@ export const updateState = function (obj, options = {}) {
|
|
|
73
73
|
const parentState = element.parent.state
|
|
74
74
|
state.parent = parentState
|
|
75
75
|
|
|
76
|
-
|
|
77
|
-
if (isUndefined(state[param])) {
|
|
78
|
-
delete state[param]
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
if (!state.__element) {
|
|
83
|
-
create(element, element.parent)
|
|
84
|
-
}
|
|
76
|
+
if (!state.__element && options.createElementFallback) { create(element, element.parent) }
|
|
85
77
|
|
|
86
78
|
const initStateUpdateReturns = triggerEventOn('initStateUpdated', element, obj)
|
|
87
79
|
if (initStateUpdateReturns === false) return element
|
|
@@ -99,9 +91,20 @@ export const updateState = function (obj, options = {}) {
|
|
|
99
91
|
if (shouldPropagateState) {
|
|
100
92
|
const isStringState = (__elementRef.__stateType === 'string')
|
|
101
93
|
const value = isStringState ? state.value : state.parse()
|
|
94
|
+
const passedValue = isStringState ? state.value : obj
|
|
95
|
+
|
|
102
96
|
parentState[stateKey] = value
|
|
103
|
-
parentState.update(
|
|
104
|
-
|
|
97
|
+
parentState.update({ [stateKey]: passedValue }, {
|
|
98
|
+
skipOverwrite: true,
|
|
99
|
+
preventUpdate: options.preventHoistElementUpdate,
|
|
100
|
+
...options
|
|
101
|
+
})
|
|
102
|
+
|
|
103
|
+
if (!options.preventUpdateListener) {
|
|
104
|
+
triggerEventOn('stateUpdated', element, value)
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
if (!options.preventHoistElementUpdate) return state
|
|
105
108
|
}
|
|
106
109
|
|
|
107
110
|
if (!options.preventUpdate) {
|
|
@@ -124,18 +127,27 @@ export const updateState = function (obj, options = {}) {
|
|
|
124
127
|
return state
|
|
125
128
|
}
|
|
126
129
|
|
|
127
|
-
export const
|
|
130
|
+
export const add = function (value, options = {}) {
|
|
131
|
+
const state = this
|
|
132
|
+
if (isArray(state)) {
|
|
133
|
+
state.push(value)
|
|
134
|
+
console.log(state)
|
|
135
|
+
state.update(state.parse(), { skipOverwrite: true, ...options })
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
export const remove = function (key, options = {}) {
|
|
128
140
|
const state = this
|
|
129
141
|
if (isArray(state)) removeFromArray(state, key)
|
|
130
142
|
if (isObject(state)) removeFromObject(state, key)
|
|
131
|
-
return state.update(state, { skipOverwrite: true, options })
|
|
143
|
+
return state.update(state.parse(), { skipOverwrite: true, ...options })
|
|
132
144
|
}
|
|
133
145
|
|
|
134
|
-
export const apply = function (func, options) {
|
|
146
|
+
export const apply = function (func, options = {}) {
|
|
135
147
|
const state = this
|
|
136
148
|
if (isFunction(func)) {
|
|
137
149
|
func(state)
|
|
138
|
-
return state.update(state, { skipOverwrite: true, options })
|
|
150
|
+
return state.update(state, { skipOverwrite: true, ...options })
|
|
139
151
|
}
|
|
140
152
|
}
|
|
141
153
|
|
|
@@ -258,6 +270,7 @@ const applyMethods = (element, state) => {
|
|
|
258
270
|
state.update = updateState
|
|
259
271
|
state.rootUpdate = rootUpdate
|
|
260
272
|
state.create = createState
|
|
273
|
+
state.add = add
|
|
261
274
|
state.remove = remove
|
|
262
275
|
state.apply = apply
|
|
263
276
|
state.parent = element.parent.state
|