mirror of
https://github.com/react/react-native-devtools-frontend.git
synced 2026-10-13 01:54:52 +08:00
This CL introduces a new type for the "IssuesManager.IssueAdded" event. Using the new type-safe event infrastructure, all consumers of IssuesManager events are now type-safe. Bug: 1228674 Change-Id: I3e015fb3c44f26510fb78c385508a338bde741d5 Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/2978378 Commit-Queue: Simon Zünd <szuend@chromium.org> Reviewed-by: Tim van der Lippe <tvanderlippe@chromium.org>
51 lines
1.7 KiB
TypeScript
51 lines
1.7 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> {
|
|
private issuesListener: Common.EventTarget.EventDescriptor|null = null;
|
|
private issuesManager: IssuesManager;
|
|
|
|
constructor(issuesManager: IssuesManager = IssuesManager.instance()) {
|
|
super();
|
|
this.issuesManager = issuesManager;
|
|
}
|
|
|
|
protected override getForId(id: Protocol.Network.RequestId): Issue|null {
|
|
return this.issuesManager.getIssueById(id) || null;
|
|
}
|
|
|
|
private 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;
|
|
}
|
|
}
|