mirror of
https://github.com/react/react-native-devtools-frontend.git
synced 2026-10-06 12:01:40 +08:00
R=szuend@chromium.org Bug: 1222126 Change-Id: Ie434053809b20f2309a4f771dd1137887bedf62b Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/3342106 Auto-Submit: Tim Van der Lippe <tvanderlippe@chromium.org> Reviewed-by: Simon Zünd <szuend@chromium.org> Commit-Queue: Simon Zünd <szuend@chromium.org>
52 lines
1.6 KiB
TypeScript
52 lines
1.6 KiB
TypeScript
// Copyright 2021 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 '../../core/common/common.js';
|
|
import type * as Protocol from '../../generated/protocol.js';
|
|
|
|
import type {Issue} from './Issue.js';
|
|
import {IssuesManager, Events as IssueManagerEvents} from './IssuesManager.js';
|
|
import type {IssueAddedEvent} from './IssuesManager.js';
|
|
|
|
/**
|
|
* A class that facilitates resolving an issueId to an issue. See `ResolverBase` for more info.
|
|
*/
|
|
export class IssueResolver extends Common.ResolverBase.ResolverBase<Protocol.Audits.IssueId, Issue> {
|
|
#issuesListener: Common.EventTarget.EventDescriptor|null = null;
|
|
#issuesManager: IssuesManager;
|
|
|
|
constructor(issuesManager: IssuesManager = IssuesManager.instance()) {
|
|
super();
|
|
this.#issuesManager = issuesManager;
|
|
}
|
|
|
|
protected override getForId(id: Protocol.Audits.IssueId): Issue|null {
|
|
return this.#issuesManager.getIssueById(id) || null;
|
|
}
|
|
|
|
#onIssueAdded(event: Common.EventTarget.EventTargetEvent<IssueAddedEvent>): void {
|
|
const {issue} = event.data;
|
|
const id = issue.getIssueId();
|
|
if (id) {
|
|
this.onResolve(id, issue);
|
|
}
|
|
}
|
|
|
|
protected override startListening(): void {
|
|
if (this.#issuesListener) {
|
|
return;
|
|
}
|
|
this.#issuesListener =
|
|
this.#issuesManager.addEventListener(IssueManagerEvents.IssueAdded, this.#onIssueAdded, this);
|
|
}
|
|
|
|
protected override stopListening(): void {
|
|
if (!this.#issuesListener) {
|
|
return;
|
|
}
|
|
Common.EventTarget.removeEventListeners([this.#issuesListener]);
|
|
this.#issuesListener = null;
|
|
}
|
|
}
|