@domql/state 2.5.9 → 2.5.16
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 +1 -1
- package/dist/cjs/updateState.js +2 -1
- package/inherit.js +6 -6
- package/methods.js +1 -1
- package/package.json +2 -2
- package/updateState.js +2 -1
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
|
@@ -93,7 +93,7 @@ const rootUpdate = function(obj, options = {}) {
|
|
|
93
93
|
if (!state)
|
|
94
94
|
return;
|
|
95
95
|
const rootState = state.__element.__ref.__root.state;
|
|
96
|
-
return rootState.update(obj, { isHoisted: false, options });
|
|
96
|
+
return rootState.update(obj, { isHoisted: false, ...options });
|
|
97
97
|
};
|
|
98
98
|
const add = function(value, options = {}) {
|
|
99
99
|
const state = this;
|
package/dist/cjs/updateState.js
CHANGED
|
@@ -78,6 +78,7 @@ const hoistStateUpdate = (state, obj, options) => {
|
|
|
78
78
|
const element = state.__element;
|
|
79
79
|
const { parent, __ref: ref } = element;
|
|
80
80
|
const stateKey = ref.__state;
|
|
81
|
+
const stateType = ref.__stateType;
|
|
81
82
|
if (!stateKey)
|
|
82
83
|
return;
|
|
83
84
|
const asksForInherit = (0, import_inherit.checkIfInherits)(element);
|
|
@@ -85,7 +86,7 @@ const hoistStateUpdate = (state, obj, options) => {
|
|
|
85
86
|
const shouldPropagateState = asksForInherit && inheritedState && !options.stopStatePropagation;
|
|
86
87
|
if (!shouldPropagateState)
|
|
87
88
|
return;
|
|
88
|
-
const isStringState =
|
|
89
|
+
const isStringState = stateType === "string" || stateType === "number" || stateType === "boolean";
|
|
89
90
|
const value = isStringState ? state.value : state.parse();
|
|
90
91
|
const passedValue = isStringState ? state.value : obj;
|
|
91
92
|
const findGrandParentState = (0, import_inherit.getParentStateInKey)(stateKey, parent.state);
|
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
|
@@ -72,7 +72,7 @@ export const rootUpdate = function (obj, options = {}) {
|
|
|
72
72
|
const state = this
|
|
73
73
|
if (!state) return
|
|
74
74
|
const rootState = (state.__element.__ref.__root).state
|
|
75
|
-
return rootState.update(obj, { isHoisted: false, options })
|
|
75
|
+
return rootState.update(obj, { isHoisted: false, ...options })
|
|
76
76
|
}
|
|
77
77
|
|
|
78
78
|
export const add = function (value, options = {}) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@domql/state",
|
|
3
|
-
"version": "2.5.
|
|
3
|
+
"version": "2.5.16",
|
|
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": "2987c1965a4cab0258feb592d273d519260f5461"
|
|
35
35
|
}
|
package/updateState.js
CHANGED
|
@@ -66,6 +66,7 @@ const hoistStateUpdate = (state, obj, options) => {
|
|
|
66
66
|
const element = state.__element
|
|
67
67
|
const { parent, __ref: ref } = element
|
|
68
68
|
const stateKey = ref.__state
|
|
69
|
+
const stateType = ref.__stateType
|
|
69
70
|
if (!stateKey) return
|
|
70
71
|
|
|
71
72
|
const asksForInherit = checkIfInherits(element)
|
|
@@ -73,7 +74,7 @@ const hoistStateUpdate = (state, obj, options) => {
|
|
|
73
74
|
const shouldPropagateState = asksForInherit && inheritedState && !options.stopStatePropagation
|
|
74
75
|
if (!shouldPropagateState) return
|
|
75
76
|
|
|
76
|
-
const isStringState = (
|
|
77
|
+
const isStringState = (stateType === 'string' || stateType === 'number' || stateType === 'boolean')
|
|
77
78
|
const value = isStringState ? state.value : state.parse()
|
|
78
79
|
const passedValue = isStringState ? state.value : obj
|
|
79
80
|
|