-
-
Notifications
You must be signed in to change notification settings - Fork 38
Perf/hotkey recorder optimizations #48
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 3 commits
9b666cf
81415ae
c7a5b83
4d1f315
48da959
bfd855f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| '@tanstack/hotkeys': patch | ||
| --- | ||
|
|
||
| Remove redundant `setState` in `destroy()` and share a single `IDLE_STATE` constant across `stop()` and `cancel()` | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,6 +18,11 @@ export interface HotkeyRecorderState { | |
| recordedHotkey: Hotkey | null | ||
| } | ||
|
|
||
| /** | ||
| * Initial idle state for the recorder, used when not recording. | ||
| */ | ||
| const IDLE_STATE: HotkeyRecorderState = { isRecording: false, recordedHotkey: null } | ||
|
|
||
| /** | ||
| * Options for configuring a HotkeyRecorder instance. | ||
| */ | ||
|
|
@@ -74,10 +79,7 @@ export class HotkeyRecorder { | |
| * The TanStack Store instance containing the recorder state. | ||
| * Use this to subscribe to state changes or access current state. | ||
| */ | ||
| readonly store: Store<HotkeyRecorderState> = new Store<HotkeyRecorderState>({ | ||
| isRecording: false, | ||
| recordedHotkey: null, | ||
| }) | ||
| readonly store: Store<HotkeyRecorderState> = new Store<HotkeyRecorderState>(IDLE_STATE) | ||
|
|
||
| #keydownHandler: ((event: KeyboardEvent) => void) | null = null | ||
| #options: HotkeyRecorderOptions | ||
|
|
@@ -113,10 +115,7 @@ export class HotkeyRecorder { | |
| } | ||
|
|
||
| // Update store state | ||
| this.store.setState(() => ({ | ||
| isRecording: true, | ||
| recordedHotkey: null, | ||
| })) | ||
| this.store.setState(() => (IDLE_STATE)) | ||
|
||
|
|
||
| // Create keydown handler | ||
| const handler = (event: KeyboardEvent) => { | ||
|
|
@@ -172,10 +171,7 @@ export class HotkeyRecorder { | |
| } | ||
|
|
||
| // Update store state immediately | ||
| this.store.setState(() => ({ | ||
| isRecording: false, | ||
| recordedHotkey: finalHotkey, | ||
| })) | ||
| this.store.setState(() => (IDLE_STATE)) | ||
|
|
||
| // Call callback AFTER listener is removed and state is set | ||
| this.#options.onRecord(finalHotkey) | ||
|
Comment on lines
181
to
188
|
||
|
|
@@ -199,10 +195,7 @@ export class HotkeyRecorder { | |
| } | ||
|
|
||
| // Update store state | ||
| this.store.setState(() => ({ | ||
| isRecording: false, | ||
| recordedHotkey: null, | ||
| })) | ||
| this.store.setState(() => (IDLE_STATE)) | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -219,10 +212,7 @@ export class HotkeyRecorder { | |
| } | ||
|
|
||
| // Update store state | ||
| this.store.setState(() => ({ | ||
| isRecording: false, | ||
| recordedHotkey: null, | ||
| })) | ||
| this.store.setState(() => (IDLE_STATE)) | ||
|
|
||
| // Call cancel callback | ||
| this.#options.onCancel?.() | ||
|
|
@@ -258,9 +248,5 @@ export class HotkeyRecorder { | |
| */ | ||
| destroy(): void { | ||
| this.stop() | ||
| this.store.setState(() => ({ | ||
| isRecording: false, | ||
| recordedHotkey: null, | ||
| })) | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The changeset message says the shared
IDLE_STATEis used acrossstop()andcancel(), but the code also uses it instart()and on successful record, anddestroy()no longer directly sets state either. Please update the changeset text to accurately describe the shipped behavior so release notes are correct.