refactor: use a regular action for 'resetRoot'

Previously, 'resetRoot' directly performed a 'setState' on the container instead of dispatching an action. This meant that hooks such as listener for 'preventRemove' won't be notified by it. This commit changes it to dispatch a regular 'RESET' action which will behave the same as other actions.
This commit is contained in:
Satyajit Sahoo
2020-11-07 15:55:48 +01:00
parent 8f0efc8db5
commit e50c8aa942
8 changed files with 196 additions and 34 deletions

View File

@@ -23,7 +23,7 @@ export type Action =
}
| {
type: 'RESET';
payload: ResetState;
payload: ResetState | undefined;
source?: string;
target?: string;
}
@@ -62,7 +62,7 @@ export function navigate(...args: any): Action {
}
}
export function reset(state: ResetState): Action {
export function reset(state: ResetState | undefined): Action {
return { type: 'RESET', payload: state };
}

View File

@@ -56,12 +56,11 @@ export type PartialRoute<R extends Route<string>> = Omit<R, 'key'> & {
};
export type PartialState<State extends NavigationState> = Partial<
Omit<State, 'stale' | 'type' | 'key' | 'routes' | 'routeNames'>
Omit<State, 'stale' | 'routes'>
> &
Readonly<{
stale?: true;
type?: string;
routes: PartialRoute<Route<string>>[];
routes: PartialRoute<Route<State['routeNames'][number]>>[];
}>;
export type Route<