domql 1.6.21 → 1.6.23
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/element/create.js +47 -42
- package/dist/cjs/element/extend.js +2 -2
- package/dist/cjs/element/iterate.js +36 -32
- package/dist/cjs/element/methods.js +1 -1
- package/dist/cjs/element/node.js +4 -4
- package/dist/cjs/element/update.js +75 -41
- package/dist/esm/element/applyParam.js +2538 -2369
- package/dist/esm/element/create.js +2737 -2570
- package/dist/esm/element/define.js +2557 -2388
- package/dist/esm/element/extend.js +1535 -2313
- package/dist/esm/element/index.js +2448 -2277
- package/dist/esm/element/iterate.js +1524 -2298
- package/dist/esm/element/methods.js +2544 -2375
- package/dist/esm/element/node.js +2802 -2633
- package/dist/esm/element/parse.js +2772 -2605
- package/dist/esm/element/remove.js +289 -282
- package/dist/esm/element/set.js +2737 -2570
- package/dist/esm/element/update.js +2744 -2575
- package/dist/esm/index.js +2451 -2280
- package/dist/iife/index.js +2451 -2280
- package/package.json +2 -2
- package/src/element/create.js +2 -2
- package/src/element/iterate.js +2 -1
|
@@ -36,22 +36,24 @@ var import_render = require("@domql/render");
|
|
|
36
36
|
var import_methods = require("@domql/methods");
|
|
37
37
|
var import_classlist = require("@domql/classlist");
|
|
38
38
|
var import_node = require("@domql/node");
|
|
39
|
+
var import_state = require("@domql/state");
|
|
40
|
+
var import_props = require("@domql/props");
|
|
39
41
|
var import_node2 = __toESM(require("./node"));
|
|
40
42
|
var import_extend = require("./extend");
|
|
41
43
|
var import_set = __toESM(require("./set"));
|
|
42
|
-
var import_state = __toESM(require("./state"));
|
|
43
|
-
var import_props = __toESM(require("./props"));
|
|
44
44
|
var import_update = __toESM(require("./update"));
|
|
45
45
|
var import_methods2 = require("./methods");
|
|
46
46
|
var import_mixins = require("./mixins");
|
|
47
47
|
var import_iterate = require("./iterate");
|
|
48
48
|
var import_options = __toESM(require("./options"));
|
|
49
|
-
var import_component = require("
|
|
49
|
+
var import_component = require("./utils/component");
|
|
50
50
|
var import_remove = require("./remove");
|
|
51
51
|
const ENV = "development";
|
|
52
52
|
const create = (element, parent, key, options = import_options.default.create || {}) => {
|
|
53
|
-
if (options && !import_options.default.create)
|
|
53
|
+
if (options && !import_options.default.create) {
|
|
54
54
|
import_options.default.create = options;
|
|
55
|
+
import_options.default.create.context = element.context || options.context;
|
|
56
|
+
}
|
|
55
57
|
if (element === void 0) {
|
|
56
58
|
if (ENV === "test" || ENV === "development") {
|
|
57
59
|
console.warn(key, "element is undefined in", parent && parent.__ref && parent.__ref.path);
|
|
@@ -96,8 +98,9 @@ const create = (element, parent, key, options = import_options.default.create ||
|
|
|
96
98
|
(0, import_component.applyComponentFromContext)(element, parent, options);
|
|
97
99
|
(0, import_extend.applyExtend)(element, parent, options);
|
|
98
100
|
element.key = assignedKey;
|
|
99
|
-
if (options.onlyResolveExtends)
|
|
101
|
+
if (options.onlyResolveExtends) {
|
|
100
102
|
return resolveExtends(element, parent, options);
|
|
103
|
+
}
|
|
101
104
|
if (Object.keys(options).length) {
|
|
102
105
|
import_mixins.registry.defaultOptions = options;
|
|
103
106
|
if (options.ignoreChildExtend)
|
|
@@ -105,24 +108,24 @@ const create = (element, parent, key, options = import_options.default.create ||
|
|
|
105
108
|
}
|
|
106
109
|
addCaching(element, parent);
|
|
107
110
|
addMethods(element, parent);
|
|
108
|
-
element.state = (0, import_state.
|
|
111
|
+
element.state = (0, import_state.createState)(element, parent);
|
|
109
112
|
checkIf(element, parent);
|
|
110
113
|
if (element.node && __ref.__if) {
|
|
111
114
|
return (0, import_render.assignNode)(element, parent, assignedKey);
|
|
112
115
|
}
|
|
113
116
|
if (__ref.__if)
|
|
114
|
-
(0, import_props.
|
|
115
|
-
const initReturns = (0, import_event.triggerEventOn)("init", element);
|
|
117
|
+
(0, import_props.createProps)(element, parent);
|
|
118
|
+
const initReturns = (0, import_event.triggerEventOn)("init", element, options);
|
|
116
119
|
if (initReturns === false)
|
|
117
120
|
return element;
|
|
118
|
-
(0, import_event.triggerEventOn)("beforeClassAssign", element);
|
|
121
|
+
(0, import_event.triggerEventOn)("beforeClassAssign", element, options);
|
|
119
122
|
(0, import_classlist.assignClass)(element);
|
|
120
123
|
(0, import_node2.default)(element, options);
|
|
121
124
|
if (!__ref.__if)
|
|
122
125
|
return element;
|
|
123
126
|
(0, import_render.assignNode)(element, parent, key);
|
|
124
|
-
(0, import_event.triggerEventOn)("renderRouter", element);
|
|
125
|
-
(0, import_event.triggerEventOn)("render", element);
|
|
127
|
+
(0, import_event.triggerEventOn)("renderRouter", element, options);
|
|
128
|
+
(0, import_event.triggerEventOn)("render", element, options);
|
|
126
129
|
if (parent.__ref && parent.__ref.__children)
|
|
127
130
|
parent.__ref.__children.push(element.key);
|
|
128
131
|
return element;
|
|
@@ -163,46 +166,48 @@ const applyContext = (element, parent, options) => {
|
|
|
163
166
|
element.context = parent.context || options.context || import_tree.ROOT.context;
|
|
164
167
|
};
|
|
165
168
|
const checkIf = (element, parent) => {
|
|
166
|
-
const { __ref } = element;
|
|
169
|
+
const { __ref: ref } = element;
|
|
167
170
|
if ((0, import_utils.isFunction)(element.if)) {
|
|
168
171
|
const ifPassed = element.if(element, element.state);
|
|
169
172
|
if (!ifPassed) {
|
|
170
173
|
const ifFragment = (0, import_node.cacheNode)({ tag: "fragment" });
|
|
171
|
-
|
|
172
|
-
delete
|
|
174
|
+
ref.__ifFragment = (0, import_render.appendNode)(ifFragment, parent.node);
|
|
175
|
+
delete ref.__if;
|
|
173
176
|
} else
|
|
174
|
-
|
|
177
|
+
ref.__if = true;
|
|
175
178
|
} else
|
|
176
|
-
|
|
179
|
+
ref.__if = true;
|
|
177
180
|
};
|
|
178
181
|
const addCaching = (element, parent) => {
|
|
179
|
-
const { __ref } = element;
|
|
180
|
-
let { __ref:
|
|
182
|
+
const { __ref: ref } = element;
|
|
183
|
+
let { __ref: parentRef } = parent;
|
|
181
184
|
if (!element.transform)
|
|
182
185
|
element.transform = {};
|
|
183
|
-
if (!
|
|
184
|
-
|
|
185
|
-
if (!
|
|
186
|
-
|
|
187
|
-
if (!
|
|
188
|
-
|
|
189
|
-
if (!
|
|
190
|
-
|
|
191
|
-
if (!
|
|
192
|
-
|
|
193
|
-
if (!
|
|
194
|
-
|
|
195
|
-
if (!
|
|
196
|
-
|
|
186
|
+
if (!ref.__cached)
|
|
187
|
+
ref.__cached = {};
|
|
188
|
+
if (!ref.__defineCache)
|
|
189
|
+
ref.__defineCache = {};
|
|
190
|
+
if (!ref.__exec)
|
|
191
|
+
ref.__exec = {};
|
|
192
|
+
if (!ref.__class)
|
|
193
|
+
ref.__class = {};
|
|
194
|
+
if (!ref.__classNames)
|
|
195
|
+
ref.__classNames = {};
|
|
196
|
+
if (!ref.__attr)
|
|
197
|
+
ref.__attr = {};
|
|
198
|
+
if (!ref.__changes)
|
|
199
|
+
ref.__changes = [];
|
|
200
|
+
if (!ref.__children)
|
|
201
|
+
ref.__children = [];
|
|
197
202
|
const hasRoot = parent && parent.key === ":root";
|
|
198
|
-
if (!
|
|
199
|
-
|
|
203
|
+
if (!ref.__root)
|
|
204
|
+
ref.__root = hasRoot ? element : parentRef.__root;
|
|
200
205
|
if (ENV === "test" || ENV === "development") {
|
|
201
|
-
if (!
|
|
202
|
-
|
|
203
|
-
if (!
|
|
204
|
-
|
|
205
|
-
|
|
206
|
+
if (!parentRef)
|
|
207
|
+
parentRef = parent.ref = {};
|
|
208
|
+
if (!parentRef.__path)
|
|
209
|
+
parentRef.__path = [];
|
|
210
|
+
ref.__path = parentRef.__path.concat(element.key);
|
|
206
211
|
}
|
|
207
212
|
};
|
|
208
213
|
const resolveExtends = (element, parent, options) => {
|
|
@@ -216,9 +221,9 @@ const resolveExtends = (element, parent, options) => {
|
|
|
216
221
|
element.props = {};
|
|
217
222
|
if (!element.state)
|
|
218
223
|
element.state = {};
|
|
219
|
-
element = (0, import_props.
|
|
220
|
-
(0, import_state.
|
|
221
|
-
(0, import_iterate.throughInitialExec)(element);
|
|
224
|
+
element = (0, import_props.createProps)(element, parent);
|
|
225
|
+
(0, import_state.createState)(element, parent, { skip: true });
|
|
226
|
+
(0, import_iterate.throughInitialExec)(element, options.propsExcludedFromExec);
|
|
222
227
|
for (const param in element) {
|
|
223
228
|
const prop = element[param];
|
|
224
229
|
if ((0, import_methods.isMethod)(param) || (0, import_utils.isObject)(import_mixins.registry[param]) || prop === void 0)
|
|
@@ -22,14 +22,14 @@ __export(extend_exports, {
|
|
|
22
22
|
});
|
|
23
23
|
module.exports = __toCommonJS(extend_exports);
|
|
24
24
|
var import_utils = require("@domql/utils");
|
|
25
|
-
var import_utils2 = require("
|
|
25
|
+
var import_utils2 = require("./utils");
|
|
26
26
|
const ENV = "development";
|
|
27
27
|
const applyExtend = (element, parent, options = {}) => {
|
|
28
28
|
if ((0, import_utils.isFunction)(element))
|
|
29
29
|
element = (0, import_utils.exec)(element, parent);
|
|
30
30
|
let { extend, props, context, __ref } = element;
|
|
31
31
|
const COMPONENTS = context && context.components || options.components;
|
|
32
|
-
if ((0, import_utils.isString)(extend))
|
|
32
|
+
if ((0, import_utils.isString)(extend) && COMPONENTS)
|
|
33
33
|
extend = COMPONENTS[extend];
|
|
34
34
|
const extendStack = (0, import_utils2.getExtendStack)(extend);
|
|
35
35
|
if (ENV !== "test" || ENV !== "development")
|
|
@@ -25,61 +25,65 @@ __export(iterate_exports, {
|
|
|
25
25
|
});
|
|
26
26
|
module.exports = __toCommonJS(iterate_exports);
|
|
27
27
|
var import_utils = require("@domql/utils");
|
|
28
|
-
var import_utils2 = require("
|
|
28
|
+
var import_utils2 = require("./utils");
|
|
29
29
|
var import_methods = require("@domql/methods");
|
|
30
|
-
const throughInitialExec = (element) => {
|
|
31
|
-
const { __ref } = element;
|
|
32
|
-
const { __exec } = __ref;
|
|
30
|
+
const throughInitialExec = (element, exclude = {}) => {
|
|
31
|
+
const { __ref: ref } = element;
|
|
33
32
|
for (const param in element) {
|
|
33
|
+
if (exclude[param])
|
|
34
|
+
continue;
|
|
34
35
|
const prop = element[param];
|
|
35
36
|
if ((0, import_utils.isFunction)(prop) && !(0, import_methods.isMethod)(param)) {
|
|
36
|
-
__exec[param] = prop;
|
|
37
|
+
ref.__exec[param] = prop;
|
|
37
38
|
element[param] = prop(element, element.state);
|
|
38
39
|
}
|
|
39
40
|
}
|
|
40
41
|
};
|
|
41
|
-
const throughUpdatedExec = (element, options) => {
|
|
42
|
-
const { __ref } = element;
|
|
43
|
-
const { __exec, __cached } = __ref;
|
|
42
|
+
const throughUpdatedExec = (element, options = { excludes: import_utils2.METHODS_EXL }) => {
|
|
43
|
+
const { __ref: ref } = element;
|
|
44
44
|
const changes = {};
|
|
45
|
-
for (const param in __exec) {
|
|
45
|
+
for (const param in ref.__exec) {
|
|
46
46
|
const prop = element[param];
|
|
47
|
-
const
|
|
48
|
-
if (
|
|
47
|
+
const isDefinedParam = ref.__defineCache[param];
|
|
48
|
+
if (isDefinedParam)
|
|
49
|
+
continue;
|
|
50
|
+
const newExec = ref.__exec[param](element, element.state);
|
|
51
|
+
const execReturnsString = (0, import_utils.isString)(newExec) || (0, import_utils.isNumber)(newExec);
|
|
52
|
+
if (prop && prop.node && execReturnsString) {
|
|
49
53
|
(0, import_utils2.overwrite)(prop, { text: newExec }, options);
|
|
50
54
|
} else if (newExec !== prop) {
|
|
51
|
-
__cached[param] = changes[param] = prop;
|
|
55
|
+
ref.__cached[param] = changes[param] = prop;
|
|
52
56
|
element[param] = newExec;
|
|
53
57
|
}
|
|
54
58
|
}
|
|
55
59
|
return changes;
|
|
56
60
|
};
|
|
57
61
|
const throughInitialDefine = (element) => {
|
|
58
|
-
const { define, context, __ref } = element;
|
|
59
|
-
|
|
60
|
-
|
|
62
|
+
const { define, context, __ref: ref } = element;
|
|
63
|
+
let defineObj = {};
|
|
64
|
+
const hasGlobalDefine = context && (0, import_utils.isObject)(context.define);
|
|
61
65
|
if ((0, import_utils.isObject)(define))
|
|
62
|
-
|
|
63
|
-
if (
|
|
64
|
-
|
|
65
|
-
for (const param in
|
|
66
|
-
let
|
|
67
|
-
if ((0, import_utils.isFunction)(
|
|
68
|
-
__exec[param] =
|
|
69
|
-
const execParam2 =
|
|
70
|
-
if (execParam2)
|
|
71
|
-
element[param] = execParam2;
|
|
66
|
+
defineObj = { ...define };
|
|
67
|
+
if (hasGlobalDefine)
|
|
68
|
+
defineObj = { ...defineObj, ...context.define };
|
|
69
|
+
for (const param in defineObj) {
|
|
70
|
+
let elementProp = element[param];
|
|
71
|
+
if ((0, import_utils.isFunction)(elementProp) && !(0, import_methods.isMethod)(param)) {
|
|
72
|
+
ref.__exec[param] = elementProp;
|
|
73
|
+
const execParam2 = elementProp = (0, import_utils.exec)(elementProp, element);
|
|
74
|
+
if (execParam2) {
|
|
75
|
+
elementProp = element[param] = execParam2.parse ? execParam2.parse() : execParam2;
|
|
76
|
+
ref.__defineCache[param] = elementProp;
|
|
77
|
+
}
|
|
72
78
|
}
|
|
73
|
-
|
|
74
|
-
const execParam = obj[param](prop, element, element.state);
|
|
79
|
+
const execParam = defineObj[param](elementProp, element, element.state);
|
|
75
80
|
if (execParam)
|
|
76
81
|
element[param] = execParam;
|
|
77
82
|
}
|
|
78
83
|
return element;
|
|
79
84
|
};
|
|
80
85
|
const throughUpdatedDefine = (element) => {
|
|
81
|
-
const { context, define, __ref } = element;
|
|
82
|
-
const { __exec, __cached } = __ref;
|
|
86
|
+
const { context, define, __ref: ref } = element;
|
|
83
87
|
const changes = {};
|
|
84
88
|
let obj = {};
|
|
85
89
|
if ((0, import_utils.isObject)(define))
|
|
@@ -87,10 +91,10 @@ const throughUpdatedDefine = (element) => {
|
|
|
87
91
|
if ((0, import_utils.isObject)(context && context.define))
|
|
88
92
|
obj = { ...obj, ...context.define };
|
|
89
93
|
for (const param in obj) {
|
|
90
|
-
const execParam = __exec[param];
|
|
94
|
+
const execParam = ref.__exec[param];
|
|
91
95
|
if (execParam)
|
|
92
|
-
|
|
93
|
-
const cached = (0, import_utils.exec)(
|
|
96
|
+
ref.__defineCache[param] = execParam(element, element.state);
|
|
97
|
+
const cached = (0, import_utils.exec)(ref.__defineCache[param], element);
|
|
94
98
|
const newExecParam = obj[param](cached, element, element.state);
|
|
95
99
|
if (newExecParam)
|
|
96
100
|
element[param] = newExecParam;
|
|
@@ -58,7 +58,7 @@ const parse = function(excl = []) {
|
|
|
58
58
|
if (v === "state") {
|
|
59
59
|
if (element.__ref && element.__ref.__hasRootState)
|
|
60
60
|
return;
|
|
61
|
-
if ((0, import_utils.isFunction)(val
|
|
61
|
+
if ((0, import_utils.isFunction)(val && val.parse))
|
|
62
62
|
val = val.parse();
|
|
63
63
|
} else if (v === "props") {
|
|
64
64
|
const { __element, update: update2, ...props } = element[v];
|
package/dist/cjs/element/node.js
CHANGED
|
@@ -38,24 +38,24 @@ var import_mixins = require("./mixins");
|
|
|
38
38
|
var import_applyParam = require("./applyParam");
|
|
39
39
|
const ENV = "development";
|
|
40
40
|
const createNode = (element, options) => {
|
|
41
|
-
let { node, tag, __ref } = element;
|
|
41
|
+
let { node, tag, __ref: ref } = element;
|
|
42
42
|
let isNewNode;
|
|
43
43
|
if (!node) {
|
|
44
44
|
isNewNode = true;
|
|
45
|
-
if (!
|
|
45
|
+
if (!ref.__if)
|
|
46
46
|
return element;
|
|
47
47
|
if (tag === "shadow") {
|
|
48
48
|
node = element.node = element.parent.node.attachShadow({ mode: "open" });
|
|
49
49
|
} else
|
|
50
50
|
node = element.node = (0, import_node.cacheNode)(element);
|
|
51
|
-
(0, import_event.triggerEventOn)("attachNode", element);
|
|
51
|
+
(0, import_event.triggerEventOn)("attachNode", element, options);
|
|
52
52
|
}
|
|
53
53
|
if (ENV === "test" || ENV === "development" || options.alowRefReference) {
|
|
54
54
|
node.ref = element;
|
|
55
55
|
if ((0, import_utils.isFunction)(node.setAttribute))
|
|
56
56
|
node.setAttribute("key", element.key);
|
|
57
57
|
}
|
|
58
|
-
if (!
|
|
58
|
+
if (!ref.__if)
|
|
59
59
|
return element;
|
|
60
60
|
if (element.tag !== "string" || element.tag !== "fragment") {
|
|
61
61
|
(0, import_iterate.throughInitialDefine)(element);
|
|
@@ -32,13 +32,14 @@ var import_utils = require("@domql/utils");
|
|
|
32
32
|
var import_event = require("@domql/event");
|
|
33
33
|
var import_methods = require("@domql/methods");
|
|
34
34
|
var import_key = require("@domql/key");
|
|
35
|
-
var
|
|
35
|
+
var import_props = require("@domql/props");
|
|
36
|
+
var import_state = require("@domql/state");
|
|
37
|
+
var import_utils2 = require("./utils");
|
|
36
38
|
var import_create = __toESM(require("./create"));
|
|
37
39
|
var import_iterate = require("./iterate");
|
|
38
40
|
var import_mixins = require("./mixins");
|
|
39
|
-
var import_props = require("./props");
|
|
40
|
-
var import_state = __toESM(require("./state"));
|
|
41
41
|
var import_applyParam = require("./applyParam");
|
|
42
|
+
var import_options = __toESM(require("./options"));
|
|
42
43
|
const snapshot = {
|
|
43
44
|
snapshotId: import_key.createSnapshotId
|
|
44
45
|
};
|
|
@@ -47,46 +48,53 @@ const UPDATE_DEFAULT_OPTIONS = {
|
|
|
47
48
|
cleanExec: true,
|
|
48
49
|
preventRecursive: false,
|
|
49
50
|
currentSnapshot: false,
|
|
50
|
-
calleeElement: false
|
|
51
|
+
calleeElement: false,
|
|
52
|
+
excludes: import_utils2.METHODS_EXL
|
|
51
53
|
};
|
|
52
54
|
const update = function(params = {}, options = UPDATE_DEFAULT_OPTIONS) {
|
|
53
55
|
const element = this;
|
|
54
56
|
const { parent, node, key } = element;
|
|
55
|
-
|
|
56
|
-
if (
|
|
57
|
-
|
|
57
|
+
const { excludes, preventInheritAtCurrentState } = options;
|
|
58
|
+
if (preventInheritAtCurrentState && preventInheritAtCurrentState.__element === element)
|
|
59
|
+
return;
|
|
60
|
+
if (!excludes)
|
|
61
|
+
(0, import_utils.merge)(options, UPDATE_DEFAULT_OPTIONS);
|
|
62
|
+
let ref = element.__ref;
|
|
63
|
+
if (!ref)
|
|
64
|
+
ref = element.__ref = {};
|
|
58
65
|
const [snapshotOnCallee, calleeElement, snapshotHasUpdated] = captureSnapshot(element, options);
|
|
59
66
|
if (snapshotHasUpdated)
|
|
60
67
|
return;
|
|
61
68
|
if ((0, import_utils.isString)(params) || (0, import_utils.isNumber)(params)) {
|
|
62
69
|
params = { text: params };
|
|
63
70
|
}
|
|
64
|
-
const ifFails = checkIfOnUpdate(element, options);
|
|
71
|
+
const ifFails = checkIfOnUpdate(element, parent, options);
|
|
65
72
|
if (ifFails)
|
|
66
73
|
return;
|
|
67
74
|
const inheritState = inheritStateUpdates(element, options);
|
|
68
75
|
if (inheritState === false)
|
|
69
76
|
return;
|
|
70
|
-
if (
|
|
77
|
+
if (ref.__if && !options.preventPropsUpdate) {
|
|
71
78
|
const hasParentProps = parent.props && (parent.props[key] || parent.props.childProps);
|
|
72
|
-
const hasFunctionInProps =
|
|
79
|
+
const hasFunctionInProps = ref.__props.filter((v) => (0, import_utils.isFunction)(v));
|
|
73
80
|
const props = params.props || hasParentProps || hasFunctionInProps.length;
|
|
74
81
|
if (props)
|
|
75
82
|
(0, import_props.updateProps)(props, element, parent);
|
|
76
83
|
}
|
|
77
84
|
if (!options.preventInitUpdateListener) {
|
|
78
|
-
const initUpdateReturns = (0, import_event.
|
|
85
|
+
const initUpdateReturns = (0, import_event.triggerEventOnUpdate)("initUpdate", params, element, options);
|
|
79
86
|
if (initUpdateReturns === false)
|
|
80
87
|
return element;
|
|
81
88
|
}
|
|
82
|
-
|
|
83
|
-
const
|
|
89
|
+
(0, import_event.triggerEventOn)("beforeClassAssign", element, options);
|
|
90
|
+
const overwriteChanges = (0, import_utils.overwriteDeep)(element, params, import_utils2.METHODS_EXL);
|
|
91
|
+
const execChanges = (0, import_iterate.throughUpdatedExec)(element, { ignore: UPDATE_DEFAULT_OPTIONS });
|
|
84
92
|
const definedChanges = (0, import_iterate.throughUpdatedDefine)(element);
|
|
85
93
|
if (options.stackChanges && element.__stackChanges) {
|
|
86
|
-
const stackChanges = (0,
|
|
94
|
+
const stackChanges = (0, import_utils.merge)(definedChanges, (0, import_utils.merge)(execChanges, overwriteChanges));
|
|
87
95
|
element.__stackChanges.push(stackChanges);
|
|
88
96
|
}
|
|
89
|
-
if (!
|
|
97
|
+
if (!ref.__if)
|
|
90
98
|
return false;
|
|
91
99
|
if (!node) {
|
|
92
100
|
return;
|
|
@@ -115,41 +123,41 @@ const update = function(params = {}, options = UPDATE_DEFAULT_OPTIONS) {
|
|
|
115
123
|
}
|
|
116
124
|
}
|
|
117
125
|
if (!options.preventUpdateListener)
|
|
118
|
-
(0, import_event.triggerEventOn)("update", element);
|
|
126
|
+
(0, import_event.triggerEventOn)("update", element, options);
|
|
119
127
|
};
|
|
120
128
|
const captureSnapshot = (element, options) => {
|
|
121
|
-
const
|
|
129
|
+
const ref = element.__ref;
|
|
122
130
|
const { currentSnapshot, calleeElement } = options;
|
|
123
131
|
const isCallee = calleeElement === element;
|
|
124
132
|
if (!calleeElement || isCallee) {
|
|
125
133
|
const createdStanpshot = snapshot.snapshotId();
|
|
126
|
-
|
|
134
|
+
ref.__currentSnapshot = createdStanpshot;
|
|
127
135
|
return [createdStanpshot, element];
|
|
128
136
|
}
|
|
129
|
-
const snapshotOnCallee =
|
|
137
|
+
const snapshotOnCallee = ref.__currentSnapshot;
|
|
130
138
|
if (currentSnapshot < snapshotOnCallee) {
|
|
131
139
|
return [snapshotOnCallee, calleeElement, true];
|
|
132
140
|
}
|
|
133
141
|
return [snapshotOnCallee, calleeElement];
|
|
134
142
|
};
|
|
135
|
-
const checkIfOnUpdate = (element, options) => {
|
|
143
|
+
const checkIfOnUpdate = (element, parent, options) => {
|
|
136
144
|
if (!(0, import_utils.isFunction)(element.if))
|
|
137
145
|
return;
|
|
138
|
-
const
|
|
139
|
-
const ifPassed = element.if(element, element.state);
|
|
140
|
-
const itWasFalse =
|
|
146
|
+
const ref = element.__ref;
|
|
147
|
+
const ifPassed = element.if(element, element.state, element.context);
|
|
148
|
+
const itWasFalse = ref.__if !== true;
|
|
141
149
|
if (ifPassed) {
|
|
142
|
-
|
|
150
|
+
ref.__if = true;
|
|
143
151
|
if (itWasFalse) {
|
|
144
152
|
delete element.__hash;
|
|
145
153
|
delete element.extend;
|
|
146
|
-
if (!
|
|
154
|
+
if (!ref.__hasRootState) {
|
|
147
155
|
delete element.state;
|
|
148
156
|
}
|
|
149
|
-
if (
|
|
150
|
-
element.state =
|
|
157
|
+
if (ref.__state) {
|
|
158
|
+
element.state = ref.__state;
|
|
151
159
|
}
|
|
152
|
-
const created = (0, import_create.default)(element,
|
|
160
|
+
const created = (0, import_create.default)(element, parent, element.key, import_options.default.create);
|
|
153
161
|
if (!options.preventUpdate && element.on && (0, import_utils.isFunction)(element.on.update)) {
|
|
154
162
|
(0, import_event.applyEvent)(element.on.update, created, created.state);
|
|
155
163
|
}
|
|
@@ -157,26 +165,52 @@ const checkIfOnUpdate = (element, options) => {
|
|
|
157
165
|
}
|
|
158
166
|
} else if (element.node && !ifPassed) {
|
|
159
167
|
element.node.remove();
|
|
160
|
-
delete
|
|
168
|
+
delete ref.__if;
|
|
161
169
|
}
|
|
162
170
|
};
|
|
163
171
|
const inheritStateUpdates = (element, options) => {
|
|
164
|
-
const { __ref } = element;
|
|
165
|
-
const stateKey =
|
|
166
|
-
const { parent } = element;
|
|
167
|
-
if (
|
|
168
|
-
|
|
172
|
+
const { __ref: ref } = element;
|
|
173
|
+
const stateKey = ref.__state;
|
|
174
|
+
const { parent, state } = element;
|
|
175
|
+
if (options.preventpdateTriggerStateUpdate)
|
|
176
|
+
return;
|
|
177
|
+
if (!stateKey && !ref.__hasRootState) {
|
|
178
|
+
element.state = parent && parent.state || {};
|
|
169
179
|
return;
|
|
170
180
|
}
|
|
171
|
-
const
|
|
181
|
+
const { isHoisted, execStateFunction, stateFunctionOverwrite } = options;
|
|
182
|
+
const shouldForceStateUpdate = (0, import_utils.isFunction)(stateKey) && (!isHoisted && execStateFunction && stateFunctionOverwrite);
|
|
183
|
+
if (shouldForceStateUpdate) {
|
|
184
|
+
const execState = (0, import_utils.exec)(stateKey, element);
|
|
185
|
+
state.set(execState, {
|
|
186
|
+
...options,
|
|
187
|
+
preventUpdate: true
|
|
188
|
+
});
|
|
189
|
+
return;
|
|
190
|
+
}
|
|
191
|
+
const parentState = parent && parent.state || {};
|
|
172
192
|
const keyInParentState = parentState[stateKey];
|
|
173
|
-
if (!keyInParentState)
|
|
193
|
+
if (!keyInParentState || options.preventInheritedStateUpdate)
|
|
174
194
|
return;
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
195
|
+
if (!options.preventInitStateUpdateListener) {
|
|
196
|
+
const initStateReturns = (0, import_event.triggerEventOnUpdate)("initStateUpdated", keyInParentState, element, options);
|
|
197
|
+
if (initStateReturns === false)
|
|
198
|
+
return element;
|
|
199
|
+
}
|
|
200
|
+
const newState = createStateUpdate(element, parent, options);
|
|
201
|
+
if (!options.preventStateUpdateListener) {
|
|
202
|
+
(0, import_event.triggerEventOnUpdate)("stateUpdated", newState.parse(), element, options);
|
|
203
|
+
}
|
|
204
|
+
};
|
|
205
|
+
const createStateUpdate = (element, parent, options) => {
|
|
206
|
+
const __stateChildren = element.state.__children;
|
|
207
|
+
const newState = (0, import_state.createState)(element, parent);
|
|
179
208
|
element.state = newState;
|
|
180
|
-
|
|
209
|
+
for (const child in __stateChildren) {
|
|
210
|
+
if (newState[child])
|
|
211
|
+
newState.__children[child] = __stateChildren[child];
|
|
212
|
+
__stateChildren[child].parent = newState;
|
|
213
|
+
}
|
|
214
|
+
return newState;
|
|
181
215
|
};
|
|
182
216
|
var update_default = update;
|