forked from ultraworkers/claw-code
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuseSettingsChange.ts
More file actions
25 lines (23 loc) · 946 Bytes
/
Copy pathuseSettingsChange.ts
File metadata and controls
25 lines (23 loc) · 946 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import { useCallback, useEffect } from 'react'
import { settingsChangeDetector } from '../utils/settings/changeDetector.js'
import type { SettingSource } from '../utils/settings/constants.js'
import { getSettings_DEPRECATED } from '../utils/settings/settings.js'
import type { SettingsJson } from '../utils/settings/types.js'
export function useSettingsChange(
onChange: (source: SettingSource, settings: SettingsJson) => void,
): void {
const handleChange = useCallback(
(source: SettingSource) => {
// Cache is already reset by the notifier (changeDetector.fanOut) —
// resetting here caused N-way thrashing with N subscribers: each
// cleared the cache, re-read from disk, then the next cleared again.
const newSettings = getSettings_DEPRECATED()
onChange(source, newSettings)
},
[onChange],
)
useEffect(
() => settingsChangeDetector.subscribe(handleChange),
[handleChange],
)
}