@davidcal/frosth 1.0.0 → 1.0.2
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 +14 -0
- package/package.json +1 -1
- package/src/create_fragment.js +16 -1
- package/src/create_self.js +4 -0
- package/src/h.js +0 -6
- package/src/render.js +11 -3
package/README.md
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# Frosth - Yet another UI framework
|
|
2
2
|
|
|
3
|
+
**Latest version**: v1.0.2
|
|
4
|
+
|
|
3
5
|
## Motivation
|
|
4
6
|
|
|
5
7
|
Frontend component frameworks are still a mess (controversial, I know).
|
|
@@ -261,3 +263,15 @@ const App = obtain(async ({ t, s }) => {
|
|
|
261
263
|
]);
|
|
262
264
|
});
|
|
263
265
|
```
|
|
266
|
+
|
|
267
|
+
Ensure to wrap children in an array if making it reactive, or alternatively pass in a component instance that is inherently reactive.
|
|
268
|
+
|
|
269
|
+
```
|
|
270
|
+
const my_text_constant = create_signal(() => "my text content");
|
|
271
|
+
|
|
272
|
+
installed.set(() => [
|
|
273
|
+
(s) => s.$h1({}, [
|
|
274
|
+
(s) => my_text_content(s),
|
|
275
|
+
]),
|
|
276
|
+
])
|
|
277
|
+
```
|
package/package.json
CHANGED
package/src/create_fragment.js
CHANGED
|
@@ -33,7 +33,22 @@ class Fragment {
|
|
|
33
33
|
|
|
34
34
|
set innerText(text) {
|
|
35
35
|
this.clear();
|
|
36
|
-
|
|
36
|
+
|
|
37
|
+
if (text === null || text === undefined) {
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
this.appendChild(document.createTextNode(String(text)));
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
set textContent(text) {
|
|
45
|
+
this.clear();
|
|
46
|
+
|
|
47
|
+
if (text === null || text === undefined) {
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
this.appendChild(document.createTextNode(String(text)));
|
|
37
52
|
}
|
|
38
53
|
}
|
|
39
54
|
|
package/src/create_self.js
CHANGED
package/src/h.js
CHANGED
package/src/render.js
CHANGED
|
@@ -20,11 +20,13 @@ const render_diff = (s, prev, next, target) => {
|
|
|
20
20
|
return prev_map.get(item);
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
-
const item_self =
|
|
23
|
+
const item_self = s._create_child();
|
|
24
24
|
const fragment = create_fragment(target);
|
|
25
25
|
const new_state = { prev: [] };
|
|
26
26
|
|
|
27
|
-
|
|
27
|
+
item_self.create_effect((s) => {
|
|
28
|
+
render(s._create_child(), fragment, item(s), new_state);
|
|
29
|
+
});
|
|
28
30
|
|
|
29
31
|
return { item, item_self, fragment, state: new_state };
|
|
30
32
|
});
|
|
@@ -33,7 +35,13 @@ const render_diff = (s, prev, next, target) => {
|
|
|
33
35
|
};
|
|
34
36
|
|
|
35
37
|
export const render = async (s, target, installed, state) => {
|
|
36
|
-
console.log("rendering", installed);
|
|
38
|
+
console.log("rendering", installed, typeof installed);
|
|
39
|
+
|
|
40
|
+
if (typeof installed === "string") {
|
|
41
|
+
target.textContent = installed;
|
|
42
|
+
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
37
45
|
|
|
38
46
|
if (Array.isArray(installed)) {
|
|
39
47
|
if (state.prev.length === 0) {
|