Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
abhishiv authored Jul 2, 2024
1 parent eb7c9a4 commit 76394d3
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,23 +42,24 @@

```tsx
/** @jsx h **/

import { component, h, render } from "alfama";

const Page = component<{ name: string }>(
"HomePage",
(props, { signal, wire }) => {
const $count = signal("count", 0);
const $doubleCount = wire(($) => $count($) * 2); // explicit subscription
// 1) The signal/wire/store functions are passed as a param to
// component definition
const Page = component("HomePage", (props, { signal, wire, store }) => {

// 2) Name signals for rock solid HMR
const $count = signal("count", 0);

// 3) Most importantly: wire reactivity to signals
// with explicit subscription using the $ token param
// Easy to reason about and no untrack/sample related errors
const $doubleCount = wire(($) => $count($) * 2);
return (
<div id="home">
<p>Hey, {props.name}</p>
<button
onClick={() => {
$count($count() + 1);
}}
>
Increment to {wire($count)}
<button onClick={() => $count($count() + 1)}>
Increment / {wire($count)}
</button>
<p>Double count = {$doubleCount}</p>
</div>
Expand Down

0 comments on commit 76394d3

Please sign in to comment.