Skip to content

Commit

Permalink
It's too advanced to use computed-signals on the intro
Browse files Browse the repository at this point in the history
  • Loading branch information
nettyso committed Jul 21, 2021
1 parent 300a7ff commit 0c8a980
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,26 @@ import { signal, wire } from 'haptic/state';
import { when } from 'haptic/stdlib';

const state = signal({
text: '',
count: 0,
countNext: wire($ => state.count($) + 1),
});

const Page = () =>
<div>
<h1>"{wire(data.text)}"</h1>
<p>You've typed {wire($ => state.text().length)} characters</p>
<input
placeholder='Type here!'
value={wire(data.text)}
onChange={(ev) => data.text(ev.currentTarget.value)}
/>
<button onClick={state.count(state.count() + 1)}>
Increment to {wire(state.countNext)}
+1
</button>
<p>Content below changes when <code>state.count > 5</code></p>
<p>After {wire($ => 5 - state.count($))} clicks the content will change</p>
{when(wire($ => state.count($) > 5 ? "T" : "F"), {
T: () => <p>There have been more than 5 clicks</p>,
F: () => <p>Current click count is {wire(state.count)}</p>,
T: () => <strong>There are over 5 clicks!</strong>,
F: () => <p>Clicks: {wire(state.count)}</p>,
})}
</div>;

Expand Down

0 comments on commit 0c8a980

Please sign in to comment.