Replies: 10 comments
-
StateEcho.render(
X.span()((t) => t.text),
Echo.reactive().state("text", "hello world"),
); Echo.render(
X.div()(
X.button({$click: (t) => t.value++})("👍"),
X.button({$click: (t) => t.value--})("👎"),
X.span()((t) => t.value),
),
Echo.reactive().state("value", 0),
); Echo.render(
X.fragment()(
X.p()("Original message: ", (t) => t.message),
X.p()("Computed reversed message: ", (t) => t.reversed),
),
Echo.reactive()
.state("message", "hello")
.computed("reversed", (t) => t.message.split("").reverse().join("")),
); |
Beta Was this translation helpful? Give feedback.
-
BindingsEcho.render(
X.span()((t) => t.text),
Echo.reactive().state("text", "hello world"),
); Echo.render(
X.button({disabled: (t) => t.disabled})("Button"),
Echo.reactive().state("disabled", true),
); Echo.render(
X.span({style: (t) => `background: ${t.background}; font-size: 20px`})("Hello World"),
Echo.reactive().state("background", "steelblue"),
); |
Beta Was this translation helpful? Give feedback.
-
List renderingEcho.render(
X.ul()(
Echo.For({each: (t) => t.items})(
X.li()((item) => item.$index + "-" + item.message),
),
),
Echo.reactive().state("items", () => [{message: "Foo"}, {message: "Bar"}]),
); Echo.render(
X.ul()(
Echo.For({each: (t) => t.items})(
X.li()(
X.span()((item) => item.$index + "-" + item.message),
Echo.For({each: (item) => item.tags})(
X.span()((tag) => tag)
),
),
),
),
Echo.reactive().state("items", () => [
{message: "Foo", tags: ["A", "B", "C"]},
{message: "Bar", tags: ["B", "C", "D"]},
]),
); |
Beta Was this translation helpful? Give feedback.
-
Conditional RenderingEcho.render(
X.div()(
Echo.Match()(
Echo.Arm({test: (d) => d.random > 0.5})(X.div()("A")),
Echo.Arm({test: (d) => d.random > 0.3})(X.div()("B")),
Echo.Arm()(X.div()("C")),
),
),
Echo.reactive().state("random", () => Math.random()),
); Echo.render(
X.div()(
Echo.Match({value: (d) => d.name})(
Echo.Arm({test: "A"})(X.div()("a")),
Echo.Arm({test: "B"})(X.div()("b")),
Echo.Arm()(X.div()("c")),
),
),
Echo.reactive()
.state("random", () => Math.random())
.computed("name", (d) => (d.random > 0.5 ? "A" : d.random > 0.3 ? "B" : "C")),
); Echo.render(
X.div()(
Echo.Match({test: (d) => d.random > 0.5})(
X.div()("A"),
X.div()("B"),
),
),
Echo.reactive().state("random", () => Math.random()),
); |
Beta Was this translation helpful? Give feedback.
-
EventsEcho.render(
X.fragment()(
X.button({$click: (t) => t.value++})("👍"),
X.button({$click: (t) => t.value--})("👎"),
X.span()((t) => t.value),
),
Echo.reactive().state("value", 0),
); |
Beta Was this translation helpful? Give feedback.
-
Refs & EffectsEcho.render(
X.span({ref: "span"})("Hello World"),
Echo.reactive()
.ref("span", null)
.effect((t) => (t.span.style.color = "#ececec")),
); |
Beta Was this translation helpful? Give feedback.
-
Componentsconst Label = Echo.component(
X.span({style: (t) => `font-size: 20px; color: ${t.color}`})(
(t) => t.children,
),
Echo.reactive().prop("color"),
) Echo.render(
Label({color: (t) => t.color})("hello world"),
Echo.reactive().state("color", "red"),
); |
Beta Was this translation helpful? Give feedback.
-
MethodsEcho.render(
X.div()(
X.button({$click: (t) => t.increment()})("👍"),
X.button({$click: (t) => t.decrement()})("👎"),
X.span()((t) => t.value),
),
Echo.reactive().state("value", 0),
); |
Beta Was this translation helpful? Give feedback.
-
Compositionconst useMouse = Echo.reactive()
.state("x", 0)
.state("y", 0)
.effect((t) => {
const mousemove = (e) => ((t.x = e.clientX), (t.y = e.clientY));
document.addEventListener("mousemove", mousemove);
return () => document.removeEventListener("mousemove", mousemove);
});
Echo.render(
X.span()(
"X: ",
(t) => t.mouse.x,
", Y: ",
(t) => t.mouse.y,
),
Echo.reactive().trait("mouse", () => useMouse()),
); |
Beta Was this translation helpful? Give feedback.
-
Slotsconst Layout = Echo.component(
X.div()(
X.header()(Echo.Slot({name: "header"})),
X.body()(Echo.Slot({name: "body"})),
X.footer()(Echo.Slot({name: "footer"})),
),
Echo.reactive().prop("header").prop("body").prop("footer"),
);
Echo.render(
Layout({
header: X.span()("Header"),
body: X.span()("Body"),
footer: X.span()("Footer"),
}),
); |
Beta Was this translation helpful? Give feedback.
-
Overview
UI = f(template, reactive)
For more out of the box usage and simpler scenario:
Beta Was this translation helpful? Give feedback.
All reactions