update NavigationContext API.

Summary: 1. Add a new api `top` which returns the root navigator of a nested navigator.
2. Remove the param `context` from the method `addListener` because it's not used and not necessary.

public

Reviewed By: fkgozali

Differential Revision: D2613852

fb-gh-sync-id: 0d5544422ff0be7875824989a4fbefbef9aac986
This commit is contained in:
Hedger Wang
2015-11-03 19:05:28 -08:00
committed by facebook-github-bot-6
parent eed38e9163
commit 4763f89efa
2 changed files with 32 additions and 13 deletions

View File

@@ -50,6 +50,15 @@ describe('NavigationContext', () => {
expect(child.parent).toBe(parent);
});
it('has `top`', () => {
var top = new NavigationContext();
var parent = new NavigationContext();
var child = new NavigationContext();
top.appendChild(parent);
parent.appendChild(child);
expect(child.top).toBe(top);
});
it('captures event', () => {
var parent = new NavigationContext();
var child = new NavigationContext();
@@ -67,8 +76,8 @@ describe('NavigationContext', () => {
});
};
parent.addListener('yo', listener, null, true);
child.addListener('yo', listener, null, true);
parent.addListener('yo', listener, true);
child.addListener('yo', listener, true);
child.emit('yo');
@@ -133,8 +142,8 @@ describe('NavigationContext', () => {
var counter = 0;
parent.addListener('yo', event => event.stopPropagation(), null, true);
child.addListener('yo', event => counter++, null, true);
parent.addListener('yo', event => event.stopPropagation(), true);
child.addListener('yo', event => counter++, true);
child.emit('yo');
@@ -162,8 +171,8 @@ describe('NavigationContext', () => {
parent.appendChild(child);
var val;
parent.addListener('yo', event => event.preventDefault(), null, true);
child.addListener('yo', event => val = event.defaultPrevented, null, true);
parent.addListener('yo', event => event.preventDefault(), true);
child.addListener('yo', event => val = event.defaultPrevented, true);
child.emit('yo');
@@ -205,9 +214,9 @@ describe('NavigationContext', () => {
child.emit('didyo');
});
parent.addListener('yo', listener, null, true);
parent.addListener('didyo', listener, null, true);
child.addListener('yo', listener, null, true);
parent.addListener('yo', listener, true);
parent.addListener('didyo', listener, true);
child.addListener('yo', listener, true);
child.emit('yo');