source dump of claude code
at main 25 lines 946 B view raw
1import { useCallback, useEffect } from 'react' 2import { settingsChangeDetector } from '../utils/settings/changeDetector.js' 3import type { SettingSource } from '../utils/settings/constants.js' 4import { getSettings_DEPRECATED } from '../utils/settings/settings.js' 5import type { SettingsJson } from '../utils/settings/types.js' 6 7export function useSettingsChange( 8 onChange: (source: SettingSource, settings: SettingsJson) => void, 9): void { 10 const handleChange = useCallback( 11 (source: SettingSource) => { 12 // Cache is already reset by the notifier (changeDetector.fanOut) — 13 // resetting here caused N-way thrashing with N subscribers: each 14 // cleared the cache, re-read from disk, then the next cleared again. 15 const newSettings = getSettings_DEPRECATED() 16 onChange(source, newSettings) 17 }, 18 [onChange], 19 ) 20 21 useEffect( 22 () => settingsChangeDetector.subscribe(handleChange), 23 [handleChange], 24 ) 25}