mirror of
https://github.com/react/react-native-devtools-frontend.git
synced 2026-10-10 05:35:05 +08:00
Bug: chromium:1011811 Change-Id: Ie18a64b6cdf84e3d53e594cd88f7c4431d9c78f6 Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/2450294 Reviewed-by: Tim van der Lippe <tvanderlippe@chromium.org> Commit-Queue: Paul Lewis <aerotwist@chromium.org>
76 lines
2.2 KiB
JavaScript
76 lines
2.2 KiB
JavaScript
// Copyright 2019 The Chromium Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
// found in the LICENSE file.
|
|
|
|
import * as Common from '../../common/common.js'; // eslint-disable-line no-unused-vars
|
|
|
|
import {Events as ViewEvents, GraphView} from './GraphView.js';
|
|
|
|
// A class that maps each context to its corresponding graph.
|
|
// It controls which graph to render when the context is switched or updated.
|
|
export class GraphManager extends Common.ObjectWrapper.ObjectWrapper {
|
|
constructor() {
|
|
super();
|
|
|
|
/** @type {!Map<!Protocol.WebAudio.GraphObjectId, !GraphView>} */
|
|
this._graphMapByContextId = new Map();
|
|
}
|
|
|
|
/**
|
|
* @param {!Protocol.WebAudio.GraphObjectId} contextId
|
|
*/
|
|
createContext(contextId) {
|
|
const graph = new GraphView(contextId);
|
|
// When a graph has any update, request redraw.
|
|
graph.addEventListener(ViewEvents.ShouldRedraw, this._notifyShouldRedraw, this);
|
|
this._graphMapByContextId.set(contextId, graph);
|
|
}
|
|
|
|
/**
|
|
* @param {!Protocol.WebAudio.GraphObjectId} contextId
|
|
*/
|
|
destroyContext(contextId) {
|
|
if (!this._graphMapByContextId.has(contextId)) {
|
|
return;
|
|
}
|
|
|
|
const graph = this._graphMapByContextId.get(contextId);
|
|
if (!graph) {
|
|
return;
|
|
}
|
|
|
|
graph.removeEventListener(ViewEvents.ShouldRedraw, this._notifyShouldRedraw, this);
|
|
this._graphMapByContextId.delete(contextId);
|
|
}
|
|
|
|
/**
|
|
* @param {string} contextId
|
|
*/
|
|
hasContext(contextId) {
|
|
return this._graphMapByContextId.has(contextId);
|
|
}
|
|
|
|
clearGraphs() {
|
|
this._graphMapByContextId.clear();
|
|
}
|
|
|
|
/**
|
|
* Get graph by contextId.
|
|
* If the user starts listening for WebAudio events after the page has been running a context for awhile,
|
|
* the graph might be undefined.
|
|
* @param {!Protocol.WebAudio.GraphObjectId} contextId
|
|
* @return {?GraphView}
|
|
*/
|
|
getGraph(contextId) {
|
|
return this._graphMapByContextId.get(contextId) || null;
|
|
}
|
|
|
|
/**
|
|
* @param {!Common.EventTarget.EventTargetEvent} event
|
|
*/
|
|
_notifyShouldRedraw(event) {
|
|
const graph = /** @type {!GraphView} */ (event.data);
|
|
this.dispatchEventToListeners(ViewEvents.ShouldRedraw, graph);
|
|
}
|
|
}
|