@domql/state 2.3.120 → 2.3.122
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 +37 -37
- package/dist/cjs/createState.js +58 -54
- package/dist/cjs/index.js +1 -1
- package/dist/cjs/{utils.js → inherit.js} +31 -26
- package/dist/cjs/updateState.js +27 -24
- package/index.js +1 -1
- package/{utils.js → inherit.js} +16 -12
- package/package.json +2 -2
- package/updateState.js +27 -26
package/createState.js
CHANGED
|
@@ -5,72 +5,72 @@ import { deepClone, exec, is, isFunction, isObject } from '@domql/utils'
|
|
|
5
5
|
import { IGNORE_STATE_PARAMS } from './ignore'
|
|
6
6
|
import { add, apply, clean, destroy, parse, remove, rootUpdate, toggle } from './methods'
|
|
7
7
|
import { updateState } from './updateState'
|
|
8
|
-
import { checkIfInherits, createInheritedState } from './
|
|
8
|
+
import { checkIfInherits, createInheritedState } from './inherit'
|
|
9
9
|
|
|
10
10
|
export const createState = function (element, parent, opts) {
|
|
11
11
|
const skip = (opts && opts.skip) ? opts.skip : false
|
|
12
|
-
let { state, __ref: __elementRef } = element
|
|
13
12
|
|
|
14
|
-
|
|
13
|
+
const objectizeState = checkForTypes(element)
|
|
14
|
+
if (objectizeState === false) return parent.state || {}
|
|
15
|
+
else element.state = objectizeState
|
|
15
16
|
|
|
16
|
-
triggerEventOn('stateInit', element)
|
|
17
|
+
const whatInitReturns = triggerEventOn('stateInit', element)
|
|
18
|
+
if (whatInitReturns === false) return element.state
|
|
17
19
|
|
|
18
20
|
if (checkIfInherits(element)) {
|
|
19
|
-
|
|
21
|
+
element.state = createInheritedState(element, parent) || {}
|
|
20
22
|
}
|
|
21
23
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
return {}
|
|
25
|
-
} else {
|
|
26
|
-
__elementRef.__hasRootState = true
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
// reference other state
|
|
30
|
-
// TODO: check why __ref is assigned with element
|
|
31
|
-
// /docs/intro
|
|
32
|
-
const { __ref } = state
|
|
33
|
-
if (__ref) {
|
|
34
|
-
state = deepClone(__ref, IGNORE_STATE_PARAMS)
|
|
35
|
-
if (isObject(__ref.__depends)) {
|
|
36
|
-
__ref.__depends[element.key] = state
|
|
37
|
-
} else __ref.__depends = { [element.key]: state }
|
|
38
|
-
} else {
|
|
39
|
-
state = deepClone(state, IGNORE_STATE_PARAMS)
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
element.state = state
|
|
24
|
+
const dependentState = applyDependentState(element, state)
|
|
25
|
+
if (dependentState) element.state = dependentState
|
|
43
26
|
|
|
44
27
|
// NOTE: Only true when 'onlyResolveExtends' option is set to true
|
|
45
|
-
if (skip) return state
|
|
28
|
+
if (skip) return element.state
|
|
46
29
|
|
|
47
|
-
applyMethods(element
|
|
30
|
+
applyMethods(element)
|
|
48
31
|
|
|
49
32
|
// trigger `on.stateCreated`
|
|
50
33
|
triggerEventOn('stateCreated', element)
|
|
51
34
|
|
|
52
|
-
return state
|
|
35
|
+
return element.state
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const applyDependentState = (element, state) => {
|
|
39
|
+
const { __ref: ref } = state
|
|
40
|
+
if (!ref) return
|
|
41
|
+
const dependentState = deepClone(ref, IGNORE_STATE_PARAMS)
|
|
42
|
+
const newDepends = { [element.key]: dependentState }
|
|
43
|
+
ref.__depends = isObject(ref.__depends)
|
|
44
|
+
? { ...ref.__depends, ...newDepends }
|
|
45
|
+
: newDepends
|
|
46
|
+
|
|
47
|
+
return dependentState
|
|
53
48
|
}
|
|
54
49
|
|
|
55
50
|
const checkForTypes = (element) => {
|
|
56
|
-
const { state, __ref:
|
|
51
|
+
const { state, __ref: ref } = element
|
|
57
52
|
if (isFunction(state)) {
|
|
58
|
-
|
|
53
|
+
ref.__state = state
|
|
59
54
|
return exec(state, element)
|
|
60
55
|
}
|
|
61
56
|
if (is(state)('string', 'number')) {
|
|
62
|
-
|
|
57
|
+
ref.__state = state
|
|
63
58
|
return {}
|
|
64
59
|
}
|
|
65
60
|
if (state === true) {
|
|
66
|
-
|
|
61
|
+
ref.__state = element.key
|
|
67
62
|
return {}
|
|
68
63
|
}
|
|
69
|
-
|
|
64
|
+
if (state) {
|
|
65
|
+
ref.__hasRootState = true
|
|
66
|
+
return state
|
|
67
|
+
}
|
|
68
|
+
return false
|
|
70
69
|
}
|
|
71
70
|
|
|
72
|
-
const applyMethods = (element
|
|
73
|
-
const
|
|
71
|
+
const applyMethods = (element) => {
|
|
72
|
+
const state = element.state
|
|
73
|
+
const ref = element.__ref
|
|
74
74
|
|
|
75
75
|
state.clean = clean
|
|
76
76
|
state.parse = parse
|
|
@@ -85,7 +85,7 @@ const applyMethods = (element, state) => {
|
|
|
85
85
|
state.parent = element.parent.state
|
|
86
86
|
state.__element = element
|
|
87
87
|
state.__children = {}
|
|
88
|
-
state.__root =
|
|
88
|
+
state.__root = ref.__root ? ref.__root.state : state
|
|
89
89
|
|
|
90
90
|
if (state.parent) state.parent.__children[element.key] = state
|
|
91
91
|
}
|
package/dist/cjs/createState.js
CHANGED
|
@@ -26,71 +26,75 @@ var import_utils = require("@domql/utils");
|
|
|
26
26
|
var import_ignore = require("./ignore");
|
|
27
27
|
var import_methods = require("./methods");
|
|
28
28
|
var import_updateState = require("./updateState");
|
|
29
|
-
var
|
|
29
|
+
var import_inherit = require("./inherit");
|
|
30
30
|
const createState = function(element, parent, opts) {
|
|
31
31
|
const skip = opts && opts.skip ? opts.skip : false;
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
32
|
+
const objectizeState = checkForTypes(element);
|
|
33
|
+
if (objectizeState === false)
|
|
34
|
+
return parent.state || {};
|
|
35
|
+
else
|
|
36
|
+
element.state = objectizeState;
|
|
37
|
+
const whatInitReturns = (0, import_event.triggerEventOn)("stateInit", element);
|
|
38
|
+
if (whatInitReturns === false)
|
|
39
|
+
return element.state;
|
|
40
|
+
if ((0, import_inherit.checkIfInherits)(element)) {
|
|
41
|
+
element.state = (0, import_inherit.createInheritedState)(element, parent) || {};
|
|
37
42
|
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
return {};
|
|
42
|
-
} else {
|
|
43
|
-
__elementRef.__hasRootState = true;
|
|
44
|
-
}
|
|
45
|
-
const { __ref } = state;
|
|
46
|
-
if (__ref) {
|
|
47
|
-
state = (0, import_utils.deepClone)(__ref, import_ignore.IGNORE_STATE_PARAMS);
|
|
48
|
-
if ((0, import_utils.isObject)(__ref.__depends)) {
|
|
49
|
-
__ref.__depends[element.key] = state;
|
|
50
|
-
} else
|
|
51
|
-
__ref.__depends = { [element.key]: state };
|
|
52
|
-
} else {
|
|
53
|
-
state = (0, import_utils.deepClone)(state, import_ignore.IGNORE_STATE_PARAMS);
|
|
54
|
-
}
|
|
55
|
-
element.state = state;
|
|
43
|
+
const dependentState = applyDependentState(element, state);
|
|
44
|
+
if (dependentState)
|
|
45
|
+
element.state = dependentState;
|
|
56
46
|
if (skip)
|
|
57
|
-
return state;
|
|
58
|
-
applyMethods(element
|
|
47
|
+
return element.state;
|
|
48
|
+
applyMethods(element);
|
|
59
49
|
(0, import_event.triggerEventOn)("stateCreated", element);
|
|
60
|
-
return state;
|
|
50
|
+
return element.state;
|
|
51
|
+
};
|
|
52
|
+
const applyDependentState = (element, state2) => {
|
|
53
|
+
const { __ref: ref } = state2;
|
|
54
|
+
if (!ref)
|
|
55
|
+
return;
|
|
56
|
+
const dependentState = (0, import_utils.deepClone)(ref, import_ignore.IGNORE_STATE_PARAMS);
|
|
57
|
+
const newDepends = { [element.key]: dependentState };
|
|
58
|
+
ref.__depends = (0, import_utils.isObject)(ref.__depends) ? { ...ref.__depends, ...newDepends } : newDepends;
|
|
59
|
+
return dependentState;
|
|
61
60
|
};
|
|
62
61
|
const checkForTypes = (element) => {
|
|
63
|
-
const { state, __ref:
|
|
64
|
-
if ((0, import_utils.isFunction)(
|
|
65
|
-
|
|
66
|
-
return (0, import_utils.exec)(
|
|
62
|
+
const { state: state2, __ref: ref } = element;
|
|
63
|
+
if ((0, import_utils.isFunction)(state2)) {
|
|
64
|
+
ref.__state = state2;
|
|
65
|
+
return (0, import_utils.exec)(state2, element);
|
|
67
66
|
}
|
|
68
|
-
if ((0, import_utils.is)(
|
|
69
|
-
|
|
67
|
+
if ((0, import_utils.is)(state2)("string", "number")) {
|
|
68
|
+
ref.__state = state2;
|
|
70
69
|
return {};
|
|
71
70
|
}
|
|
72
|
-
if (
|
|
73
|
-
|
|
71
|
+
if (state2 === true) {
|
|
72
|
+
ref.__state = element.key;
|
|
74
73
|
return {};
|
|
75
74
|
}
|
|
76
|
-
|
|
75
|
+
if (state2) {
|
|
76
|
+
ref.__hasRootState = true;
|
|
77
|
+
return state2;
|
|
78
|
+
}
|
|
79
|
+
return false;
|
|
77
80
|
};
|
|
78
|
-
const applyMethods = (element
|
|
79
|
-
const
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
81
|
+
const applyMethods = (element) => {
|
|
82
|
+
const state2 = element.state;
|
|
83
|
+
const ref = element.__ref;
|
|
84
|
+
state2.clean = import_methods.clean;
|
|
85
|
+
state2.parse = import_methods.parse;
|
|
86
|
+
state2.destroy = import_methods.destroy;
|
|
87
|
+
state2.update = import_updateState.updateState;
|
|
88
|
+
state2.rootUpdate = import_methods.rootUpdate;
|
|
89
|
+
state2.create = createState;
|
|
90
|
+
state2.add = import_methods.add;
|
|
91
|
+
state2.toggle = import_methods.toggle;
|
|
92
|
+
state2.remove = import_methods.remove;
|
|
93
|
+
state2.apply = import_methods.apply;
|
|
94
|
+
state2.parent = element.parent.state;
|
|
95
|
+
state2.__element = element;
|
|
96
|
+
state2.__children = {};
|
|
97
|
+
state2.__root = ref.__root ? ref.__root.state : state2;
|
|
98
|
+
if (state2.parent)
|
|
99
|
+
state2.parent.__children[element.key] = state2;
|
|
96
100
|
};
|
package/dist/cjs/index.js
CHANGED
|
@@ -19,4 +19,4 @@ __reExport(state_exports, require("./ignore"), module.exports);
|
|
|
19
19
|
__reExport(state_exports, require("./createState"), module.exports);
|
|
20
20
|
__reExport(state_exports, require("./updateState"), module.exports);
|
|
21
21
|
__reExport(state_exports, require("./methods"), module.exports);
|
|
22
|
-
__reExport(state_exports, require("./
|
|
22
|
+
__reExport(state_exports, require("./inherit"), module.exports);
|
|
@@ -16,18 +16,19 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
16
16
|
return to;
|
|
17
17
|
};
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
var
|
|
20
|
-
__export(
|
|
19
|
+
var inherit_exports = {};
|
|
20
|
+
__export(inherit_exports, {
|
|
21
21
|
checkIfInherits: () => checkIfInherits,
|
|
22
22
|
createInheritedState: () => createInheritedState,
|
|
23
|
+
findInheritedState: () => findInheritedState,
|
|
23
24
|
getChildStateInKey: () => getChildStateInKey,
|
|
24
25
|
getParentStateInKey: () => getParentStateInKey,
|
|
25
26
|
isState: () => isState
|
|
26
27
|
});
|
|
27
|
-
module.exports = __toCommonJS(
|
|
28
|
+
module.exports = __toCommonJS(inherit_exports);
|
|
28
29
|
var import_utils = require("@domql/utils");
|
|
29
|
-
const getParentStateInKey = (
|
|
30
|
-
const arr =
|
|
30
|
+
const getParentStateInKey = (stateKey2, parentState) => {
|
|
31
|
+
const arr = stateKey2.split("../");
|
|
31
32
|
const arrLength = arr.length - 1;
|
|
32
33
|
for (let i = 0; i < arrLength; i++) {
|
|
33
34
|
if (!parentState.parent)
|
|
@@ -36,48 +37,52 @@ const getParentStateInKey = (stateKey, parentState) => {
|
|
|
36
37
|
}
|
|
37
38
|
return parentState;
|
|
38
39
|
};
|
|
39
|
-
const getChildStateInKey = (
|
|
40
|
-
const arr =
|
|
40
|
+
const getChildStateInKey = (stateKey2, parentState) => {
|
|
41
|
+
const arr = stateKey2.split("/");
|
|
41
42
|
const arrLength = arr.length - 1;
|
|
42
43
|
for (let i = 0; i < arrLength; i++) {
|
|
43
44
|
const childKey = arr[i];
|
|
44
45
|
const grandChildKey = arr[i + 1];
|
|
45
46
|
const childInParent = parentState[childKey];
|
|
46
47
|
if (childInParent && childInParent[grandChildKey]) {
|
|
47
|
-
|
|
48
|
+
stateKey2 = grandChildKey;
|
|
48
49
|
parentState = childInParent;
|
|
49
50
|
} else
|
|
50
51
|
return;
|
|
51
52
|
}
|
|
52
|
-
return parentState[
|
|
53
|
+
return parentState[stateKey2];
|
|
53
54
|
};
|
|
54
|
-
const
|
|
55
|
-
const
|
|
56
|
-
let
|
|
57
|
-
if (!
|
|
55
|
+
const findInheritedState = (element, parent) => {
|
|
56
|
+
const ref = element.__ref;
|
|
57
|
+
let stateKey2 = ref.__state;
|
|
58
|
+
if (!stateKey2 || (0, import_utils.isNot)(stateKey2)("number", "string"))
|
|
58
59
|
return element.state;
|
|
59
60
|
let parentState = parent.state;
|
|
60
|
-
if (
|
|
61
|
-
parentState = getParentStateInKey(
|
|
62
|
-
|
|
61
|
+
if (stateKey2.includes("../")) {
|
|
62
|
+
parentState = getParentStateInKey(stateKey2, parent.state);
|
|
63
|
+
stateKey2 = stateKey2.replaceAll("../", "");
|
|
63
64
|
}
|
|
64
65
|
if (!parentState)
|
|
65
66
|
return;
|
|
66
|
-
|
|
67
|
-
|
|
67
|
+
return getChildStateInKey(stateKey2, parentState);
|
|
68
|
+
};
|
|
69
|
+
const createInheritedState = (element, parent) => {
|
|
70
|
+
const ref = element.__ref;
|
|
71
|
+
const inheritedState = findInheritedState(element, parent);
|
|
72
|
+
if (!inheritedState)
|
|
68
73
|
return;
|
|
69
|
-
if ((0, import_utils.is)(
|
|
70
|
-
return (0, import_utils.deepClone)(
|
|
71
|
-
} else if ((0, import_utils.is)(
|
|
72
|
-
|
|
73
|
-
return { value:
|
|
74
|
+
if ((0, import_utils.is)(inheritedState)("object", "array")) {
|
|
75
|
+
return (0, import_utils.deepClone)(inheritedState);
|
|
76
|
+
} else if ((0, import_utils.is)(inheritedState)("string", "number")) {
|
|
77
|
+
ref.__stateType = "string";
|
|
78
|
+
return { value: inheritedState };
|
|
74
79
|
}
|
|
75
80
|
console.warn(stateKey, "is not present. Replacing with", {});
|
|
76
81
|
};
|
|
77
82
|
const checkIfInherits = (element) => {
|
|
78
|
-
const
|
|
79
|
-
const
|
|
80
|
-
if (!
|
|
83
|
+
const ref = element.__ref;
|
|
84
|
+
const stateKey2 = ref.__state;
|
|
85
|
+
if (!stateKey2 || (0, import_utils.isNot)(stateKey2)("number", "string"))
|
|
81
86
|
return false;
|
|
82
87
|
return true;
|
|
83
88
|
};
|
package/dist/cjs/updateState.js
CHANGED
|
@@ -25,7 +25,7 @@ var import_report = require("@domql/report");
|
|
|
25
25
|
var import_event = require("@domql/event");
|
|
26
26
|
var import_ignore = require("./ignore");
|
|
27
27
|
var import_utils = require("@domql/utils");
|
|
28
|
-
var
|
|
28
|
+
var import_inherit = require("./inherit");
|
|
29
29
|
const updateState = function(obj, options = {}) {
|
|
30
30
|
const state = this;
|
|
31
31
|
const element = state.__element;
|
|
@@ -38,7 +38,7 @@ const updateState = function(obj, options = {}) {
|
|
|
38
38
|
}
|
|
39
39
|
applyOverwrite(state, obj, options);
|
|
40
40
|
hoistStateUpdate(state, obj, options);
|
|
41
|
-
|
|
41
|
+
updateDependentState(state, obj, options);
|
|
42
42
|
applyElementUpdate(state, obj, options);
|
|
43
43
|
if (!options.preventStateUpdateListener) {
|
|
44
44
|
(0, import_event.triggerEventOn)("stateUpdated", element, obj);
|
|
@@ -58,29 +58,32 @@ const applyOverwrite = (state, obj, options) => {
|
|
|
58
58
|
};
|
|
59
59
|
const hoistStateUpdate = (state, obj, options) => {
|
|
60
60
|
const element = state.__element;
|
|
61
|
-
const
|
|
62
|
-
const stateKey =
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
const
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
61
|
+
const { parent, __ref: ref } = element;
|
|
62
|
+
const stateKey = ref.__state;
|
|
63
|
+
if (!stateKey)
|
|
64
|
+
return;
|
|
65
|
+
const asksForInherit = (0, import_inherit.checkIfInherits)(element);
|
|
66
|
+
const inheritedState = (0, import_inherit.findInheritedState)(element, parent);
|
|
67
|
+
const shouldPropagateState = asksForInherit && inheritedState && !options.stopStatePropagation;
|
|
68
|
+
if (!shouldPropagateState)
|
|
69
|
+
return;
|
|
70
|
+
console.log(inheritedState);
|
|
71
|
+
const isStringState = ref.__stateType === "string";
|
|
72
|
+
const value = isStringState ? state.value : state.parse();
|
|
73
|
+
const passedValue = isStringState ? state.value : obj;
|
|
74
|
+
inheritedState[stateKey] = value;
|
|
75
|
+
inheritedState.update({ [stateKey]: passedValue }, {
|
|
76
|
+
skipOverwrite: true,
|
|
77
|
+
preventUpdate: options.preventHoistElementUpdate,
|
|
78
|
+
...options
|
|
79
|
+
});
|
|
77
80
|
};
|
|
78
|
-
const
|
|
79
|
-
if (state.__depends)
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
81
|
+
const updateDependentState = (state, obj, options) => {
|
|
82
|
+
if (!state.__depends)
|
|
83
|
+
return;
|
|
84
|
+
for (const el in state.__depends) {
|
|
85
|
+
const dependentState = state.__depends[el];
|
|
86
|
+
dependentState.clean().update(state.parse(), options);
|
|
84
87
|
}
|
|
85
88
|
};
|
|
86
89
|
const applyElementUpdate = (state, obj, options) => {
|
package/index.js
CHANGED
package/{utils.js → inherit.js}
RENAMED
|
@@ -27,9 +27,9 @@ export const getChildStateInKey = (stateKey, parentState) => {
|
|
|
27
27
|
return parentState[stateKey]
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
-
export const
|
|
31
|
-
const
|
|
32
|
-
let stateKey =
|
|
30
|
+
export const findInheritedState = (element, parent) => {
|
|
31
|
+
const ref = element.__ref
|
|
32
|
+
let stateKey = ref.__state
|
|
33
33
|
if (!stateKey || isNot(stateKey)('number', 'string')) return element.state
|
|
34
34
|
|
|
35
35
|
let parentState = parent.state
|
|
@@ -38,23 +38,27 @@ export const createInheritedState = (element, parent) => {
|
|
|
38
38
|
stateKey = stateKey.replaceAll('../', '')
|
|
39
39
|
}
|
|
40
40
|
if (!parentState) return
|
|
41
|
+
return getChildStateInKey(stateKey, parentState)
|
|
42
|
+
}
|
|
41
43
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
+
export const createInheritedState = (element, parent) => {
|
|
45
|
+
const ref = element.__ref
|
|
46
|
+
const inheritedState = findInheritedState(element, parent)
|
|
47
|
+
if (!inheritedState) return
|
|
44
48
|
|
|
45
|
-
if (is(
|
|
46
|
-
return deepClone(
|
|
47
|
-
} else if (is(
|
|
48
|
-
|
|
49
|
-
return { value:
|
|
49
|
+
if (is(inheritedState)('object', 'array')) {
|
|
50
|
+
return deepClone(inheritedState)
|
|
51
|
+
} else if (is(inheritedState)('string', 'number')) {
|
|
52
|
+
ref.__stateType = 'string'
|
|
53
|
+
return { value: inheritedState }
|
|
50
54
|
}
|
|
51
55
|
|
|
52
56
|
console.warn(stateKey, 'is not present. Replacing with', {})
|
|
53
57
|
}
|
|
54
58
|
|
|
55
59
|
export const checkIfInherits = (element) => {
|
|
56
|
-
const
|
|
57
|
-
const stateKey =
|
|
60
|
+
const ref = element.__ref
|
|
61
|
+
const stateKey = ref.__state
|
|
58
62
|
if (!stateKey || isNot(stateKey)('number', 'string')) return false
|
|
59
63
|
return true
|
|
60
64
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@domql/state",
|
|
3
|
-
"version": "2.3.
|
|
3
|
+
"version": "2.3.122",
|
|
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": "e599b1dc425a72bd3ec989b909f47bb51bf4dbac"
|
|
30
30
|
}
|
package/updateState.js
CHANGED
|
@@ -4,7 +4,7 @@ import { report } from '@domql/report'
|
|
|
4
4
|
import { triggerEventOn } from '@domql/event'
|
|
5
5
|
import { IGNORE_STATE_PARAMS } from './ignore'
|
|
6
6
|
import { deepMerge, overwriteDeep, overwriteShallow } from '@domql/utils'
|
|
7
|
-
import { checkIfInherits } from './
|
|
7
|
+
import { checkIfInherits, findInheritedState } from './inherit'
|
|
8
8
|
|
|
9
9
|
export const updateState = function (obj, options = {}) {
|
|
10
10
|
const state = this
|
|
@@ -21,7 +21,7 @@ export const updateState = function (obj, options = {}) {
|
|
|
21
21
|
|
|
22
22
|
hoistStateUpdate(state, obj, options)
|
|
23
23
|
|
|
24
|
-
|
|
24
|
+
updateDependentState(state, obj, options)
|
|
25
25
|
|
|
26
26
|
applyElementUpdate(state, obj, options)
|
|
27
27
|
|
|
@@ -48,32 +48,33 @@ const applyOverwrite = (state, obj, options) => {
|
|
|
48
48
|
|
|
49
49
|
const hoistStateUpdate = (state, obj, options) => {
|
|
50
50
|
const element = state.__element
|
|
51
|
-
const
|
|
52
|
-
const stateKey =
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
const
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
51
|
+
const { parent, __ref: ref } = element
|
|
52
|
+
const stateKey = ref.__state
|
|
53
|
+
if (!stateKey) return
|
|
54
|
+
|
|
55
|
+
const asksForInherit = checkIfInherits(element)
|
|
56
|
+
const inheritedState = findInheritedState(element, parent)
|
|
57
|
+
const shouldPropagateState = asksForInherit && inheritedState && !options.stopStatePropagation
|
|
58
|
+
if (!shouldPropagateState) return
|
|
59
|
+
console.log(inheritedState)
|
|
60
|
+
|
|
61
|
+
const isStringState = (ref.__stateType === 'string')
|
|
62
|
+
const value = isStringState ? state.value : state.parse()
|
|
63
|
+
const passedValue = isStringState ? state.value : obj
|
|
64
|
+
|
|
65
|
+
inheritedState[stateKey] = value
|
|
66
|
+
inheritedState.update({ [stateKey]: passedValue }, {
|
|
67
|
+
skipOverwrite: true,
|
|
68
|
+
preventUpdate: options.preventHoistElementUpdate,
|
|
69
|
+
...options
|
|
70
|
+
})
|
|
69
71
|
}
|
|
70
72
|
|
|
71
|
-
const
|
|
72
|
-
if (state.__depends)
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
}
|
|
73
|
+
const updateDependentState = (state, obj, options) => {
|
|
74
|
+
if (!state.__depends) return
|
|
75
|
+
for (const el in state.__depends) {
|
|
76
|
+
const dependentState = state.__depends[el]
|
|
77
|
+
dependentState.clean().update(state.parse(), options)
|
|
77
78
|
}
|
|
78
79
|
}
|
|
79
80
|
|