diff --git a/index.html b/index.html index d361c2f..00cdd51 100644 --- a/index.html +++ b/index.html @@ -7,8 +7,9 @@ diff --git a/playground/components/Article.ts b/playground/components/Article.ts index a263308..949fb1c 100644 --- a/playground/components/Article.ts +++ b/playground/components/Article.ts @@ -1,5 +1,5 @@ import { html } from "@f-stack/reflow"; -import { Counter } from "../pages/reactivity/1-state-and-derived/Counter.ts"; +import { Counter } from "./Counter.ts"; export const Article = (props: { title: string }) => { return html` diff --git a/playground/pages/reactivity/1-state-and-derived/Counter.ts b/playground/components/Counter.ts similarity index 100% rename from playground/pages/reactivity/1-state-and-derived/Counter.ts rename to playground/components/Counter.ts diff --git a/playground/components/Hi.ts b/playground/components/Hi.ts deleted file mode 100644 index 8bbde53..0000000 --- a/playground/components/Hi.ts +++ /dev/null @@ -1,7 +0,0 @@ -import { html } from "@f-stack/reflow"; - -export const Hi = () => { - return html` -
Hi
- `; -}; diff --git a/playground/pages/reactivity/2-cleanup/Cleanup.ts b/playground/pages/reactivity/Cleanup.ts similarity index 100% rename from playground/pages/reactivity/2-cleanup/Cleanup.ts rename to playground/pages/reactivity/Cleanup.ts diff --git a/playground/pages/reactivity/objects/ObjectPage.ts b/playground/pages/reactivity/ObjectPage.ts similarity index 100% rename from playground/pages/reactivity/objects/ObjectPage.ts rename to playground/pages/reactivity/ObjectPage.ts diff --git a/playground/pages/reactivity/3-shared-state/SharedState.ts b/playground/pages/reactivity/SharedState.ts similarity index 54% rename from playground/pages/reactivity/3-shared-state/SharedState.ts rename to playground/pages/reactivity/SharedState.ts index ca8a7c5..d6bb57a 100644 --- a/playground/pages/reactivity/3-shared-state/SharedState.ts +++ b/playground/pages/reactivity/SharedState.ts @@ -1,14 +1,14 @@ -import { derived, reactive } from "@f-stack/functorial"; +import { reactive } from "@f-stack/functorial"; import { html, on } from "@f-stack/reflow"; -const state = reactive({ - count: 0, +const count = reactive({ + value: 0, }); export const Counter = () => { return html` - `; }; diff --git a/playground/pages/reactivity/writable-derived/WritableDerived.ts b/playground/pages/reactivity/WritableDerived.ts similarity index 100% rename from playground/pages/reactivity/writable-derived/WritableDerived.ts rename to playground/pages/reactivity/WritableDerived.ts diff --git a/playground/pages/sinks/Attach.ts b/playground/pages/sinks/Attach.ts index e96f705..412ffb1 100644 --- a/playground/pages/sinks/Attach.ts +++ b/playground/pages/sinks/Attach.ts @@ -1,65 +1,48 @@ -import { listen, reactive } from "@f-stack/functorial"; -import { attach, attr, html, on, show } from "@f-stack/reflow"; +import { reactive } from "@f-stack/functorial"; +import { attach, attr, component, html, on, show } from "@f-stack/reflow"; export const AttachPage = () => { - const form = reactive({ value: "Bob" }); - const color = reactive({ value: "#40E0D0" }); - const display = reactive({ value: true }); + const state = reactive({ color: "#40E0D0", show: true }); return html` -
- - -
-
({ input: function () { - color.value = this.value; + state.color = this.value; }, })}> - +
- ${show(() => display.value, () => - html` - { - const context = canvas.getContext("2d"); + ${show( + () => state.show, + component(function () { + return html` + { + const context = canvas.getContext("2d"); - if (context) { - const draw = (color: string) => { - context.fillStyle = color; - context.fillRect(0, 0, 200, 200); - }; + if (context) { + const draw = (color: string) => { + context.fillStyle = color; + context.fillRect(0, 0, 200, 200); + }; - draw(color.value); + draw(state.color); - listen(color, (e) => { - console.log(e); - if (e.type !== "update") return; - draw(e.newValue); - }); - } - }, - )}>Enable JS - `)} + this.listen(state, (e) => { + console.log(e); + if (e.type !== "update") return; + draw(e.newValue); + }); + } + }, + )}>Enable JS + `; + }), + )}