@domql/state 2.5.15 → 2.5.18
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 +3 -3
- package/dist/cjs/create.js +1 -1
- package/dist/cjs/inherit.js +6 -6
- package/dist/cjs/methods.js +13 -1
- package/dist/cjs/updateState.js +3 -4
- package/inherit.js +6 -6
- package/methods.js +10 -1
- package/package.json +2 -2
- package/updateState.js +3 -4
package/create.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
3
|
import { triggerEventOn } from '@domql/event'
|
|
4
|
-
import { deepClone, exec, is, isArray, isFunction, isObject } from '@domql/utils'
|
|
4
|
+
import { deepClone, exec, is, isArray, isFunction, isObject, isUndefined } from '@domql/utils'
|
|
5
5
|
import { IGNORE_STATE_PARAMS } from './ignore'
|
|
6
6
|
import { add, apply, clean, destroy, parentUpdate, parse, remove, rootUpdate, set, toggle } from './methods'
|
|
7
7
|
import { updateState } from './updateState'
|
|
@@ -22,7 +22,7 @@ export const applyInitialState = function (element, parent, options) {
|
|
|
22
22
|
|
|
23
23
|
if (checkIfInherits(element)) {
|
|
24
24
|
const inheritedState = createInheritedState(element, parent)
|
|
25
|
-
element.state = inheritedState
|
|
25
|
+
element.state = isUndefined(inheritedState) ? {} : inheritedState
|
|
26
26
|
}
|
|
27
27
|
|
|
28
28
|
const dependentState = applyDependentState(element, element.state)
|
|
@@ -62,7 +62,7 @@ const checkForTypes = (element) => {
|
|
|
62
62
|
} else if (state) {
|
|
63
63
|
ref.__hasRootState = true
|
|
64
64
|
return state
|
|
65
|
-
} else
|
|
65
|
+
} else {
|
|
66
66
|
return false
|
|
67
67
|
}
|
|
68
68
|
}
|
package/dist/cjs/create.js
CHANGED
|
@@ -43,7 +43,7 @@ const applyInitialState = function(element, parent, options) {
|
|
|
43
43
|
return element.state;
|
|
44
44
|
if ((0, import_inherit.checkIfInherits)(element)) {
|
|
45
45
|
const inheritedState = (0, import_inherit.createInheritedState)(element, parent);
|
|
46
|
-
element.state = inheritedState
|
|
46
|
+
element.state = (0, import_utils.isUndefined)(inheritedState) ? {} : inheritedState;
|
|
47
47
|
}
|
|
48
48
|
const dependentState = applyDependentState(element, element.state);
|
|
49
49
|
if (dependentState)
|
package/dist/cjs/inherit.js
CHANGED
|
@@ -79,12 +79,12 @@ const findInheritedState = (element, parent, options = {}) => {
|
|
|
79
79
|
const createInheritedState = (element, parent) => {
|
|
80
80
|
const ref = element.__ref;
|
|
81
81
|
const inheritedState = findInheritedState(element, parent);
|
|
82
|
-
if (
|
|
82
|
+
if ((0, import_utils.isUndefined)(inheritedState))
|
|
83
83
|
return element.state;
|
|
84
84
|
if ((0, import_utils.is)(inheritedState)("object", "array")) {
|
|
85
85
|
return (0, import_utils.deepClone)(inheritedState, import_ignore.IGNORE_STATE_PARAMS);
|
|
86
|
-
} else if ((0, import_utils.is)(inheritedState)("string", "number")) {
|
|
87
|
-
ref.__stateType =
|
|
86
|
+
} else if ((0, import_utils.is)(inheritedState)("string", "number", "boolean")) {
|
|
87
|
+
ref.__stateType = typeof inheritedState;
|
|
88
88
|
return { value: inheritedState };
|
|
89
89
|
}
|
|
90
90
|
console.warn(ref.__state, "is not present. Replacing with", {});
|
|
@@ -92,9 +92,9 @@ const createInheritedState = (element, parent) => {
|
|
|
92
92
|
const checkIfInherits = (element) => {
|
|
93
93
|
const ref = element.__ref;
|
|
94
94
|
const stateKey = ref.__state;
|
|
95
|
-
if (
|
|
96
|
-
return
|
|
97
|
-
return
|
|
95
|
+
if (stateKey && (0, import_utils.is)(stateKey)("number", "string", "boolean"))
|
|
96
|
+
return true;
|
|
97
|
+
return false;
|
|
98
98
|
};
|
|
99
99
|
const isState = function(state) {
|
|
100
100
|
if (!(0, import_utils.isObjectLike)(state))
|
package/dist/cjs/methods.js
CHANGED
|
@@ -75,7 +75,19 @@ const destroy = function(options = {}) {
|
|
|
75
75
|
for (const key in state.__children) {
|
|
76
76
|
const child = state.__children[key];
|
|
77
77
|
if (child.state) {
|
|
78
|
-
child.
|
|
78
|
+
if ((0, import_utils.isArray)(child.state)) {
|
|
79
|
+
Object.defineProperty(child.state, "parent", {
|
|
80
|
+
value: state.parent,
|
|
81
|
+
enumerable: false,
|
|
82
|
+
// Set this to true if you want the method to appear in for...in loops
|
|
83
|
+
configurable: true,
|
|
84
|
+
// Set this to true if you want to allow redefining/removing the property later
|
|
85
|
+
writable: true
|
|
86
|
+
// Set this to true if you want to allow changing the function later
|
|
87
|
+
});
|
|
88
|
+
} else {
|
|
89
|
+
Object.setPrototypeOf(child, { parent: state.parent });
|
|
90
|
+
}
|
|
79
91
|
}
|
|
80
92
|
}
|
|
81
93
|
}
|
package/dist/cjs/updateState.js
CHANGED
|
@@ -31,8 +31,7 @@ const STATE_UPDATE_OPTIONS = {
|
|
|
31
31
|
preventHoistElementUpdate: false,
|
|
32
32
|
updateByState: true,
|
|
33
33
|
isHoisted: true,
|
|
34
|
-
execStateFunction: true
|
|
35
|
-
stateFunctionOverwrite: true
|
|
34
|
+
execStateFunction: true
|
|
36
35
|
};
|
|
37
36
|
const updateState = function(obj, options = STATE_UPDATE_OPTIONS) {
|
|
38
37
|
const state = this;
|
|
@@ -78,6 +77,7 @@ const hoistStateUpdate = (state, obj, options) => {
|
|
|
78
77
|
const element = state.__element;
|
|
79
78
|
const { parent, __ref: ref } = element;
|
|
80
79
|
const stateKey = ref.__state;
|
|
80
|
+
const stateType = ref.__stateType;
|
|
81
81
|
if (!stateKey)
|
|
82
82
|
return;
|
|
83
83
|
const asksForInherit = (0, import_inherit.checkIfInherits)(element);
|
|
@@ -85,7 +85,7 @@ const hoistStateUpdate = (state, obj, options) => {
|
|
|
85
85
|
const shouldPropagateState = asksForInherit && inheritedState && !options.stopStatePropagation;
|
|
86
86
|
if (!shouldPropagateState)
|
|
87
87
|
return;
|
|
88
|
-
const isStringState =
|
|
88
|
+
const isStringState = stateType === "string" || stateType === "number" || stateType === "boolean";
|
|
89
89
|
const value = isStringState ? state.value : state.parse();
|
|
90
90
|
const passedValue = isStringState ? state.value : obj;
|
|
91
91
|
const findGrandParentState = (0, import_inherit.getParentStateInKey)(stateKey, parent.state);
|
|
@@ -95,7 +95,6 @@ const hoistStateUpdate = (state, obj, options) => {
|
|
|
95
95
|
targetParent[stateKey] = value;
|
|
96
96
|
targetParent.update(changesValue, {
|
|
97
97
|
execStateFunction: false,
|
|
98
|
-
stateFunctionOverwrite: false,
|
|
99
98
|
isHoisted: true,
|
|
100
99
|
...options,
|
|
101
100
|
preventUpdate: options.preventHoistElementUpdate,
|
package/inherit.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
-
import { deepClone, is,
|
|
3
|
+
import { deepClone, is, isObjectLike, isUndefined } from '@domql/utils'
|
|
4
4
|
import { IGNORE_STATE_PARAMS } from './ignore'
|
|
5
5
|
|
|
6
6
|
export const getParentStateInKey = (stateKey, parentState) => {
|
|
@@ -53,12 +53,12 @@ export const findInheritedState = (element, parent, options = {}) => {
|
|
|
53
53
|
export const createInheritedState = (element, parent) => {
|
|
54
54
|
const ref = element.__ref
|
|
55
55
|
const inheritedState = findInheritedState(element, parent)
|
|
56
|
-
if (
|
|
56
|
+
if (isUndefined(inheritedState)) return element.state
|
|
57
57
|
|
|
58
58
|
if (is(inheritedState)('object', 'array')) {
|
|
59
59
|
return deepClone(inheritedState, IGNORE_STATE_PARAMS)
|
|
60
|
-
} else if (is(inheritedState)('string', 'number')) {
|
|
61
|
-
ref.__stateType =
|
|
60
|
+
} else if (is(inheritedState)('string', 'number', 'boolean')) {
|
|
61
|
+
ref.__stateType = typeof inheritedState
|
|
62
62
|
return { value: inheritedState }
|
|
63
63
|
}
|
|
64
64
|
|
|
@@ -69,8 +69,8 @@ export const checkIfInherits = (element) => {
|
|
|
69
69
|
const ref = element.__ref
|
|
70
70
|
const stateKey = ref.__state
|
|
71
71
|
|
|
72
|
-
if (
|
|
73
|
-
return
|
|
72
|
+
if (stateKey && is(stateKey)('number', 'string', 'boolean')) return true
|
|
73
|
+
return false
|
|
74
74
|
}
|
|
75
75
|
|
|
76
76
|
export const isState = function (state) {
|
package/methods.js
CHANGED
|
@@ -53,7 +53,16 @@ export const destroy = function (options = {}) {
|
|
|
53
53
|
for (const key in state.__children) {
|
|
54
54
|
const child = state.__children[key]
|
|
55
55
|
if (child.state) {
|
|
56
|
-
child.
|
|
56
|
+
if (isArray(child.state)) {
|
|
57
|
+
Object.defineProperty(child.state, 'parent', {
|
|
58
|
+
value: state.parent,
|
|
59
|
+
enumerable: false, // Set this to true if you want the method to appear in for...in loops
|
|
60
|
+
configurable: true, // Set this to true if you want to allow redefining/removing the property later
|
|
61
|
+
writable: true // Set this to true if you want to allow changing the function later
|
|
62
|
+
})
|
|
63
|
+
} else {
|
|
64
|
+
Object.setPrototypeOf(child, { parent: state.parent })
|
|
65
|
+
}
|
|
57
66
|
}
|
|
58
67
|
}
|
|
59
68
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@domql/state",
|
|
3
|
-
"version": "2.5.
|
|
3
|
+
"version": "2.5.18",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "dist/esm/index.js",
|
|
@@ -31,5 +31,5 @@
|
|
|
31
31
|
"@domql/report": "latest",
|
|
32
32
|
"@domql/utils": "latest"
|
|
33
33
|
},
|
|
34
|
-
"gitHead": "
|
|
34
|
+
"gitHead": "4aeead0b153d4cd5430694ecf45a5d3052f9f9f5"
|
|
35
35
|
}
|
package/updateState.js
CHANGED
|
@@ -11,8 +11,7 @@ const STATE_UPDATE_OPTIONS = {
|
|
|
11
11
|
preventHoistElementUpdate: false,
|
|
12
12
|
updateByState: true,
|
|
13
13
|
isHoisted: true,
|
|
14
|
-
execStateFunction: true
|
|
15
|
-
stateFunctionOverwrite: true
|
|
14
|
+
execStateFunction: true
|
|
16
15
|
}
|
|
17
16
|
|
|
18
17
|
export const updateState = function (obj, options = STATE_UPDATE_OPTIONS) {
|
|
@@ -66,6 +65,7 @@ const hoistStateUpdate = (state, obj, options) => {
|
|
|
66
65
|
const element = state.__element
|
|
67
66
|
const { parent, __ref: ref } = element
|
|
68
67
|
const stateKey = ref.__state
|
|
68
|
+
const stateType = ref.__stateType
|
|
69
69
|
if (!stateKey) return
|
|
70
70
|
|
|
71
71
|
const asksForInherit = checkIfInherits(element)
|
|
@@ -73,7 +73,7 @@ const hoistStateUpdate = (state, obj, options) => {
|
|
|
73
73
|
const shouldPropagateState = asksForInherit && inheritedState && !options.stopStatePropagation
|
|
74
74
|
if (!shouldPropagateState) return
|
|
75
75
|
|
|
76
|
-
const isStringState = (
|
|
76
|
+
const isStringState = (stateType === 'string' || stateType === 'number' || stateType === 'boolean')
|
|
77
77
|
const value = isStringState ? state.value : state.parse()
|
|
78
78
|
const passedValue = isStringState ? state.value : obj
|
|
79
79
|
|
|
@@ -83,7 +83,6 @@ const hoistStateUpdate = (state, obj, options) => {
|
|
|
83
83
|
if (options.replace) targetParent[stateKey] = value
|
|
84
84
|
targetParent.update(changesValue, {
|
|
85
85
|
execStateFunction: false,
|
|
86
|
-
stateFunctionOverwrite: false,
|
|
87
86
|
isHoisted: true,
|
|
88
87
|
...options,
|
|
89
88
|
preventUpdate: options.preventHoistElementUpdate,
|