Commit f5009cb0 authored by John Emau's avatar John Emau Committed by Commit Bot

DevTools: skip audio context selector empty list state with _items.replace

Problem:
When a web audio context change event occurs the "changed to" context is
first removed from the context selector list then added back.

If the list only contains 1 items then the list contents goes 1 -> 0 -> 1
and the event listener AudioContextSelector._onListItemReplaced will
intermediately disable the context menu during the change event when the
empty state list is reached.

This can cause side-effects and is extra cycles we don't need to spend.

Solution:
The UI.ListModel.replace method does the same operation without the intermediary
empty list state.

Change-Id: Ide76e2281c6c7224c22e77f3e7a5766fb2ef0a24
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1823730
Commit-Queue: John Emau <John.Emau@microsoft.com>
Reviewed-by: default avatarYang Guo <yangguo@chromium.org>
Reviewed-by: default avatarMandy Chen <mandy.chen@microsoft.com>
Cr-Commit-Position: refs/heads/master@{#704856}
parent 8d5aede3
......@@ -61,8 +61,7 @@ WebAudio.AudioContextSelector = class extends Common.Object {
const changedContext = /** @type {!Protocol.WebAudio.BaseAudioContext} */ (event.data);
const contextIndex = this._items.findIndex(context => context.contextId === changedContext.contextId);
if (contextIndex > -1) {
this._items.remove(contextIndex);
this._items.insert(contextIndex, changedContext);
this._items.replace(contextIndex, changedContext);
// If the changed context is currently selected by user. Re-select it
// because the actual element is replaced with a new one.
......
......@@ -62,7 +62,6 @@ Selected Context: {
Running: testOnListItemReplacedCalled
_onListItemReplaced called with contexts (items) count: 1
_onListItemReplaced called with contexts (items) count: 0
_onListItemReplaced called with contexts (items) count: 1
Number of contexts (items): 1
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment