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

@@ -14,6 +14,7 @@
* limitations under the License.
*/
const {helper, assert} = require('./helper');
const {Events} = require('./Events');
const debugProtocol = require('debug')('puppeteer:protocol');
const debugSession = require('debug')('puppeteer:session');
const EventEmitter = require('events');
@@ -120,7 +121,7 @@ class Connection extends EventEmitter {
for (const session of this._sessions.values())
session._onClosed();
this._sessions.clear();
this.emit(Connection.Events.Disconnected);
this.emit(Events.Connection.Disconnected);
}
dispose() {
@@ -140,10 +141,6 @@ class Connection extends EventEmitter {
}
}
Connection.Events = {
Disconnected: Symbol('Connection.Events.Disconnected'),
};
class CDPSession extends EventEmitter {
/**
* @param {!Connection|!CDPSession} connection
@@ -228,7 +225,7 @@ class CDPSession extends EventEmitter {
callback.reject(rewriteError(callback.error, `Protocol error (${callback.method}): Target closed.`));
this._callbacks.clear();
this._connection = null;
this.emit(CDPSession.Events.Disconnected);
this.emit(Events.CDPSession.Disconnected);
}
/**
@@ -242,10 +239,6 @@ class CDPSession extends EventEmitter {
}
}
CDPSession.Events = {
Disconnected: Symbol('CDPSession.Events.Disconnected'),
};
helper.tracePublicAPI(CDPSession);
/**