/** * A reactive counter demonstrating Svelte 5 rune detection in plain * `.svelte.ts` modules — `$state`, `$state.raw`, `$derived`, and * `$derived.by` initializers surface on the `reactivity` field. * @module */ /** A reactive counter built on Svelte 5 runes. */ export class Counter { /** Current count. */ count: number = $state(0); /** Past counts; replaced wholesale on change, so raw state. */ history: ReadonlyArray<number> = $state.raw([]); /** Double the current count. */ doubled: number = $derived(this.count * 2); /** Display label computed from several fields. */ label: string = $derived.by(() => `count: ${this.count} (doubled: ${this.doubled})`); /** * Increment the count, recording the previous value. * @param amount - how much to add * @mutates `this` */ increment(amount: number = 1): void { this.history = [...this.history, this.count]; this.count += amount; } }
{ "path": "counter.svelte.ts", "declarations": [ { "name": "Counter", "kind": "class", "docComment": "A reactive counter built on Svelte 5 runes.", "sourceLine": 9, "alsoExportedFrom": [ "index.ts" ], "members": [ { "name": "count", "kind": "variable", "docComment": "Current count.", "typeSignature": "number", "reactivity": "$state" }, { "name": "history", "kind": "variable", "docComment": "Past counts; replaced wholesale on change, so raw state.", "typeSignature": "ReadonlyArray<number>", "reactivity": "$state.raw" }, { "name": "doubled", "kind": "variable", "docComment": "Double the current count.", "typeSignature": "number", "reactivity": "$derived" }, { "name": "label", "kind": "variable", "docComment": "Display label computed from several fields.", "typeSignature": "string", "reactivity": "$derived.by" }, { "name": "increment", "kind": "function", "docComment": "Increment the count, recording the previous value.", "typeSignature": "(amount?: number): void", "parameters": [ { "name": "amount", "type": "number", "description": "how much to add", "defaultValue": "1" } ], "returnType": "void" } ] } ], "moduleComment": "A reactive counter demonstrating Svelte 5 rune detection in plain\n`.svelte.ts` modules — `$state`, `$state.raw`, `$derived`, and\n`$derived.by` initializers surface on the `reactivity` field.", "dependents": [ "index.ts" ] }