@domql/state 2.31.30 → 2.31.31
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/dist/cjs/updateState.js +26 -15
- package/dist/esm/updateState.js +31 -14
- package/package.json +5 -5
- package/updateState.js +43 -20
package/dist/cjs/updateState.js
CHANGED
|
@@ -30,8 +30,7 @@ const STATE_UPDATE_OPTIONS = {
|
|
|
30
30
|
overwrite: true,
|
|
31
31
|
preventHoistElementUpdate: false,
|
|
32
32
|
updateByState: true,
|
|
33
|
-
isHoisted: true
|
|
34
|
-
execStateFunction: true
|
|
33
|
+
isHoisted: true
|
|
35
34
|
};
|
|
36
35
|
const updateState = async function(obj, options = STATE_UPDATE_OPTIONS) {
|
|
37
36
|
const state = this;
|
|
@@ -43,7 +42,12 @@ const updateState = async function(obj, options = STATE_UPDATE_OPTIONS) {
|
|
|
43
42
|
options.preventInheritAtCurrentState = state;
|
|
44
43
|
} else if (options.preventInheritAtCurrentState) return;
|
|
45
44
|
if (!options.preventBeforeStateUpdateListener) {
|
|
46
|
-
const beforeStateUpdateReturns = await (0, import_event.triggerEventOnUpdate)(
|
|
45
|
+
const beforeStateUpdateReturns = await (0, import_event.triggerEventOnUpdate)(
|
|
46
|
+
"beforeStateUpdate",
|
|
47
|
+
obj,
|
|
48
|
+
element,
|
|
49
|
+
options
|
|
50
|
+
);
|
|
47
51
|
if (beforeStateUpdateReturns === false) return element;
|
|
48
52
|
}
|
|
49
53
|
applyOverwrite(state, obj, options);
|
|
@@ -76,7 +80,9 @@ const hoistStateUpdate = async (state, obj, options) => {
|
|
|
76
80
|
const stateType = ref == null ? void 0 : ref.__stateType;
|
|
77
81
|
if (!stateKey) return;
|
|
78
82
|
const asksForInherit = (0, import_inherit.checkIfInherits)(element);
|
|
79
|
-
const inheritedState = (0, import_inherit.findInheritedState)(element, parent, {
|
|
83
|
+
const inheritedState = (0, import_inherit.findInheritedState)(element, parent, {
|
|
84
|
+
returnParent: true
|
|
85
|
+
});
|
|
80
86
|
const shouldPropagateState = asksForInherit && inheritedState && !options.stopStatePropagation;
|
|
81
87
|
if (!shouldPropagateState) return;
|
|
82
88
|
const isStringState = stateType === "string" || stateType === "number" || stateType === "boolean";
|
|
@@ -88,7 +94,6 @@ const hoistStateUpdate = async (state, obj, options) => {
|
|
|
88
94
|
const targetParent = findRootState || findGrandParentState || parent.state;
|
|
89
95
|
if (options.replace) (0, import_utils.overwriteDeep)(targetParent, changesValue || value);
|
|
90
96
|
await targetParent.update(changesValue, {
|
|
91
|
-
execStateFunction: false,
|
|
92
97
|
isHoisted: true,
|
|
93
98
|
preventUpdate: options.preventHoistElementUpdate,
|
|
94
99
|
overwrite: !options.replace,
|
|
@@ -110,16 +115,22 @@ const updateDependentState = async (state, obj, options) => {
|
|
|
110
115
|
const applyElementUpdate = async (state, obj, options) => {
|
|
111
116
|
const element = state.__element;
|
|
112
117
|
if (options.preventUpdate !== true) {
|
|
113
|
-
await element.update(
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
118
|
+
await element.update(
|
|
119
|
+
{},
|
|
120
|
+
{
|
|
121
|
+
...options,
|
|
122
|
+
updateByState: true
|
|
123
|
+
}
|
|
124
|
+
);
|
|
117
125
|
} else if (options.preventUpdate === "recursive") {
|
|
118
|
-
await element.update(
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
126
|
+
await element.update(
|
|
127
|
+
{},
|
|
128
|
+
{
|
|
129
|
+
...options,
|
|
130
|
+
isHoisted: false,
|
|
131
|
+
updateByState: true,
|
|
132
|
+
preventUpdate: true
|
|
133
|
+
}
|
|
134
|
+
);
|
|
124
135
|
}
|
|
125
136
|
};
|
package/dist/esm/updateState.js
CHANGED
|
@@ -21,13 +21,18 @@ import { report } from "@domql/report";
|
|
|
21
21
|
import { triggerEventOnUpdate } from "@domql/event";
|
|
22
22
|
import { IGNORE_STATE_PARAMS } from "./ignore.js";
|
|
23
23
|
import { deepMerge, merge, overwriteDeep, overwriteShallow } from "@domql/utils";
|
|
24
|
-
import {
|
|
24
|
+
import {
|
|
25
|
+
checkIfInherits,
|
|
26
|
+
createNestedObjectByKeyPath,
|
|
27
|
+
findInheritedState,
|
|
28
|
+
getParentStateInKey,
|
|
29
|
+
getRootStateInKey
|
|
30
|
+
} from "./inherit.js";
|
|
25
31
|
const STATE_UPDATE_OPTIONS = {
|
|
26
32
|
overwrite: true,
|
|
27
33
|
preventHoistElementUpdate: false,
|
|
28
34
|
updateByState: true,
|
|
29
|
-
isHoisted: true
|
|
30
|
-
execStateFunction: true
|
|
35
|
+
isHoisted: true
|
|
31
36
|
};
|
|
32
37
|
const updateState = async function(obj, options = STATE_UPDATE_OPTIONS) {
|
|
33
38
|
const state = this;
|
|
@@ -39,7 +44,12 @@ const updateState = async function(obj, options = STATE_UPDATE_OPTIONS) {
|
|
|
39
44
|
options.preventInheritAtCurrentState = state;
|
|
40
45
|
} else if (options.preventInheritAtCurrentState) return;
|
|
41
46
|
if (!options.preventBeforeStateUpdateListener) {
|
|
42
|
-
const beforeStateUpdateReturns = await triggerEventOnUpdate(
|
|
47
|
+
const beforeStateUpdateReturns = await triggerEventOnUpdate(
|
|
48
|
+
"beforeStateUpdate",
|
|
49
|
+
obj,
|
|
50
|
+
element,
|
|
51
|
+
options
|
|
52
|
+
);
|
|
43
53
|
if (beforeStateUpdateReturns === false) return element;
|
|
44
54
|
}
|
|
45
55
|
applyOverwrite(state, obj, options);
|
|
@@ -72,7 +82,9 @@ const hoistStateUpdate = async (state, obj, options) => {
|
|
|
72
82
|
const stateType = ref == null ? void 0 : ref.__stateType;
|
|
73
83
|
if (!stateKey) return;
|
|
74
84
|
const asksForInherit = checkIfInherits(element);
|
|
75
|
-
const inheritedState = findInheritedState(element, parent, {
|
|
85
|
+
const inheritedState = findInheritedState(element, parent, {
|
|
86
|
+
returnParent: true
|
|
87
|
+
});
|
|
76
88
|
const shouldPropagateState = asksForInherit && inheritedState && !options.stopStatePropagation;
|
|
77
89
|
if (!shouldPropagateState) return;
|
|
78
90
|
const isStringState = stateType === "string" || stateType === "number" || stateType === "boolean";
|
|
@@ -84,7 +96,6 @@ const hoistStateUpdate = async (state, obj, options) => {
|
|
|
84
96
|
const targetParent = findRootState || findGrandParentState || parent.state;
|
|
85
97
|
if (options.replace) overwriteDeep(targetParent, changesValue || value);
|
|
86
98
|
await targetParent.update(changesValue, __spreadValues({
|
|
87
|
-
execStateFunction: false,
|
|
88
99
|
isHoisted: true,
|
|
89
100
|
preventUpdate: options.preventHoistElementUpdate,
|
|
90
101
|
overwrite: !options.replace
|
|
@@ -105,15 +116,21 @@ const updateDependentState = async (state, obj, options) => {
|
|
|
105
116
|
const applyElementUpdate = async (state, obj, options) => {
|
|
106
117
|
const element = state.__element;
|
|
107
118
|
if (options.preventUpdate !== true) {
|
|
108
|
-
await element.update(
|
|
109
|
-
|
|
110
|
-
|
|
119
|
+
await element.update(
|
|
120
|
+
{},
|
|
121
|
+
__spreadProps(__spreadValues({}, options), {
|
|
122
|
+
updateByState: true
|
|
123
|
+
})
|
|
124
|
+
);
|
|
111
125
|
} else if (options.preventUpdate === "recursive") {
|
|
112
|
-
await element.update(
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
126
|
+
await element.update(
|
|
127
|
+
{},
|
|
128
|
+
__spreadProps(__spreadValues({}, options), {
|
|
129
|
+
isHoisted: false,
|
|
130
|
+
updateByState: true,
|
|
131
|
+
preventUpdate: true
|
|
132
|
+
})
|
|
133
|
+
);
|
|
117
134
|
}
|
|
118
135
|
};
|
|
119
136
|
export {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@domql/state",
|
|
3
|
-
"version": "2.31.
|
|
3
|
+
"version": "2.31.31",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "index.js",
|
|
@@ -28,9 +28,9 @@
|
|
|
28
28
|
"prepublish": "npx rimraf -I dist && npm run build && npm run copy:package:cjs"
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@domql/event": "^2.31.
|
|
32
|
-
"@domql/report": "^2.31.
|
|
33
|
-
"@domql/utils": "^2.31.
|
|
31
|
+
"@domql/event": "^2.31.31",
|
|
32
|
+
"@domql/report": "^2.31.31",
|
|
33
|
+
"@domql/utils": "^2.31.31"
|
|
34
34
|
},
|
|
35
|
-
"gitHead": "
|
|
35
|
+
"gitHead": "a87c7ae3e84fbab1a9ee130d6d03f384e94260ab"
|
|
36
36
|
}
|
package/updateState.js
CHANGED
|
@@ -4,17 +4,25 @@ import { report } from '@domql/report'
|
|
|
4
4
|
import { triggerEventOnUpdate } from '@domql/event'
|
|
5
5
|
import { IGNORE_STATE_PARAMS } from './ignore.js'
|
|
6
6
|
import { deepMerge, merge, overwriteDeep, overwriteShallow } from '@domql/utils'
|
|
7
|
-
import {
|
|
7
|
+
import {
|
|
8
|
+
checkIfInherits,
|
|
9
|
+
createNestedObjectByKeyPath,
|
|
10
|
+
findInheritedState,
|
|
11
|
+
getParentStateInKey,
|
|
12
|
+
getRootStateInKey
|
|
13
|
+
} from './inherit.js'
|
|
8
14
|
|
|
9
15
|
const STATE_UPDATE_OPTIONS = {
|
|
10
16
|
overwrite: true,
|
|
11
17
|
preventHoistElementUpdate: false,
|
|
12
18
|
updateByState: true,
|
|
13
|
-
isHoisted: true
|
|
14
|
-
execStateFunction: true
|
|
19
|
+
isHoisted: true
|
|
15
20
|
}
|
|
16
21
|
|
|
17
|
-
export const updateState = async function (
|
|
22
|
+
export const updateState = async function (
|
|
23
|
+
obj,
|
|
24
|
+
options = STATE_UPDATE_OPTIONS
|
|
25
|
+
) {
|
|
18
26
|
const state = this
|
|
19
27
|
const element = state.__element
|
|
20
28
|
|
|
@@ -28,7 +36,12 @@ export const updateState = async function (obj, options = STATE_UPDATE_OPTIONS)
|
|
|
28
36
|
} else if (options.preventInheritAtCurrentState) return
|
|
29
37
|
|
|
30
38
|
if (!options.preventBeforeStateUpdateListener) {
|
|
31
|
-
const beforeStateUpdateReturns = await triggerEventOnUpdate(
|
|
39
|
+
const beforeStateUpdateReturns = await triggerEventOnUpdate(
|
|
40
|
+
'beforeStateUpdate',
|
|
41
|
+
obj,
|
|
42
|
+
element,
|
|
43
|
+
options
|
|
44
|
+
)
|
|
32
45
|
if (beforeStateUpdateReturns === false) return element
|
|
33
46
|
}
|
|
34
47
|
|
|
@@ -73,11 +86,15 @@ const hoistStateUpdate = async (state, obj, options) => {
|
|
|
73
86
|
if (!stateKey) return
|
|
74
87
|
|
|
75
88
|
const asksForInherit = checkIfInherits(element)
|
|
76
|
-
const inheritedState = findInheritedState(element, parent, {
|
|
77
|
-
|
|
89
|
+
const inheritedState = findInheritedState(element, parent, {
|
|
90
|
+
returnParent: true
|
|
91
|
+
})
|
|
92
|
+
const shouldPropagateState =
|
|
93
|
+
asksForInherit && inheritedState && !options.stopStatePropagation
|
|
78
94
|
if (!shouldPropagateState) return
|
|
79
95
|
|
|
80
|
-
const isStringState =
|
|
96
|
+
const isStringState =
|
|
97
|
+
stateType === 'string' || stateType === 'number' || stateType === 'boolean'
|
|
81
98
|
const value = isStringState ? state.value : state.parse()
|
|
82
99
|
const passedValue = isStringState ? state.value : obj
|
|
83
100
|
|
|
@@ -87,13 +104,13 @@ const hoistStateUpdate = async (state, obj, options) => {
|
|
|
87
104
|
const targetParent = findRootState || findGrandParentState || parent.state
|
|
88
105
|
if (options.replace) overwriteDeep(targetParent, changesValue || value) // check with createNestedObjectByKeyPath
|
|
89
106
|
await targetParent.update(changesValue, {
|
|
90
|
-
execStateFunction: false,
|
|
91
107
|
isHoisted: true,
|
|
92
108
|
preventUpdate: options.preventHoistElementUpdate,
|
|
93
109
|
overwrite: !options.replace,
|
|
94
110
|
...options
|
|
95
111
|
})
|
|
96
|
-
const hasNotUpdated =
|
|
112
|
+
const hasNotUpdated =
|
|
113
|
+
options.preventUpdate !== true || !options.preventHoistElementUpdate
|
|
97
114
|
if (!options.preventStateUpdateListener && hasNotUpdated) {
|
|
98
115
|
await triggerEventOnUpdate('stateUpdate', obj, element, options)
|
|
99
116
|
}
|
|
@@ -111,16 +128,22 @@ const updateDependentState = async (state, obj, options) => {
|
|
|
111
128
|
const applyElementUpdate = async (state, obj, options) => {
|
|
112
129
|
const element = state.__element
|
|
113
130
|
if (options.preventUpdate !== true) {
|
|
114
|
-
await element.update(
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
131
|
+
await element.update(
|
|
132
|
+
{},
|
|
133
|
+
{
|
|
134
|
+
...options,
|
|
135
|
+
updateByState: true
|
|
136
|
+
}
|
|
137
|
+
)
|
|
118
138
|
} else if (options.preventUpdate === 'recursive') {
|
|
119
|
-
await element.update(
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
139
|
+
await element.update(
|
|
140
|
+
{},
|
|
141
|
+
{
|
|
142
|
+
...options,
|
|
143
|
+
isHoisted: false,
|
|
144
|
+
updateByState: true,
|
|
145
|
+
preventUpdate: true
|
|
146
|
+
}
|
|
147
|
+
)
|
|
125
148
|
}
|
|
126
149
|
}
|