@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 CHANGED
@@ -1,6 +1,6 @@
1
1
  # Frosth - Yet another UI framework
2
2
 
3
- **Latest version**: v1.1.0
3
+ **Latest version**: v1.2.0
4
4
 
5
5
  ## Motivation
6
6
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@davidcal/frosth",
3
- "version": "1.1.0",
3
+ "version": "1.2.0",
4
4
  "description": "Async-first CRUD-last UI framework that treats encapsulation as a solved problem.",
5
5
  "type": "module",
6
6
  "main": "./src/sigew.js",
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
- throw new Error("[Frosth] Ref \"on_mount\" strategy not yet implemented.");
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);
package/src/render.js CHANGED
@@ -100,6 +100,7 @@ export const render = async (s, target, installed, state) => {
100
100
  }
101
101
 
102
102
  target.innerHTML = "";
103
+
103
104
  const fragment = create_fragment(target);
104
105
 
105
106
  const new_state = { prev: [] };