@domql/state 2.5.179 → 2.5.182
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 +18 -6
- package/dist/cjs/create.js +11 -6
- package/dist/cjs/ignore.js +6 -1
- package/dist/cjs/inherit.js +1 -1
- package/dist/cjs/methods.js +1 -1
- package/ignore.js +2 -1
- package/inherit.js +5 -0
- package/methods.js +1 -1
- package/package.json +3 -3
package/create.js
CHANGED
|
@@ -20,19 +20,24 @@ 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'
|
|
26
31
|
import { updateState } from './updateState'
|
|
27
32
|
import { checkIfInherits, createInheritedState } from './inherit'
|
|
28
33
|
|
|
29
|
-
export const createState = function (element, parent, options) {
|
|
30
|
-
element.state = applyInitialState(element, parent, options)
|
|
34
|
+
export const createState = async function (element, parent, options) {
|
|
35
|
+
element.state = await applyInitialState(element, parent, options)
|
|
31
36
|
return element.state
|
|
32
37
|
}
|
|
33
38
|
|
|
34
|
-
export const applyInitialState = function (element, parent, options) {
|
|
35
|
-
const objectizeState = checkForTypes(element)
|
|
39
|
+
export const applyInitialState = async function (element, parent, options) {
|
|
40
|
+
const objectizeState = await checkForTypes(element)
|
|
36
41
|
if (objectizeState === false) return parent.state || {}
|
|
37
42
|
else element.state = objectizeState
|
|
38
43
|
|
|
@@ -75,12 +80,12 @@ const applyDependentState = (element, state) => {
|
|
|
75
80
|
return dependentState
|
|
76
81
|
}
|
|
77
82
|
|
|
78
|
-
const checkForTypes = (element) => {
|
|
83
|
+
const checkForTypes = async (element) => {
|
|
79
84
|
const { state: orig, props, __ref: ref } = element
|
|
80
85
|
const state = props?.state || orig
|
|
81
86
|
if (isFunction(state)) {
|
|
82
87
|
ref.__state = state
|
|
83
|
-
return exec(state, element)
|
|
88
|
+
return await exec(state, element)
|
|
84
89
|
} else if (is(state)('string', 'number')) {
|
|
85
90
|
ref.__state = state
|
|
86
91
|
return { value: state }
|
|
@@ -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
|
@@ -28,12 +28,12 @@ var import_ignore = require("./ignore");
|
|
|
28
28
|
var import_methods = require("./methods");
|
|
29
29
|
var import_updateState = require("./updateState");
|
|
30
30
|
var import_inherit = require("./inherit");
|
|
31
|
-
const createState = function(element, parent, options) {
|
|
32
|
-
element.state = applyInitialState(element, parent, options);
|
|
31
|
+
const createState = async function(element, parent, options) {
|
|
32
|
+
element.state = await applyInitialState(element, parent, options);
|
|
33
33
|
return element.state;
|
|
34
34
|
};
|
|
35
|
-
const applyInitialState = function(element, parent, options) {
|
|
36
|
-
const objectizeState = checkForTypes(element);
|
|
35
|
+
const applyInitialState = async function(element, parent, options) {
|
|
36
|
+
const objectizeState = await checkForTypes(element);
|
|
37
37
|
if (objectizeState === false)
|
|
38
38
|
return parent.state || {};
|
|
39
39
|
else
|
|
@@ -67,12 +67,12 @@ const applyDependentState = (element, state) => {
|
|
|
67
67
|
}
|
|
68
68
|
return dependentState;
|
|
69
69
|
};
|
|
70
|
-
const checkForTypes = (element) => {
|
|
70
|
+
const checkForTypes = async (element) => {
|
|
71
71
|
const { state: orig, props, __ref: ref } = element;
|
|
72
72
|
const state = (props == null ? void 0 : props.state) || orig;
|
|
73
73
|
if ((0, import_utils.isFunction)(state)) {
|
|
74
74
|
ref.__state = state;
|
|
75
|
-
return (0, import_utils.exec)(state, element);
|
|
75
|
+
return await (0, import_utils.exec)(state, element);
|
|
76
76
|
} else if ((0, import_utils.is)(state)("string", "number")) {
|
|
77
77
|
ref.__state = state;
|
|
78
78
|
return { value: state };
|
|
@@ -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
|
@@ -161,7 +161,7 @@ const setByPath = function(path, val, options = {}) {
|
|
|
161
161
|
const setPathCollection = function(changes, options = {}) {
|
|
162
162
|
const state = this;
|
|
163
163
|
const update = changes.reduce((acc, change) => {
|
|
164
|
-
const result = setByPath(...change, { preventUpdate: true });
|
|
164
|
+
const result = setByPath(...change.slice(1), { preventUpdate: true });
|
|
165
165
|
return (0, import_utils.overwriteDeep)(acc, result);
|
|
166
166
|
}, {});
|
|
167
167
|
return state.update(update, options);
|
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
|
@@ -140,7 +140,7 @@ export const setByPath = function (path, val, options = {}) {
|
|
|
140
140
|
export const setPathCollection = function (changes, options = {}) {
|
|
141
141
|
const state = this
|
|
142
142
|
const update = changes.reduce((acc, change) => {
|
|
143
|
-
const result = setByPath(...change, { preventUpdate: true })
|
|
143
|
+
const result = setByPath(...change.slice(1), { preventUpdate: true })
|
|
144
144
|
return overwriteDeep(acc, result)
|
|
145
145
|
}, {})
|
|
146
146
|
return state.update(update, options)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@domql/state",
|
|
3
|
-
"version": "2.5.
|
|
3
|
+
"version": "2.5.182",
|
|
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.182",
|
|
31
31
|
"@domql/report": "^2.5.162",
|
|
32
32
|
"@domql/utils": "^2.5.179"
|
|
33
33
|
},
|
|
34
|
-
"gitHead": "
|
|
34
|
+
"gitHead": "0071c581cbefc87854f08d3b658580055911ed24"
|
|
35
35
|
}
|