[ide-react] Only call scope watcher with the latest value from each batch (#16296)

GitOrigin-RevId: 0284f99130424d50a2115853d793979a2b0387ff
This commit is contained in:
Alf Eaton 2023-12-20 11:48:05 +00:00 committed by Copybot
parent fe206936ac
commit 7cb427738c
2 changed files with 6 additions and 5 deletions

View file

@ -71,7 +71,7 @@ const EditorNavigationToolbarRoot = React.memo(
eventTracking.sendMB('navigation-clicked-chat', {
action: isOpentoString(!chatIsOpen),
})
setChatIsOpen(value => !value)
setChatIsOpen(!chatIsOpen)
}, [chatIsOpen, setChatIsOpen, markMessagesAsRead])
const toggleReviewPanelOpen = useCallback(

View file

@ -60,7 +60,7 @@ export class ReactScopeValueStore implements ScopeValueStore {
private readonly items = new Map<string, ScopeValueStoreValue>()
private readonly persisters: Map<string, Persister> = new Map()
private watcherUpdates: WatcherUpdate[] = []
private watcherUpdates = new Map<string, WatcherUpdate>()
private watcherUpdateTimer: number | null = null
private allowedNonExistentPaths: AllowedNonExistentPath[] = []
@ -129,8 +129,8 @@ export class ReactScopeValueStore implements ScopeValueStore {
this.watcherUpdateTimer = null
}
// Clone watcherUpdates in case a watcher creates new watcherUpdates
const watcherUpdates = [...this.watcherUpdates]
this.watcherUpdates = []
const watcherUpdates = [...this.watcherUpdates.values()]
this.watcherUpdates = new Map()
for (const { value, watchers } of watcherUpdates) {
for (const watcher of watchers) {
if (!watcher.removed) {
@ -152,7 +152,7 @@ export class ReactScopeValueStore implements ScopeValueStore {
path,
watchers: [...watchers],
}
this.watcherUpdates.push(update)
this.watcherUpdates.set(path, update)
if (!this.watcherUpdateTimer) {
this.watcherUpdateTimer = window.setTimeout(() => {
this.watcherUpdateTimer = null
@ -166,6 +166,7 @@ export class ReactScopeValueStore implements ScopeValueStore {
}
private setValue<T>(path: string, value: T): void {
debugConsole.log('setValue', path, value)
let item = this.items.get(path)
if (item === undefined) {
item = { value, watchers: [] }