Skip to content

Commit

Permalink
WIP: Update counter.
Browse files Browse the repository at this point in the history
  • Loading branch information
dgp1130 committed Dec 20, 2023
1 parent b610241 commit 914f41b
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/demo/auto-counter.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import { component } from 'hydroactive';
import { cached, signal } from 'hydroactive/signals.js';

/** Automatically increments the count over time. */
export const AutoCounter = component('auto-counter', (comp) => {
const count = comp.live('span', Number);
const label = comp.host.query('span');
const count = signal(Number(label.text));
const doubleCount = cached(() => count() * 2);

comp.connected(() => {
const id = setInterval(() => {
Expand All @@ -13,4 +16,9 @@ export const AutoCounter = component('auto-counter', (comp) => {
clearInterval(id);
};
});

comp.effect(() => {
label.native.textContent = count().toString();
console.log(`Double count: ${doubleCount()}`);
});
});

0 comments on commit 914f41b

Please sign in to comment.