Skip to content

Commit

Permalink
fix(facade): change EventEmitter to be sync by default (#8761)
Browse files Browse the repository at this point in the history
  • Loading branch information
robwormald authored and mhevery committed May 26, 2016
1 parent cf1122c commit e5904f4
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 36 deletions.
5 changes: 2 additions & 3 deletions modules/@angular/core/test/linker/integration_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1527,11 +1527,10 @@ function declareTests(isJit: boolean) {
tick();

var tc = fixture.debugElement.children[0];
tc.inject(DirectiveEmittingEvent).fireEvent("boom");


try {
tick();
throw "Should throw";
tc.inject(DirectiveEmittingEvent).fireEvent("boom");
} catch (e) {
clearPendingTimers();

Expand Down
2 changes: 1 addition & 1 deletion modules/@angular/facade/src/async.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ export class EventEmitter<T> extends Subject<T> {
* Creates an instance of [EventEmitter], which depending on [isAsync],
* delivers events synchronously or asynchronously.
*/
constructor(isAsync: boolean = true) {
constructor(isAsync: boolean = false) {
super();
this.__isAsync = isAsync;
}
Expand Down
37 changes: 20 additions & 17 deletions modules/@angular/facade/test/async_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,27 +46,27 @@ export function main() {
ObservableWrapper.callComplete(emitter);
}));

it("should subscribe to the wrapper asynchronously", () => {
it("should subscribe to the wrapper synchronously", () => {
var called = false;
ObservableWrapper.subscribe(emitter, (value) => { called = true; });

ObservableWrapper.callEmit(emitter, 99);
expect(called).toBe(false);
expect(called).toBe(true);
});

// Makes Edge to disconnect when running the full unit test campaign
// TODO: remove when issue is solved: https://github.com/angular/angular/issues/4756
if (!browserDetection.isEdge) {
it("delivers next and error events asynchronously", inject([AsyncTestCompleter], (async) => {
it("delivers next and error events synchronously", inject([AsyncTestCompleter], (async) => {
let log = [];
ObservableWrapper.subscribe(emitter,
(x) => {
log.push(x);
expect(log).toEqual([1, 3, 5, 2]);
expect(log).toEqual([1, 2]);
},
(err) => {
log.push(err);
expect(log).toEqual([1, 3, 5, 2, 4]);
expect(log).toEqual([1, 2, 3, 4]);
async.done();
});
log.push(1);
Expand All @@ -76,36 +76,39 @@ export function main() {
log.push(5);
}));

it("delivers next and complete events asynchronously",
inject([AsyncTestCompleter], (async) => {
it("delivers next and complete events synchronously", () => {
let log = [];
ObservableWrapper.subscribe(emitter,
(x) => {
log.push(x);
expect(log).toEqual([1, 3, 5, 2]);
expect(log).toEqual([1, 2]);
},
null, () => {
log.push(4);
expect(log).toEqual([1, 3, 5, 2, 4]);
async.done();
});
expect(log).toEqual([1, 2, 3, 4]);
});
log.push(1);
ObservableWrapper.callEmit(emitter, 2);
log.push(3);
ObservableWrapper.callComplete(emitter);
log.push(5);
}));
expect(log).toEqual([1, 2, 3, 4, 5]);
});
}

it('delivers events synchronously', () => {
var e = new EventEmitter(false);
it('delivers events asynchronously when forced to async mode', inject([AsyncTestCompleter], (async) => {
var e = new EventEmitter(true);
var log = [];
ObservableWrapper.subscribe(e, (x) => { log.push(x); });
ObservableWrapper.subscribe(e, (x) => {
log.push(x);
expect(log).toEqual([1, 3, 2]);
async.done();
});
log.push(1);
ObservableWrapper.callEmit(e, 2);
log.push(3);
expect(log).toEqual([1, 2, 3]);
});

}));

it('reports whether it has subscribers', () => {
var e = new EventEmitter(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,12 @@ export function main() {
});

it('should normalize urls on popstate', inject([AsyncTestCompleter], (async) => {
locationStrategy.simulatePopState('/my/app/user/btford');

location.subscribe((ev) => {
expect(ev['url']).toEqual('/user/btford');
async.done();
})
});
locationStrategy.simulatePopState('/my/app/user/btford');
}));

it('should revert to the previous path when a back() operation is executed', () => {
Expand Down
18 changes: 5 additions & 13 deletions modules/@angular/upgrade/test/upgrade_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,19 +193,11 @@ export function main() {
expect(multiTrim(document.body.textContent))
.toEqual(
"ignore: -; " + "literal: Text; interpolate: Hello world; " +
"oneWayA: A; oneWayB: B; twoWayA: initModelA; twoWayB: initModelB; (1) | " +
"modelA: initModelA; modelB: initModelB; eventA: ?; eventB: ?;");
setTimeout(() => {
// we need to do setTimeout, because the EventEmitter uses setTimeout to schedule
// events, and so without this we would not see the events processed.
expect(multiTrim(document.body.textContent))
.toEqual("ignore: -; " + "literal: Text; interpolate: Hello world; " +
"oneWayA: A; oneWayB: B; twoWayA: newA; twoWayB: newB; (3) | " +
"modelA: newA; modelB: newB; eventA: aFired; eventB: bFired;");
ref.dispose();
async.done();
});
});
"oneWayA: A; oneWayB: B; twoWayA: newA; twoWayB: newB; (2) | " +
"modelA: newA; modelB: newB; eventA: aFired; eventB: bFired;")
ref.dispose();
async.done();
});

}));

Expand Down

0 comments on commit e5904f4

Please sign in to comment.