@davidcal/frosth 1.1.0 → 1.2.0
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/README.md +1 -1
- package/package.json +1 -1
- package/src/h.js +2 -1
- package/src/mount_checks.js +30 -0
- package/src/render.js +1 -0
package/README.md
CHANGED
package/package.json
CHANGED
package/src/h.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { create_fragment } from "./create_fragment.js";
|
|
2
|
+
import { outstanding_mount_checks } from "./mount_checks.js";
|
|
2
3
|
import { render } from "./render.js";
|
|
3
4
|
|
|
4
5
|
export const h = (s, tag, props, children) => {
|
|
@@ -38,7 +39,7 @@ export const h = (s, tag, props, children) => {
|
|
|
38
39
|
if (when === "on_create") {
|
|
39
40
|
ref_set(() => el);
|
|
40
41
|
} else if (when === "on_mount") {
|
|
41
|
-
|
|
42
|
+
outstanding_mount_checks.set(el, () => ref_set(() => el));
|
|
42
43
|
} else {
|
|
43
44
|
throw new Error(`[Frosth] Invalid ref strategy "${when}"`);
|
|
44
45
|
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
export const outstanding_mount_checks = new Map();
|
|
2
|
+
|
|
3
|
+
const mutation_observer = new MutationObserver((mutations) => {
|
|
4
|
+
for (const mutation of mutations) {
|
|
5
|
+
for (const node of mutation.addedNodes) {
|
|
6
|
+
if (!outstanding_mount_checks.has(node)) {
|
|
7
|
+
continue;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
outstanding_mount_checks.get(node)();
|
|
11
|
+
outstanding_mount_checks.delete(node);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
if (typeof document !== "undefined") {
|
|
17
|
+
mutation_observer.observe(document, {
|
|
18
|
+
childList: true,
|
|
19
|
+
subtree: true,
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
setInterval(() => {
|
|
24
|
+
if (outstanding_mount_checks.size === 0) {
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
console.warn(`[Frosth] One or more (${outstanding_mount_checks.size}) element(s) were created but not mounted. At least one \`ref: ["on_mount", ...]\` was never fired as a result.`);
|
|
29
|
+
outstanding_mount_checks.clear();
|
|
30
|
+
}, 0);
|