Skip to content

Commit

Permalink
Updated demo
Browse files Browse the repository at this point in the history
  • Loading branch information
Skaldebane committed Feb 16, 2024
1 parent 6f22bdf commit e720162
Showing 1 changed file with 26 additions and 6 deletions.
32 changes: 26 additions & 6 deletions src/routes/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,33 @@
<script lang="ts">
import { cleanable } from "$lib/index.js";
const parent = cleanable(0);
let logs: string[] = [];
const state = cleanable(0);
parent.subscribe((value) => {
console.log("parent changed", value);
return () => console.log(`cleaning up old parent ${value}...`);
state.subscribe((value) => {
log(`state = ${value}`);
return () => log(`cleaning up ${value}...`);
});
function log(msg: string) {
console.log(msg);
logs = [msg, ...logs];
}
function increment() {
logs = ["$state++", "", ...logs];
$state++;
}
</script>

<h1>Parent: {$parent}</h1>
<button on:click={() => $parent++}>Increment</button>
<h1>state = {$state}</h1>
<button on:click={increment}>Increment</button>
{#each logs as log}
<p class={log === "$state++" ? "highlighted" : ""}>{log}</p>
{/each}

<style>
.highlighted {
color: green;
}
</style>

0 comments on commit e720162

Please sign in to comment.