Просмотр исходного кода

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

GitOrigin-RevId: 0284f99130424d50a2115853d793979a2b0387ff
Alf Eaton 2 лет назад
Родитель
Сommit
7cb427738c

+ 1 - 1
services/web/frontend/js/features/editor-navigation-toolbar/components/editor-navigation-toolbar-root.jsx

@@ -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(

+ 5 - 4
services/web/frontend/js/features/ide-react/scope-value-store/react-scope-value-store.ts

@@ -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: [] }