Fixed "Sending `didSendNetworkData` with no listeners registered" warning

Summary:
XMLHttpRequest was sending the request before registering any listeners, resulting in a warning from the native event emitter.

Since we weren't seeing widespread problems with XHR missing data, this was probably working OK in practice because the queuing of events meant that the listener would have been registered before the message was actually delivered.

Still, this was working more through luck than design. This diff fixes it by registering the listeners *before* sending the request.

Reviewed By: lexs

Differential Revision: D3371320

fbshipit-source-id: c688d4053a61f856eaacccd0106905edbefcc86a
This commit is contained in:
Nick Lockwood 2016-06-01 06:18:17 -07:00 committed by Facebook Github Bot 1
parent aa53770c25
commit bdcdfb03d4
1 changed files with 16 additions and 16 deletions

View File

@ -212,22 +212,6 @@ class XMLHttpRequest extends EventTarget(...XHR_EVENTS) {
// exposed for testing
__didCreateRequest(requestId: number): void {
this._requestId = requestId;
this._subscriptions.push(RCTNetworking.addListener(
'didSendNetworkData',
(args) => this.__didUploadProgress(...args)
));
this._subscriptions.push(RCTNetworking.addListener(
'didReceiveNetworkResponse',
(args) => this._didReceiveResponse(...args)
));
this._subscriptions.push(RCTNetworking.addListener(
'didReceiveNetworkData',
(args) => this._didReceiveData(...args)
));
this._subscriptions.push(RCTNetworking.addListener(
'didCompleteNetworkResponse',
(args) => this.__didCompleteResponse(...args)
));
}
// exposed for testing
@ -340,6 +324,22 @@ class XMLHttpRequest extends EventTarget(...XHR_EVENTS) {
useIncrementalUpdates: boolean,
timeout: number,
): void {
this._subscriptions.push(RCTNetworking.addListener(
'didSendNetworkData',
(args) => this.__didUploadProgress(...args)
));
this._subscriptions.push(RCTNetworking.addListener(
'didReceiveNetworkResponse',
(args) => this._didReceiveResponse(...args)
));
this._subscriptions.push(RCTNetworking.addListener(
'didReceiveNetworkData',
(args) => this._didReceiveData(...args)
));
this._subscriptions.push(RCTNetworking.addListener(
'didCompleteNetworkResponse',
(args) => this.__didCompleteResponse(...args)
));
RCTNetworking.sendRequest(
method,
url,