Skip to content

Commit ca4767d

Browse files
committed
breaking(TimerState): Rename onTick to tick
1 parent f7b36c2 commit ca4767d

3 files changed

Lines changed: 13 additions & 8 deletions

File tree

.changeset/light-mice-brake.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@layerstack/svelte-state': patch
3+
---
4+
5+
breaking(TimerState): Rename `onTick` to `tick`

packages/svelte-state/src/lib/timerState.svelte.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export type TimerOptions<T> = {
1212
disabled?: boolean;
1313

1414
/** Called on each interval tick. Returned value is used to update store value, defaulting to current Date */
15-
onTick?: (current: T | null) => any;
15+
tick?: (current: T | null) => any;
1616
};
1717

1818
/**
@@ -25,14 +25,14 @@ export class TimerState<T = any> {
2525
#delay: number;
2626
#disabled: boolean;
2727
#running = $state(false);
28-
#onTick: (current: T | null) => any;
28+
#tick: (current: T | null) => any;
2929

3030
constructor(options: TimerOptions<T> = {}) {
3131
this.#initial = options.initial ?? null;
3232
this.#current = this.#initial;
3333
this.#delay = options.delay ?? 1000;
3434
this.#disabled = options.disabled ?? false;
35-
this.#onTick = options.onTick ?? (() => new Date());
35+
this.#tick = options.tick ?? (() => new Date());
3636

3737
if (!this.#disabled) {
3838
this.start();
@@ -68,7 +68,7 @@ export class TimerState<T = any> {
6868
start = () => {
6969
stop();
7070
this.#intervalId = setInterval(() => {
71-
this.#current = this.#onTick(this.#current) ?? new Date();
71+
this.#current = this.#tick(this.#current) ?? new Date();
7272
}, this.#delay);
7373
this.#running = true;
7474
};

sites/docs/src/routes/docs/svelte-state/TimerState/+page.svelte

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,16 @@
55
import Preview from '$docs/Preview.svelte';
66
import Code from '$docs/Code.svelte';
77
8-
const dateTimer = new TimerState({ initial: new Date(), onTick: () => new Date() });
9-
const tickTimer = new TimerState({ initial: 0, onTick: (value) => (value ?? 0) + 1 });
8+
const dateTimer = new TimerState({ initial: new Date() });
9+
const tickTimer = new TimerState({ initial: 0, tick: (value) => (value ?? 0) + 1 });
1010
</script>
1111

1212
<h1>Usage</h1>
1313

1414
<Code source={`const timer = new TimerState();`} language="javascript" />
1515

1616
<Code
17-
source={`const timer = new TimerState<T>({ initial?: T, onTick?: (value: T) => {...}, delay?: number, disabled?: boolean })`}
17+
source={`const timer = new TimerState<T>({ initial?: T, tick?: (value: T) => {...}, delay?: number, disabled?: boolean })`}
1818
language="javascript"
1919
/>
2020

@@ -38,7 +38,7 @@
3838
<h2>Tick count</h2>
3939

4040
<Code
41-
source={`const tickTimer = new TimerState({ initial: 0, onTick: (value) => value + 1 });`}
41+
source={`const tickTimer = new TimerState({ initial: 0, tick: (value) => value + 1 });`}
4242
language="javascript"
4343
/>
4444

0 commit comments

Comments
 (0)