Skip to content
This repository has been archived by the owner on Feb 26, 2024. It is now read-only.

fix bug add event listener to xhrhttprequest multiple times #528

Closed
wants to merge 30 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
767f5ef
fix long-stack-trace zone will not render correctly when reject a pro…
JiaLiPassion Aug 17, 2016
1db3876
Merge https://github.com/angular/zone.js
JiaLiPassion Nov 4, 2016
da482b9
fix issue #484 and #491, patch EventEmitter.once and removeAllListeners
JiaLiPassion Nov 9, 2016
4dabc6f
add event emitter once test case
JiaLiPassion Nov 9, 2016
46533fa
prependlistener should add listener at the beginning of the listener …
JiaLiPassion Nov 16, 2016
c4ec5f1
Merge https://github.com/angular/zone.js
JiaLiPassion Nov 16, 2016
2fcaeef
use newest fetch to test
JiaLiPassion Nov 16, 2016
58ee705
Merge remote-tracking branch 'upstream/master'
JiaLiPassion Nov 16, 2016
c5486f8
patch process.nextTick
JiaLiPassion Nov 21, 2016
c832dd6
Merge remote-tracking branch 'upstream/master'
JiaLiPassion Nov 21, 2016
508b3cf
restore ZoneAwareError captureStackTrace function
JiaLiPassion Nov 23, 2016
7c2a616
move captureStackTrace test into node
JiaLiPassion Nov 23, 2016
39644e5
use hasOwnProperty for check captureStackTrace exist or not
JiaLiPassion Nov 23, 2016
058c6a7
change var to const
JiaLiPassion Nov 23, 2016
3f3335f
add process.spec.ts into node_tests.ts target
JiaLiPassion Nov 23, 2016
6938214
add done in process.spec.ts
JiaLiPassion Nov 23, 2016
8046b67
change var to let
JiaLiPassion Nov 23, 2016
285e4c0
add nexttick order case
JiaLiPassion Nov 23, 2016
bedb768
add prepareStackTrace callback to ZoneAwareError
JiaLiPassion Nov 23, 2016
1d3e3d4
fix when EventEmitter removeAllListeners has no event type parameter,…
JiaLiPassion Nov 24, 2016
e011fd3
change some var to let/const, remove unnecessary cancelTask call
JiaLiPassion Nov 25, 2016
5462fcb
modify testcases
JiaLiPassion Nov 25, 2016
44a17fc
remove typo
JiaLiPassion Nov 25, 2016
300b965
use zone.scheduleMicrotask to patch process.nextTick
JiaLiPassion Nov 25, 2016
d55139f
forget use let/const again
JiaLiPassion Nov 25, 2016
4762e65
Merge remote-tracking branch 'upstream/master'
JiaLiPassion Nov 25, 2016
12dd13d
add comment to removeAllListeners patch, and remove useCapturing para…
JiaLiPassion Nov 27, 2016
c9a18c5
update fetch to 2.0.1
JiaLiPassion Dec 5, 2016
a65881c
Merge branch 'master' of https://github.com/angular/zone.js
JiaLiPassion Dec 6, 2016
cab6d64
fix bug add event listener to xhrhttprequest multiple times #527
JiaLiPassion Dec 6, 2016
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
12 changes: 10 additions & 2 deletions lib/browser/browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ patchXHR(_global);

const XHR_TASK = zoneSymbol('xhrTask');
const XHR_SYNC = zoneSymbol('xhrSync');
const XHR_LISTENER = zoneSymbol('xhrListener');

interface XHROptions extends TaskData {
target: any;
Expand All @@ -63,13 +64,20 @@ function patchXHR(window: any) {

function scheduleTask(task: Task) {
var data = <XHROptions>task.data;
data.target.addEventListener('readystatechange', () => {
// remove existing event listener
var listener = data.target[XHR_LISTENER];
if (listener) {
data.target.removeEventListener('readystatechange', listener);
}
var newListener = data.target[XHR_LISTENER] = () => {
if (data.target.readyState === data.target.DONE) {
if (!data.aborted) {
task.invoke();
}
}
});
};
data.target.addEventListener('readystatechange', newListener);

var storedTask: Task = data.target[XHR_TASK];
if (!storedTask) {
data.target[XHR_TASK] = task;
Expand Down
12 changes: 12 additions & 0 deletions test/browser/XMLHttpRequest.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,4 +182,16 @@ describe('XMLHttpRequest', function() {
expect(XMLHttpRequest.LOADING).toEqual(3);
expect(XMLHttpRequest.DONE).toEqual(4);
});

it('should work properly when send request multiple times on single xmlRequest instance', function() {
testZone.run(function() {
var req = new XMLHttpRequest();
req.open('get', '/', true);
req.send();
req.onloadend = function() {
req.open('get', '/', true);
req.send();
}
});
})
});