mirror of
https://github.com/overleaf/overleaf.git
synced 2025-04-23 03:06:24 +00:00
[ide-react] Only call scope watcher with the latest value from each batch (#16296)
GitOrigin-RevId: 0284f99130424d50a2115853d793979a2b0387ff
This commit is contained in:
parent
fe206936ac
commit
7cb427738c
2 changed files with 6 additions and 5 deletions
services/web/frontend/js/features
editor-navigation-toolbar/components
ide-react/scope-value-store
|
@ -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(
|
||||
|
|
|
@ -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: [] }
|
||||
|
|
Loading…
Add table
Reference in a new issue