mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-04-27 19:25:11 +08:00
[Navigator] Add a callback that is called after emitting an event.
Summary:
While adeveloper requests the emitter to emit an event, the emitter
may not emit the event immediately instead of putting the request
into a queue and process it later.
This diff allows the developer to provide a callback which will be called
when the event has been emitted.
For instance:
```
class NavigationContext {
push(nextRoute) {
var nextStack = this._stack.push(nextRoute);
this.emit(
'change',
{
reason: 'push',
nextStack: nextStack,
nextRoute: nextRoute,
},
this._onPush
);
}
_onPush(event){
if (event.defaultPrevented) {
return;
}
this._stack = event.nextStack;
this.emit('change');
}
}
```
This commit is contained in:
@@ -36,7 +36,7 @@ class NavigationEventPool {
|
||||
this._list = [];
|
||||
}
|
||||
|
||||
get(type: String, target: Object, data: any): NavigationEvent {
|
||||
get(type: string, target: Object, data: any): NavigationEvent {
|
||||
var event;
|
||||
if (this._list.length > 0) {
|
||||
event = this._list.pop();
|
||||
@@ -59,13 +59,13 @@ class NavigationEvent {
|
||||
_defaultPrevented: boolean;
|
||||
_disposed: boolean;
|
||||
_target: ?Object;
|
||||
_type: ?String;
|
||||
_type: ?string;
|
||||
|
||||
static pool(type: String, target: Object, data: any): NavigationEvent {
|
||||
static pool(type: string, target: Object, data: any): NavigationEvent {
|
||||
return _navigationEventPool.get(type, target, data);
|
||||
}
|
||||
|
||||
constructor(type: String, target: Object, data: any) {
|
||||
constructor(type: string, target: Object, data: any) {
|
||||
this._type = type;
|
||||
this._target = target;
|
||||
this._data = data;
|
||||
|
||||
Reference in New Issue
Block a user