refactor: consolidate all events in Events.js (#3772)

This will allow us to break all dependency cycles that were forcing
us to put many things in a single file (e.g. ExecutionContext and
ElementHandle).
This commit is contained in:
Andrey Lushnikov
2019-01-14 19:57:05 -08:00
committed by GitHub
parent 71edfc779b
commit 4e9e3bc614
17 changed files with 181 additions and 151 deletions

View File

@@ -15,6 +15,7 @@
*/
const EventEmitter = require('events');
const {helper, assert, debugError} = require('./helper');
const {Events} = require('./Events');
const Multimap = require('./Multimap');
class NetworkManager extends EventEmitter {
@@ -206,7 +207,7 @@ class NetworkManager extends EventEmitter {
const frame = event.frameId && this._frameManager ? this._frameManager.frame(event.frameId) : null;
const request = new Request(this._client, frame, interceptionId, this._userRequestInterceptionEnabled, event, redirectChain);
this._requestIdToRequest.set(event.requestId, request);
this.emit(NetworkManager.Events.Request, request);
this.emit(Events.NetworkManager.Request, request);
}
@@ -230,8 +231,8 @@ class NetworkManager extends EventEmitter {
response._bodyLoadedPromiseFulfill.call(null, new Error('Response body is unavailable for redirect responses'));
this._requestIdToRequest.delete(request._requestId);
this._attemptedAuthentications.delete(request._interceptionId);
this.emit(NetworkManager.Events.Response, response);
this.emit(NetworkManager.Events.RequestFinished, request);
this.emit(Events.NetworkManager.Response, response);
this.emit(Events.NetworkManager.RequestFinished, request);
}
/**
@@ -244,7 +245,7 @@ class NetworkManager extends EventEmitter {
return;
const response = new Response(this._client, request, event.response);
request._response = response;
this.emit(NetworkManager.Events.Response, response);
this.emit(Events.NetworkManager.Response, response);
}
/**
@@ -263,7 +264,7 @@ class NetworkManager extends EventEmitter {
request.response()._bodyLoadedPromiseFulfill.call(null);
this._requestIdToRequest.delete(request._requestId);
this._attemptedAuthentications.delete(request._interceptionId);
this.emit(NetworkManager.Events.RequestFinished, request);
this.emit(Events.NetworkManager.RequestFinished, request);
}
/**
@@ -281,7 +282,7 @@ class NetworkManager extends EventEmitter {
response._bodyLoadedPromiseFulfill.call(null);
this._requestIdToRequest.delete(request._requestId);
this._attemptedAuthentications.delete(request._interceptionId);
this.emit(NetworkManager.Events.RequestFailed, request);
this.emit(Events.NetworkManager.RequestFailed, request);
}
}
@@ -732,13 +733,6 @@ class SecurityDetails {
}
}
NetworkManager.Events = {
Request: 'request',
Response: 'response',
RequestFailed: 'requestfailed',
RequestFinished: 'requestfinished',
};
const statusTexts = {
'100': 'Continue',
'101': 'Switching Protocols',