( onChange: (source: SettingSource, settings: SettingsJson) => void, )
| 5 | import type { SettingsJson } from '../utils/settings/types.js' |
| 6 | |
| 7 | export 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 | } |
| 26 |
no test coverage detected