Remove `key` from `NavigationState`.
Summary: NavigationState is composed of many things such as `index`, `routes`. The only way to effectively compare navigation states is to assume their immutability and simply compare their references. That said, `navigationState.key` does not really serves anything useful. The key does not make a navigation state more unique or comparable. This diff makes `navigationState.key` irrelevant thus we could make NavigationState simpler. Reviewed By: ericvicenti Differential Revision: D3351915 fbshipit-source-id: 75d5fa432d2a693f999a91b11e3bff1fdd42e61d
This commit is contained in:
parent
26e8426248
commit
f7279b4074
|
@ -43,7 +43,6 @@ const navigationRoute = PropTypes.shape({
|
|||
/* navigationRoute */
|
||||
const navigationState = PropTypes.shape({
|
||||
index: PropTypes.number.isRequired,
|
||||
key: PropTypes.string.isRequired,
|
||||
routes: PropTypes.arrayOf(navigationRoute),
|
||||
});
|
||||
|
||||
|
|
|
@ -95,7 +95,6 @@ function set(state: ?NavigationState, key: string, nextChildren: Array<Navigatio
|
|||
return {
|
||||
routes: nextChildren,
|
||||
index: nextIndex,
|
||||
key,
|
||||
};
|
||||
}
|
||||
const parentState = getParent(state);
|
||||
|
@ -103,17 +102,15 @@ function set(state: ?NavigationState, key: string, nextChildren: Array<Navigatio
|
|||
return {
|
||||
routes: nextChildren,
|
||||
index: nextIndex,
|
||||
key,
|
||||
};
|
||||
}
|
||||
if (nextChildren === parentState.routes && nextIndex === parentState.index && key === parentState.key) {
|
||||
if (nextChildren === parentState.routes && nextIndex === parentState.index) {
|
||||
return parentState;
|
||||
}
|
||||
return {
|
||||
...parentState,
|
||||
routes: nextChildren,
|
||||
index: nextIndex,
|
||||
key,
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -144,7 +141,7 @@ function jumpTo(state: NavigationState, key: string): NavigationState {
|
|||
};
|
||||
}
|
||||
|
||||
function replaceAt(state: NavigationState, key: string, newState: NavigationState): NavigationState {
|
||||
function replaceAt(state: NavigationState, key: string, newState: NavigationRoute): NavigationState {
|
||||
const parentState = getParent(state);
|
||||
if (!parentState) {
|
||||
return state;
|
||||
|
@ -162,7 +159,7 @@ function replaceAt(state: NavigationState, key: string, newState: NavigationStat
|
|||
};
|
||||
}
|
||||
|
||||
function replaceAtIndex(state: NavigationState, index: number, newState: NavigationState): NavigationState {
|
||||
function replaceAtIndex(state: NavigationState, index: number, newState: NavigationRoute): NavigationState {
|
||||
const parentState = getParent(state);
|
||||
if (!parentState) {
|
||||
return state;
|
||||
|
@ -176,17 +173,17 @@ function replaceAtIndex(state: NavigationState, index: number, newState: Navigat
|
|||
}
|
||||
|
||||
const NavigationStateUtils = {
|
||||
getParent,
|
||||
get: get,
|
||||
getParent,
|
||||
indexOf,
|
||||
push,
|
||||
pop,
|
||||
reset,
|
||||
set: set,
|
||||
jumpToIndex,
|
||||
jumpTo,
|
||||
jumpToIndex,
|
||||
pop,
|
||||
push,
|
||||
replaceAt,
|
||||
replaceAtIndex,
|
||||
reset,
|
||||
set: set,
|
||||
};
|
||||
|
||||
module.exports = NavigationStateUtils;
|
||||
|
|
|
@ -26,7 +26,6 @@ export type NavigationRoute = {
|
|||
};
|
||||
|
||||
export type NavigationState = {
|
||||
key: string,
|
||||
index: number,
|
||||
routes: Array<NavigationRoute>,
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue