@domql/state 2.3.144 → 2.3.148
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/createState.js +23 -20
- package/dist/cjs/createState.js +23 -19
- package/dist/cjs/inherit.js +7 -6
- package/inherit.js +7 -5
- package/package.json +2 -2
package/createState.js
CHANGED
|
@@ -8,7 +8,7 @@ import { updateState } from './updateState'
|
|
|
8
8
|
import { checkIfInherits, createInheritedState } from './inherit'
|
|
9
9
|
|
|
10
10
|
export const createState = function (element, parent, options) {
|
|
11
|
-
const skipApplyMethods = Boolean(options
|
|
11
|
+
const skipApplyMethods = Boolean(options && options.skipApplyMethods)
|
|
12
12
|
|
|
13
13
|
const objectizeState = checkForTypes(element)
|
|
14
14
|
if (objectizeState === false) return parent.state || {}
|
|
@@ -27,10 +27,9 @@ export const createState = function (element, parent, options) {
|
|
|
27
27
|
|
|
28
28
|
// NOTE: Only true when 'onlyResolveExtends' option is set to true
|
|
29
29
|
if (skipApplyMethods) {
|
|
30
|
-
if (element.parent && element.parent.state)
|
|
30
|
+
if (element.parent && element.parent.state) {
|
|
31
31
|
element.state.parent = element.parent.state
|
|
32
|
-
else
|
|
33
|
-
element.state.parent = element.state // self loop
|
|
32
|
+
} else { element.state.parent = element.state } // self loop
|
|
34
33
|
return element.state
|
|
35
34
|
}
|
|
36
35
|
|
|
@@ -79,22 +78,26 @@ const applyMethods = (element) => {
|
|
|
79
78
|
const state = element.state
|
|
80
79
|
const ref = element.__ref
|
|
81
80
|
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
81
|
+
const proto = {
|
|
82
|
+
clean: clean.bind(state),
|
|
83
|
+
parse: parse.bind(state),
|
|
84
|
+
destroy: destroy.bind(state),
|
|
85
|
+
update: updateState.bind(state),
|
|
86
|
+
rootUpdate: rootUpdate.bind(state),
|
|
87
|
+
parentUpdate: parentUpdate.bind(state),
|
|
88
|
+
create: createState.bind(state),
|
|
89
|
+
add: add.bind(state),
|
|
90
|
+
toggle: toggle.bind(state),
|
|
91
|
+
remove: remove.bind(state),
|
|
92
|
+
apply: apply.bind(state),
|
|
93
|
+
set: set.bind(state),
|
|
94
|
+
parent: element.parent.state,
|
|
95
|
+
__element: element,
|
|
96
|
+
__children: {},
|
|
97
|
+
__root: ref.__root ? ref.__root.state : state
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
Object.setPrototypeOf(state, proto)
|
|
98
101
|
|
|
99
102
|
if (state.parent) state.parent.__children[element.key] = state
|
|
100
103
|
}
|
package/dist/cjs/createState.js
CHANGED
|
@@ -28,7 +28,7 @@ var import_methods = require("./methods");
|
|
|
28
28
|
var import_updateState = require("./updateState");
|
|
29
29
|
var import_inherit = require("./inherit");
|
|
30
30
|
const createState = function(element, parent, options) {
|
|
31
|
-
const skipApplyMethods = Boolean(options
|
|
31
|
+
const skipApplyMethods = Boolean(options && options.skipApplyMethods);
|
|
32
32
|
const objectizeState = checkForTypes(element);
|
|
33
33
|
if (objectizeState === false)
|
|
34
34
|
return parent.state || {};
|
|
@@ -45,10 +45,11 @@ const createState = function(element, parent, options) {
|
|
|
45
45
|
if (dependentState)
|
|
46
46
|
element.state = dependentState;
|
|
47
47
|
if (skipApplyMethods) {
|
|
48
|
-
if (element.parent && element.parent.state)
|
|
48
|
+
if (element.parent && element.parent.state) {
|
|
49
49
|
element.state.parent = element.parent.state;
|
|
50
|
-
else
|
|
50
|
+
} else {
|
|
51
51
|
element.state.parent = element.state;
|
|
52
|
+
}
|
|
52
53
|
return element.state;
|
|
53
54
|
}
|
|
54
55
|
applyMethods(element);
|
|
@@ -87,22 +88,25 @@ const checkForTypes = (element) => {
|
|
|
87
88
|
const applyMethods = (element) => {
|
|
88
89
|
const state = element.state;
|
|
89
90
|
const ref = element.__ref;
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
91
|
+
const proto = {
|
|
92
|
+
clean: import_methods.clean.bind(state),
|
|
93
|
+
parse: import_methods.parse.bind(state),
|
|
94
|
+
destroy: import_methods.destroy.bind(state),
|
|
95
|
+
update: import_updateState.updateState.bind(state),
|
|
96
|
+
rootUpdate: import_methods.rootUpdate.bind(state),
|
|
97
|
+
parentUpdate: import_methods.parentUpdate.bind(state),
|
|
98
|
+
create: createState.bind(state),
|
|
99
|
+
add: import_methods.add.bind(state),
|
|
100
|
+
toggle: import_methods.toggle.bind(state),
|
|
101
|
+
remove: import_methods.remove.bind(state),
|
|
102
|
+
apply: import_methods.apply.bind(state),
|
|
103
|
+
set: import_methods.set.bind(state),
|
|
104
|
+
parent: element.parent.state,
|
|
105
|
+
__element: element,
|
|
106
|
+
__children: {},
|
|
107
|
+
__root: ref.__root ? ref.__root.state : state
|
|
108
|
+
};
|
|
109
|
+
Object.setPrototypeOf(state, proto);
|
|
106
110
|
if (state.parent)
|
|
107
111
|
state.parent.__children[element.key] = state;
|
|
108
112
|
};
|
package/dist/cjs/inherit.js
CHANGED
|
@@ -47,12 +47,13 @@ const getChildStateInKey = (stateKey, parentState, options = {}) => {
|
|
|
47
47
|
for (let i = 0; i < arrLength; i++) {
|
|
48
48
|
const childKey = arr[i];
|
|
49
49
|
const grandChildKey = arr[i + 1];
|
|
50
|
-
|
|
51
|
-
if (childInParent
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
50
|
+
let childInParent = parentState[childKey];
|
|
51
|
+
if (!childInParent)
|
|
52
|
+
childInParent = parentState[childKey] = {};
|
|
53
|
+
if (!childInParent[grandChildKey])
|
|
54
|
+
childInParent[grandChildKey] = {};
|
|
55
|
+
stateKey = grandChildKey;
|
|
56
|
+
parentState = childInParent;
|
|
56
57
|
}
|
|
57
58
|
if (options.returnParent)
|
|
58
59
|
return parentState;
|
package/inherit.js
CHANGED
|
@@ -20,11 +20,13 @@ export const getChildStateInKey = (stateKey, parentState, options = {}) => {
|
|
|
20
20
|
for (let i = 0; i < arrLength; i++) {
|
|
21
21
|
const childKey = arr[i]
|
|
22
22
|
const grandChildKey = arr[i + 1]
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
23
|
+
|
|
24
|
+
let childInParent = parentState[childKey]
|
|
25
|
+
if (!childInParent) childInParent = parentState[childKey] = {}
|
|
26
|
+
if (!childInParent[grandChildKey]) childInParent[grandChildKey] = {}
|
|
27
|
+
|
|
28
|
+
stateKey = grandChildKey
|
|
29
|
+
parentState = childInParent
|
|
28
30
|
}
|
|
29
31
|
if (options.returnParent) return parentState
|
|
30
32
|
return parentState[stateKey]
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@domql/state",
|
|
3
|
-
"version": "2.3.
|
|
3
|
+
"version": "2.3.148",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "dist/esm/index.js",
|
|
@@ -26,5 +26,5 @@
|
|
|
26
26
|
"@domql/report": "latest",
|
|
27
27
|
"@domql/utils": "latest"
|
|
28
28
|
},
|
|
29
|
-
"gitHead": "
|
|
29
|
+
"gitHead": "de4e989bbd734a02763ba4d4c9279f9fbb060b03"
|
|
30
30
|
}
|