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/render.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;
|
|
@@ -936,27 +899,6 @@ function applyProps(el, newProps, oldProps, isSvg) {
|
|
|
936
899
|
}
|
|
937
900
|
}
|
|
938
901
|
function setProp(el, key, value, isSvg) {
|
|
939
|
-
if (!isSafeUrlAttributeValue(key, value)) {
|
|
940
|
-
if (typeof console !== "undefined") {
|
|
941
|
-
console.warn(`[what] Blocked unsafe URL in "${key}" attribute: ${value}`);
|
|
942
|
-
}
|
|
943
|
-
el.removeAttribute(getDomAttributeName(key));
|
|
944
|
-
return;
|
|
945
|
-
}
|
|
946
|
-
if (typeof value === "function" && !(key.startsWith("on") && key.length > 2) && key !== "ref") {
|
|
947
|
-
if (!el._propEffects) el._propEffects = {};
|
|
948
|
-
if (el._propEffects[key]) {
|
|
949
|
-
try {
|
|
950
|
-
el._propEffects[key]();
|
|
951
|
-
} catch (e) {
|
|
952
|
-
}
|
|
953
|
-
}
|
|
954
|
-
el._propEffects[key] = effect(() => {
|
|
955
|
-
const resolved = value();
|
|
956
|
-
setProp(el, key, resolved, isSvg);
|
|
957
|
-
});
|
|
958
|
-
return;
|
|
959
|
-
}
|
|
960
902
|
if (key.startsWith("on") && key.length > 2) {
|
|
961
903
|
let eventName = key.slice(2);
|
|
962
904
|
let useCapture = false;
|
|
@@ -981,6 +923,32 @@ function setProp(el, key, value, isSvg) {
|
|
|
981
923
|
el.addEventListener(event, wrappedHandler, eventOpts || useCapture || void 0);
|
|
982
924
|
return;
|
|
983
925
|
}
|
|
926
|
+
if (key === "ref") {
|
|
927
|
+
if (typeof value === "function") value(el);
|
|
928
|
+
else if (value) value.current = el;
|
|
929
|
+
return;
|
|
930
|
+
}
|
|
931
|
+
if (!isSafeUrlAttributeValue(key, value)) {
|
|
932
|
+
if (typeof console !== "undefined") {
|
|
933
|
+
console.warn(`[what] Blocked unsafe URL in "${key}" attribute: ${value}`);
|
|
934
|
+
}
|
|
935
|
+
el.removeAttribute(getDomAttributeName(key));
|
|
936
|
+
return;
|
|
937
|
+
}
|
|
938
|
+
if (typeof value === "function") {
|
|
939
|
+
if (!el._propEffects) el._propEffects = {};
|
|
940
|
+
if (el._propEffects[key]) {
|
|
941
|
+
try {
|
|
942
|
+
el._propEffects[key]();
|
|
943
|
+
} catch (e) {
|
|
944
|
+
}
|
|
945
|
+
}
|
|
946
|
+
el._propEffects[key] = effect(() => {
|
|
947
|
+
const resolved = value();
|
|
948
|
+
setProp(el, key, resolved, isSvg);
|
|
949
|
+
});
|
|
950
|
+
return;
|
|
951
|
+
}
|
|
984
952
|
if (key === "className" || key === "class") {
|
|
985
953
|
if (isSvg) {
|
|
986
954
|
el.setAttribute("class", value || "");
|