refactor: mark initial state as stale to determine when to rehydrate (#23)

This commit is contained in:
Satyajit Sahoo
2019-07-22 23:21:56 +02:00
committed by Michał Osadnik
parent 2798c93e8b
commit bd6aa667cb
9 changed files with 71 additions and 19 deletions

View File

@@ -86,9 +86,10 @@ const StackRouter: Router<CommonAction | Action> = {
getRehydratedState({ routeNames, partialState }) {
let state = partialState;
if (state.routeNames === undefined || state.key === undefined) {
if (state.stale) {
state = {
...state,
stale: false,
routeNames,
key: `stack-${shortid()}`,
};

View File

@@ -72,9 +72,10 @@ const TabRouter: Router<Action | CommonAction> = {
getRehydratedState({ routeNames, partialState }) {
let state = partialState;
if (state.routeNames === undefined || state.key === undefined) {
if (state.stale) {
state = {
...state,
stale: false,
routeNames,
key: `tab-${shortid()}`,
};

View File

@@ -3,9 +3,9 @@ import { render } from 'react-dom';
import {
NavigationContainer,
CompositeNavigationProp,
PartialState,
NavigationProp,
RouteProp,
InitialState,
} from '../src';
import StackNavigator, { StackNavigationProp } from './StackNavigator';
import TabNavigator, { TabNavigationProp } from './TabNavigator';
@@ -143,7 +143,7 @@ const Fifth = ({
const PERSISTENCE_KEY = 'NAVIGATION_STATE';
let initialState: PartialState | undefined;
let initialState: InitialState | undefined;
try {
initialState = JSON.parse(localStorage.getItem(PERSISTENCE_KEY) || '');