mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-03-29 22:41:56 +08:00
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:
committed by
Facebook Github Bot 1
parent
d5d9c5a7c6
commit
8a1629166e
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user