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 18, 2023
1 parent b75b99e commit d87726d
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/demo/auto-counter.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { component } from 'hydroactive';
import { signal } from 'hydroactive/signals.js';
import { cached, signal } from 'hydroactive/signals.js';

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

comp.connected(() => {
const id = setInterval(() => {
Expand All @@ -18,5 +19,6 @@ export const AutoCounter = component('auto-counter', (comp) => {

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

0 comments on commit d87726d

Please sign in to comment.