what-core 0.6.7 → 0.6.9
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/compiler.js +59 -91
- package/dist/compiler.js.map +3 -3
- package/dist/compiler.min.js +1 -1
- package/dist/compiler.min.js.map +3 -3
- package/dist/devtools.js.map +1 -1
- package/dist/devtools.min.js.map +1 -1
- package/dist/index.js +165 -91
- package/dist/index.js.map +3 -3
- package/dist/index.min.js +6 -6
- package/dist/index.min.js.map +3 -3
- package/dist/render.js +59 -91
- package/dist/render.js.map +3 -3
- package/dist/render.min.js +2 -2
- package/dist/render.min.js.map +3 -3
- package/dist/testing.js +59 -91
- package/dist/testing.js.map +3 -3
- package/dist/testing.min.js +1 -1
- package/dist/testing.min.js.map +3 -3
- package/hooks.d.ts +15 -14
- package/index.d.ts +3 -3
- package/package.json +2 -2
- package/src/dom.js +31 -22
- package/src/index.js +7 -3
- package/src/reactive.js +36 -59
package/dist/compiler.js
CHANGED
|
@@ -115,38 +115,11 @@ function _createEffect(fn, lazy) {
|
|
|
115
115
|
function _runEffect(e) {
|
|
116
116
|
if (e.disposed) return;
|
|
117
117
|
if (e._stable) {
|
|
118
|
-
|
|
119
|
-
try {
|
|
120
|
-
e._cleanup();
|
|
121
|
-
} catch (err) {
|
|
122
|
-
if (__DEV__) console.warn("[what] Error in effect cleanup:", err);
|
|
123
|
-
}
|
|
124
|
-
e._cleanup = null;
|
|
125
|
-
}
|
|
126
|
-
const prev2 = currentEffect;
|
|
127
|
-
currentEffect = null;
|
|
128
|
-
try {
|
|
129
|
-
const result = e.fn();
|
|
130
|
-
if (typeof result === "function") e._cleanup = result;
|
|
131
|
-
} catch (err) {
|
|
132
|
-
if (__devtools?.onError) __devtools.onError(err, { type: "effect", effect: e });
|
|
133
|
-
if (__DEV__) console.warn("[what] Error in stable effect:", err);
|
|
134
|
-
} finally {
|
|
135
|
-
currentEffect = prev2;
|
|
136
|
-
}
|
|
137
|
-
if (__DEV__ && __devtools?.onEffectRun) __devtools.onEffectRun(e);
|
|
118
|
+
runStableEffect(e);
|
|
138
119
|
return;
|
|
139
120
|
}
|
|
140
121
|
cleanup(e);
|
|
141
|
-
|
|
142
|
-
try {
|
|
143
|
-
e._cleanup();
|
|
144
|
-
} catch (err) {
|
|
145
|
-
if (__devtools?.onError) __devtools.onError(err, { type: "effect-cleanup", effect: e });
|
|
146
|
-
if (__DEV__) console.warn("[what] Error in effect cleanup:", err);
|
|
147
|
-
}
|
|
148
|
-
e._cleanup = null;
|
|
149
|
-
}
|
|
122
|
+
runEffectCleanup(e, "effect cleanup");
|
|
150
123
|
const prev = currentEffect;
|
|
151
124
|
currentEffect = e;
|
|
152
125
|
try {
|
|
@@ -167,14 +140,36 @@ function _disposeEffect(e) {
|
|
|
167
140
|
e.disposed = true;
|
|
168
141
|
if (__DEV__ && __devtools) __devtools.onEffectDispose(e);
|
|
169
142
|
cleanup(e);
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
143
|
+
runEffectCleanup(e, "effect cleanup on dispose");
|
|
144
|
+
}
|
|
145
|
+
function reportEffectCleanupError(err, e, phase) {
|
|
146
|
+
if (__devtools?.onError) __devtools.onError(err, { type: "effect-cleanup", effect: e, phase });
|
|
147
|
+
if (__DEV__) console.warn(`[what] Error in ${phase}:`, err);
|
|
148
|
+
}
|
|
149
|
+
function runEffectCleanup(e, phase) {
|
|
150
|
+
if (!e._cleanup) return;
|
|
151
|
+
const cleanupFn = e._cleanup;
|
|
152
|
+
e._cleanup = null;
|
|
153
|
+
try {
|
|
154
|
+
cleanupFn();
|
|
155
|
+
} catch (err) {
|
|
156
|
+
reportEffectCleanupError(err, e, phase);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
function runStableEffect(e) {
|
|
160
|
+
const prev = currentEffect;
|
|
161
|
+
currentEffect = null;
|
|
162
|
+
try {
|
|
163
|
+
runEffectCleanup(e, "stable effect cleanup");
|
|
164
|
+
const result = e.fn();
|
|
165
|
+
if (typeof result === "function") e._cleanup = result;
|
|
166
|
+
} catch (err) {
|
|
167
|
+
if (__devtools?.onError) __devtools.onError(err, { type: "effect", effect: e });
|
|
168
|
+
if (__DEV__) console.warn("[what] Error in stable effect:", err);
|
|
169
|
+
} finally {
|
|
170
|
+
currentEffect = prev;
|
|
177
171
|
}
|
|
172
|
+
if (__DEV__ && __devtools?.onEffectRun) __devtools.onEffectRun(e);
|
|
178
173
|
}
|
|
179
174
|
function cleanup(e) {
|
|
180
175
|
const deps = e.deps;
|
|
@@ -193,23 +188,7 @@ function notify(subs) {
|
|
|
193
188
|
if (e._onNotify) {
|
|
194
189
|
e._onNotify();
|
|
195
190
|
} else if (batchDepth === 0 && e._stable) {
|
|
196
|
-
|
|
197
|
-
currentEffect = null;
|
|
198
|
-
try {
|
|
199
|
-
const result = e.fn();
|
|
200
|
-
if (typeof result === "function") {
|
|
201
|
-
if (e._cleanup) try {
|
|
202
|
-
e._cleanup();
|
|
203
|
-
} catch (err) {
|
|
204
|
-
}
|
|
205
|
-
e._cleanup = result;
|
|
206
|
-
}
|
|
207
|
-
} catch (err) {
|
|
208
|
-
if (__devtools?.onError) __devtools.onError(err, { type: "effect", effect: e });
|
|
209
|
-
if (__DEV__) console.warn("[what] Error in stable effect:", err);
|
|
210
|
-
} finally {
|
|
211
|
-
currentEffect = prev;
|
|
212
|
-
}
|
|
191
|
+
runStableEffect(e);
|
|
213
192
|
} else if (!e._pending) {
|
|
214
193
|
e._pending = true;
|
|
215
194
|
const level = e._level;
|
|
@@ -231,23 +210,7 @@ function notify(subs) {
|
|
|
231
210
|
if (e._onNotify) {
|
|
232
211
|
e._onNotify();
|
|
233
212
|
} else if (batchDepth === 0 && e._stable) {
|
|
234
|
-
|
|
235
|
-
currentEffect = null;
|
|
236
|
-
try {
|
|
237
|
-
const result = e.fn();
|
|
238
|
-
if (typeof result === "function") {
|
|
239
|
-
if (e._cleanup) try {
|
|
240
|
-
e._cleanup();
|
|
241
|
-
} catch (err) {
|
|
242
|
-
}
|
|
243
|
-
e._cleanup = result;
|
|
244
|
-
}
|
|
245
|
-
} catch (err) {
|
|
246
|
-
if (__devtools?.onError) __devtools.onError(err, { type: "effect", effect: e });
|
|
247
|
-
if (__DEV__) console.warn("[what] Error in stable effect:", err);
|
|
248
|
-
} finally {
|
|
249
|
-
currentEffect = prev;
|
|
250
|
-
}
|
|
213
|
+
runStableEffect(e);
|
|
251
214
|
} else if (!e._pending) {
|
|
252
215
|
e._pending = true;
|
|
253
216
|
const level = e._level;
|
|
@@ -933,27 +896,6 @@ function applyProps(el, newProps, oldProps, isSvg) {
|
|
|
933
896
|
}
|
|
934
897
|
}
|
|
935
898
|
function setProp(el, key, value, isSvg) {
|
|
936
|
-
if (!isSafeUrlAttributeValue(key, value)) {
|
|
937
|
-
if (typeof console !== "undefined") {
|
|
938
|
-
console.warn(`[what] Blocked unsafe URL in "${key}" attribute: ${value}`);
|
|
939
|
-
}
|
|
940
|
-
el.removeAttribute(getDomAttributeName(key));
|
|
941
|
-
return;
|
|
942
|
-
}
|
|
943
|
-
if (typeof value === "function" && !(key.startsWith("on") && key.length > 2) && key !== "ref") {
|
|
944
|
-
if (!el._propEffects) el._propEffects = {};
|
|
945
|
-
if (el._propEffects[key]) {
|
|
946
|
-
try {
|
|
947
|
-
el._propEffects[key]();
|
|
948
|
-
} catch (e) {
|
|
949
|
-
}
|
|
950
|
-
}
|
|
951
|
-
el._propEffects[key] = effect(() => {
|
|
952
|
-
const resolved = value();
|
|
953
|
-
setProp(el, key, resolved, isSvg);
|
|
954
|
-
});
|
|
955
|
-
return;
|
|
956
|
-
}
|
|
957
899
|
if (key.startsWith("on") && key.length > 2) {
|
|
958
900
|
let eventName = key.slice(2);
|
|
959
901
|
let useCapture = false;
|
|
@@ -978,6 +920,32 @@ function setProp(el, key, value, isSvg) {
|
|
|
978
920
|
el.addEventListener(event, wrappedHandler, eventOpts || useCapture || void 0);
|
|
979
921
|
return;
|
|
980
922
|
}
|
|
923
|
+
if (key === "ref") {
|
|
924
|
+
if (typeof value === "function") value(el);
|
|
925
|
+
else if (value) value.current = el;
|
|
926
|
+
return;
|
|
927
|
+
}
|
|
928
|
+
if (!isSafeUrlAttributeValue(key, value)) {
|
|
929
|
+
if (typeof console !== "undefined") {
|
|
930
|
+
console.warn(`[what] Blocked unsafe URL in "${key}" attribute: ${value}`);
|
|
931
|
+
}
|
|
932
|
+
el.removeAttribute(getDomAttributeName(key));
|
|
933
|
+
return;
|
|
934
|
+
}
|
|
935
|
+
if (typeof value === "function") {
|
|
936
|
+
if (!el._propEffects) el._propEffects = {};
|
|
937
|
+
if (el._propEffects[key]) {
|
|
938
|
+
try {
|
|
939
|
+
el._propEffects[key]();
|
|
940
|
+
} catch (e) {
|
|
941
|
+
}
|
|
942
|
+
}
|
|
943
|
+
el._propEffects[key] = effect(() => {
|
|
944
|
+
const resolved = value();
|
|
945
|
+
setProp(el, key, resolved, isSvg);
|
|
946
|
+
});
|
|
947
|
+
return;
|
|
948
|
+
}
|
|
981
949
|
if (key === "className" || key === "class") {
|
|
982
950
|
if (isSvg) {
|
|
983
951
|
el.setAttribute("class", value || "");
|