@domql/state 2.5.178 → 2.5.181
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/create.js +12 -0
- package/dist/cjs/create.js +5 -0
- package/dist/cjs/ignore.js +6 -1
- package/dist/cjs/inherit.js +1 -1
- package/dist/cjs/methods.js +40 -0
- package/ignore.js +2 -1
- package/inherit.js +5 -0
- package/methods.js +44 -1
- package/package.json +4 -4
package/create.js
CHANGED
|
@@ -20,6 +20,11 @@ import {
|
|
|
20
20
|
quietUpdate,
|
|
21
21
|
quietReplace,
|
|
22
22
|
applyReplace,
|
|
23
|
+
setByPath,
|
|
24
|
+
setPathCollection,
|
|
25
|
+
removeByPath,
|
|
26
|
+
removePathCollection,
|
|
27
|
+
getByPath,
|
|
23
28
|
keys,
|
|
24
29
|
values
|
|
25
30
|
} from './methods'
|
|
@@ -130,6 +135,13 @@ const applyMethods = (element) => {
|
|
|
130
135
|
quietReplace: quietReplace.bind(state),
|
|
131
136
|
reset: reset.bind(state),
|
|
132
137
|
parent: element.parent.state || state,
|
|
138
|
+
|
|
139
|
+
setByPath: setByPath.bind(state),
|
|
140
|
+
setPathCollection: setPathCollection.bind(state),
|
|
141
|
+
removeByPath: removeByPath.bind(state),
|
|
142
|
+
removePathCollection: removePathCollection.bind(state),
|
|
143
|
+
getByPath: getByPath.bind(state),
|
|
144
|
+
|
|
133
145
|
keys: keys.bind(state),
|
|
134
146
|
values: values.bind(state),
|
|
135
147
|
__element: element,
|
package/dist/cjs/create.js
CHANGED
|
@@ -122,6 +122,11 @@ const applyMethods = (element) => {
|
|
|
122
122
|
quietReplace: import_methods.quietReplace.bind(state),
|
|
123
123
|
reset: import_methods.reset.bind(state),
|
|
124
124
|
parent: element.parent.state || state,
|
|
125
|
+
setByPath: import_methods.setByPath.bind(state),
|
|
126
|
+
setPathCollection: import_methods.setPathCollection.bind(state),
|
|
127
|
+
removeByPath: import_methods.removeByPath.bind(state),
|
|
128
|
+
removePathCollection: import_methods.removePathCollection.bind(state),
|
|
129
|
+
getByPath: import_methods.getByPath.bind(state),
|
|
125
130
|
keys: import_methods.keys.bind(state),
|
|
126
131
|
values: import_methods.values.bind(state),
|
|
127
132
|
__element: element,
|
package/dist/cjs/ignore.js
CHANGED
package/dist/cjs/inherit.js
CHANGED
|
@@ -113,7 +113,7 @@ const checkIfInherits = (element) => {
|
|
|
113
113
|
const isState = function(state) {
|
|
114
114
|
if (!(0, import_utils.isObjectLike)(state))
|
|
115
115
|
return false;
|
|
116
|
-
return state.update && state.parse && state.clean && state.create && state.parent && state.destroy && state.rootUpdate && state.parentUpdate && state.keys && state.values && state.toggle && state.replace && state.quietUpdate && state.quietReplace && state.add && state.apply && state.applyReplace && state.applyFunction && state.__element && state.__children;
|
|
116
|
+
return state.update && state.parse && state.clean && state.create && state.parent && state.destroy && state.rootUpdate && state.parentUpdate && state.keys && state.values && state.toggle && state.replace && state.quietUpdate && state.quietReplace && state.add && state.apply && state.applyReplace && state.setByPath && state.setPathCollection && state.removeByPath && state.removePathCollection && state.getByPath && state.applyFunction && state.__element && state.__children;
|
|
117
117
|
};
|
|
118
118
|
const createNestedObjectByKeyPath = (path, value) => {
|
|
119
119
|
if (!path) {
|
package/dist/cjs/methods.js
CHANGED
|
@@ -24,16 +24,21 @@ __export(methods_exports, {
|
|
|
24
24
|
applyReplace: () => applyReplace,
|
|
25
25
|
clean: () => clean,
|
|
26
26
|
destroy: () => destroy,
|
|
27
|
+
getByPath: () => getByPath,
|
|
27
28
|
keys: () => keys,
|
|
28
29
|
parentUpdate: () => parentUpdate,
|
|
29
30
|
parse: () => parse,
|
|
30
31
|
quietReplace: () => quietReplace,
|
|
31
32
|
quietUpdate: () => quietUpdate,
|
|
32
33
|
remove: () => remove,
|
|
34
|
+
removeByPath: () => removeByPath,
|
|
35
|
+
removePathCollection: () => removePathCollection,
|
|
33
36
|
replace: () => replace,
|
|
34
37
|
reset: () => reset,
|
|
35
38
|
rootUpdate: () => rootUpdate,
|
|
36
39
|
set: () => set,
|
|
40
|
+
setByPath: () => setByPath,
|
|
41
|
+
setPathCollection: () => setPathCollection,
|
|
37
42
|
toggle: () => toggle,
|
|
38
43
|
values: () => values
|
|
39
44
|
});
|
|
@@ -144,6 +149,41 @@ const set = function(val, options = {}) {
|
|
|
144
149
|
const value = (0, import_utils.deepClone)(val);
|
|
145
150
|
return state.clean({ preventStateUpdate: true, ...options }).update(value, { replace: true, ...options });
|
|
146
151
|
};
|
|
152
|
+
const setByPath = function(path, val, options = {}) {
|
|
153
|
+
const state = this;
|
|
154
|
+
const value = (0, import_utils.deepClone)(val);
|
|
155
|
+
(0, import_utils.setInObjectByPath)(state, path, val);
|
|
156
|
+
const update = (0, import_utils.createNestedObject)(path, value);
|
|
157
|
+
if (options.preventUpdate)
|
|
158
|
+
return update;
|
|
159
|
+
return state.update(update, options);
|
|
160
|
+
};
|
|
161
|
+
const setPathCollection = function(changes, options = {}) {
|
|
162
|
+
const state = this;
|
|
163
|
+
const update = changes.reduce((acc, change) => {
|
|
164
|
+
const result = setByPath(...change, { preventUpdate: true });
|
|
165
|
+
return (0, import_utils.overwriteDeep)(acc, result);
|
|
166
|
+
}, {});
|
|
167
|
+
return state.update(update, options);
|
|
168
|
+
};
|
|
169
|
+
const removeByPath = function(path, options = {}) {
|
|
170
|
+
const state = this;
|
|
171
|
+
(0, import_utils.removeNestedKeyByPath)(state, path);
|
|
172
|
+
if (options.preventUpdate)
|
|
173
|
+
return path;
|
|
174
|
+
return state.update({}, options);
|
|
175
|
+
};
|
|
176
|
+
const removePathCollection = function(changes, options = {}) {
|
|
177
|
+
const state = this;
|
|
178
|
+
changes.forEach((item) => {
|
|
179
|
+
removeByPath(item, { preventUpdate: true });
|
|
180
|
+
});
|
|
181
|
+
return state.update({}, options);
|
|
182
|
+
};
|
|
183
|
+
const getByPath = function(path, options = {}) {
|
|
184
|
+
const state = this;
|
|
185
|
+
return (0, import_utils.getInObjectByPath)(state, path);
|
|
186
|
+
};
|
|
147
187
|
const reset = function(options = {}) {
|
|
148
188
|
const state = this;
|
|
149
189
|
const value = (0, import_utils.deepClone)(state.parse());
|
package/ignore.js
CHANGED
|
@@ -3,5 +3,6 @@
|
|
|
3
3
|
export const IGNORE_STATE_PARAMS = [
|
|
4
4
|
'update', 'parse', 'clean', 'create', 'destroy', 'add', 'toggle', 'remove', 'apply', 'set', 'reset',
|
|
5
5
|
'replace', 'quietReplace', 'quietUpdate', 'applyReplace', 'applyFunction', 'keys', 'values', 'ref',
|
|
6
|
-
'rootUpdate', 'parentUpdate', 'parent', '__element', '__depends', '__ref', '__children', 'root'
|
|
6
|
+
'rootUpdate', 'parentUpdate', 'parent', '__element', '__depends', '__ref', '__children', 'root',
|
|
7
|
+
'setByPath', 'setPathCollection', 'removeByPath', 'removePathCollection', 'getByPath'
|
|
7
8
|
]
|
package/inherit.js
CHANGED
|
@@ -105,6 +105,11 @@ export const isState = function (state) {
|
|
|
105
105
|
state.add &&
|
|
106
106
|
state.apply &&
|
|
107
107
|
state.applyReplace &&
|
|
108
|
+
state.setByPath &&
|
|
109
|
+
state.setPathCollection &&
|
|
110
|
+
state.removeByPath &&
|
|
111
|
+
state.removePathCollection &&
|
|
112
|
+
state.getByPath &&
|
|
108
113
|
state.applyFunction &&
|
|
109
114
|
state.__element &&
|
|
110
115
|
state.__children
|
package/methods.js
CHANGED
|
@@ -7,7 +7,12 @@ import {
|
|
|
7
7
|
isObject,
|
|
8
8
|
isString,
|
|
9
9
|
removeFromArray,
|
|
10
|
-
removeFromObject
|
|
10
|
+
removeFromObject,
|
|
11
|
+
overwriteDeep,
|
|
12
|
+
createNestedObject,
|
|
13
|
+
getInObjectByPath,
|
|
14
|
+
removeNestedKeyByPath,
|
|
15
|
+
setInObjectByPath
|
|
11
16
|
} from '@domql/utils'
|
|
12
17
|
|
|
13
18
|
import { IGNORE_STATE_PARAMS } from './ignore'
|
|
@@ -123,6 +128,44 @@ export const set = function (val, options = {}) {
|
|
|
123
128
|
.update(value, { replace: true, ...options })
|
|
124
129
|
}
|
|
125
130
|
|
|
131
|
+
export const setByPath = function (path, val, options = {}) {
|
|
132
|
+
const state = this
|
|
133
|
+
const value = deepClone(val)
|
|
134
|
+
setInObjectByPath(state, path, val)
|
|
135
|
+
const update = createNestedObject(path, value)
|
|
136
|
+
if (options.preventUpdate) return update
|
|
137
|
+
return state.update(update, options)
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
export const setPathCollection = function (changes, options = {}) {
|
|
141
|
+
const state = this
|
|
142
|
+
const update = changes.reduce((acc, change) => {
|
|
143
|
+
const result = setByPath(...change, { preventUpdate: true })
|
|
144
|
+
return overwriteDeep(acc, result)
|
|
145
|
+
}, {})
|
|
146
|
+
return state.update(update, options)
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
export const removeByPath = function (path, options = {}) {
|
|
150
|
+
const state = this
|
|
151
|
+
removeNestedKeyByPath(state, path)
|
|
152
|
+
if (options.preventUpdate) return path
|
|
153
|
+
return state.update({}, options)
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
export const removePathCollection = function (changes, options = {}) {
|
|
157
|
+
const state = this
|
|
158
|
+
changes.forEach(item => {
|
|
159
|
+
removeByPath(item, { preventUpdate: true })
|
|
160
|
+
})
|
|
161
|
+
return state.update({}, options)
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
export const getByPath = function (path, options = {}) {
|
|
165
|
+
const state = this
|
|
166
|
+
return getInObjectByPath(state, path)
|
|
167
|
+
}
|
|
168
|
+
|
|
126
169
|
export const reset = function (options = {}) {
|
|
127
170
|
const state = this
|
|
128
171
|
const value = deepClone(state.parse())
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@domql/state",
|
|
3
|
-
"version": "2.5.
|
|
3
|
+
"version": "2.5.181",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "dist/esm/index.js",
|
|
@@ -27,9 +27,9 @@
|
|
|
27
27
|
"prepublish": "rimraf -I dist && npm run build && npm run copy:package:cjs"
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@domql/event": "^2.5.
|
|
30
|
+
"@domql/event": "^2.5.179",
|
|
31
31
|
"@domql/report": "^2.5.162",
|
|
32
|
-
"@domql/utils": "^2.5.
|
|
32
|
+
"@domql/utils": "^2.5.179"
|
|
33
33
|
},
|
|
34
|
-
"gitHead": "
|
|
34
|
+
"gitHead": "4e5c3841725d9b2ffaeacc0e32bbff5c913b80b4"
|
|
35
35
|
}
|