nested emit call in a queue should be handled in FIFO

Summary: I think we should dispose events in FIFO order

Reviewed By: fkgozali

Differential Revision: D2987425

fb-gh-sync-id: a4ad256512725d0bed0086b642e10fe7e7715070
shipit-source-id: a4ad256512725d0bed0086b642e10fe7e7715070
This commit is contained in:
Wenjing Wang
2016-03-03 18:56:27 -08:00
committed by Facebook Github Bot 1
parent d5d9c5a7c6
commit 8a1629166e
2 changed files with 27 additions and 1 deletions

View File

@@ -59,7 +59,7 @@ class NavigationEventEmitter extends EventEmitter {
// An event cycle that was previously created hasn't finished yet.
// Put this event cycle into the queue and will finish them later.
var args: any = Array.prototype.slice.call(arguments);
this._emitQueue.unshift(args);
this._emitQueue.push(args);
return;
}

View File

@@ -100,6 +100,32 @@ describe('NavigationEventEmitter', () => {
expect(logs).toEqual([1, 2, 3, 4, 5]);
});
it('puts nested emit call in a queue should be in sequence order', () => {
var context = {};
var emitter = new NavigationEventEmitter(context);
var logs = [];
emitter.addListener('one', () => {
logs.push(1);
emitter.emit('two');
emitter.emit('three');
logs.push(2);
});
emitter.addListener('two', () => {
logs.push(3);
logs.push(4);
});
emitter.addListener('three', () => {
logs.push(5);
});
emitter.emit('one');
expect(logs).toEqual([1, 2, 3, 4, 5]);
});
it('calls callback after emitting', () => {
var context = {};
var emitter = new NavigationEventEmitter(context);