From 8a1629166edea6064f409b6206f1cc2d2eee61a4 Mon Sep 17 00:00:00 2001 From: Wenjing Wang Date: Thu, 3 Mar 2016 18:56:27 -0800 Subject: [PATCH] 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 --- .../Navigation/NavigationEventEmitter.js | 2 +- .../__tests__/NavigationEventEmitter-test.js | 26 +++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/Libraries/CustomComponents/Navigator/Navigation/NavigationEventEmitter.js b/Libraries/CustomComponents/Navigator/Navigation/NavigationEventEmitter.js index a2abd3d55bd..339c9573403 100644 --- a/Libraries/CustomComponents/Navigator/Navigation/NavigationEventEmitter.js +++ b/Libraries/CustomComponents/Navigator/Navigation/NavigationEventEmitter.js @@ -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; } diff --git a/Libraries/CustomComponents/Navigator/Navigation/__tests__/NavigationEventEmitter-test.js b/Libraries/CustomComponents/Navigator/Navigation/__tests__/NavigationEventEmitter-test.js index 63b1ccd0ba1..9e9aef47680 100644 --- a/Libraries/CustomComponents/Navigator/Navigation/__tests__/NavigationEventEmitter-test.js +++ b/Libraries/CustomComponents/Navigator/Navigation/__tests__/NavigationEventEmitter-test.js @@ -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);