MCPcopy Create free account
hub / github.com/TanStack/hotkeys / createHotkeyRecorder

Function createHotkeyRecorder

packages/solid-hotkeys/src/createHotkeyRecorder.ts:61–103  ·  view source on GitHub ↗
(
  options: HotkeyRecorderOptions | (() => HotkeyRecorderOptions),
)

Source from the content-addressed store, hash-verified

59 * ```
60 */
61export function createHotkeyRecorder(
62 options: HotkeyRecorderOptions | (() => HotkeyRecorderOptions),
63): SolidHotkeyRecorder {
64 const defaultOptions = useDefaultHotkeysOptions()
65
66 const resolvedOptions = typeof options === 'function' ? options() : options
67 const mergedOptions = {
68 ...defaultOptions.hotkeyRecorder,
69 ...resolvedOptions,
70 } as HotkeyRecorderOptions
71
72 // Create recorder once synchronously (matches React's useRef pattern)
73 const recorder = new HotkeyRecorder(mergedOptions)
74
75 // Subscribe to recorder state using useSelector (same pattern as useHotkeyRecorder)
76 const isRecording = useSelector(recorder.store, (state) => state.isRecording)
77 const recordedHotkey = useSelector(
78 recorder.store,
79 (state) => state.recordedHotkey,
80 )
81
82 // Sync options on every effect run (matches React's sync on render)
83 createEffect(() => {
84 const resolved = typeof options === 'function' ? options() : options
85 recorder.setOptions({
86 ...defaultOptions.hotkeyRecorder,
87 ...resolved,
88 } as HotkeyRecorderOptions)
89 })
90
91 // Cleanup on unmount
92 onCleanup(() => {
93 recorder.destroy()
94 })
95
96 return {
97 isRecording,
98 recordedHotkey,
99 startRecording: () => recorder.start(),
100 stopRecording: () => recorder.stop(),
101 cancelRecording: () => recorder.cancel(),
102 }
103}

Callers 1

AppFunction · 0.90

Calls 6

setOptionsMethod · 0.95
destroyMethod · 0.95
startMethod · 0.95
stopMethod · 0.95
cancelMethod · 0.95
useDefaultHotkeysOptionsFunction · 0.90

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…