Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Map inspector requests by id so single requests can be reset at a time #26770

Merged
merged 1 commit into from
Dec 7, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 17 additions & 4 deletions src/ui/public/inspector/adapters/request/request_adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
*/

import { EventEmitter } from 'events';
import _ from 'lodash';
import uuid from 'uuid/v4';
import { RequestResponder } from './request_responder';
import { Request, RequestParams, RequestStatus } from './types';

Expand All @@ -29,7 +31,12 @@ import { Request, RequestParams, RequestStatus } from './types';
* @extends EventEmitter
*/
class RequestAdapter extends EventEmitter {
private requests: Request[] = [];
private requests: Map<string, Request>;

constructor() {
super();
this.requests = new Map();
}

/**
* Start logging a new request into this request adapter. The new request will
Expand All @@ -47,19 +54,25 @@ class RequestAdapter extends EventEmitter {
name,
startTime: Date.now(),
status: RequestStatus.PENDING,
id: _.get(params, 'id', uuid()),
};
this.requests.push(req);
this.requests.set(req.id, req);
this._onChange();
return new RequestResponder(req, () => this._onChange());
}

public reset(): void {
this.requests = [];
this.requests = new Map();
this._onChange();
}

public resetRequest(id: string): void {
this.requests.delete(id);
this._onChange();
}

public getRequests(): Request[] {
return this.requests;
return Array.from(this.requests.values());
}

private _onChange(): void {
Expand Down
2 changes: 2 additions & 0 deletions src/ui/public/inspector/adapters/request/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export enum RequestStatus {
}

export interface Request extends RequestParams {
id: string;
name: string;
json?: object;
response?: Response;
Expand All @@ -46,6 +47,7 @@ export interface Request extends RequestParams {
}

export interface RequestParams {
id?: string;
description?: string;
}

Expand Down