refactor: drop shouldActionPropagateToChildren

This commit is contained in:
Michal Osadnik
2019-08-04 23:49:20 +01:00
committed by Satyajit Sahoo
parent e0bee10e6b
commit 89c279fb23
7 changed files with 7 additions and 64 deletions

View File

@@ -75,15 +75,6 @@ const BaseRouter = {
}
},
shouldActionPropagateToChildren(action: CommonAction) {
return (
action.type === 'NAVIGATE' ||
action.type === 'REPLACE' ||
action.type === 'SET_PARAMS' ||
action.type === 'RESET'
);
},
shouldActionChangeFocus(action: CommonAction) {
return action.type === 'NAVIGATE';
},

View File

@@ -124,17 +124,7 @@ it('throws when nesting performTransaction', () => {
});
it('handle dispatching with ref', () => {
function CurrentParentRouter(options: DefaultRouterOptions) {
const CurrentMockRouter = MockRouter(options);
const ParentRouter: Router<NavigationState, MockActions> = {
...CurrentMockRouter,
shouldActionPropagateToChildren() {
return true;
},
};
return ParentRouter;
}
const CurrentParentRouter = MockRouter;
function CurrentChildRouter(options: DefaultRouterOptions) {
const CurrentMockRouter = MockRouter(options);

View File

@@ -93,10 +93,6 @@ export default function MockRouter(options: DefaultRouterOptions) {
}
},
shouldActionPropagateToChildren(action) {
return action.type === 'NAVIGATE';
},
shouldActionChangeFocus() {
return false;
},

View File

@@ -87,17 +87,7 @@ it("lets parent handle the action if child didn't", () => {
});
it("lets children handle the action if parent didn't", () => {
function CurrentParentRouter(options: DefaultRouterOptions) {
const CurrentMockRouter = MockRouter(options);
const ParentRouter: Router<NavigationState, MockActions> = {
...CurrentMockRouter,
shouldActionPropagateToChildren() {
return true;
},
};
return ParentRouter;
}
const CurrentParentRouter = MockRouter;
function CurrentChildRouter(options: DefaultRouterOptions) {
const CurrentMockRouter = MockRouter(options);
@@ -221,17 +211,7 @@ it("lets children handle the action if parent didn't", () => {
});
it("doesn't crash if no navigator handled the action", () => {
function TestRouter(options: DefaultRouterOptions) {
const router: Router<NavigationState, MockActions> = {
...MockRouter(options),
shouldActionPropagateToChildren() {
return true;
},
};
return router;
}
const TestRouter = MockRouter;
const TestNavigator = (props: any) => {
const { state, descriptors } = useNavigationBuilder(TestRouter, props);

View File

@@ -139,14 +139,6 @@ export type Router<
*/
getStateForAction(state: State, action: Action): State | null;
/**
* Whether the action bubbles to other navigators
* When an action isn't handled by current navigator, it can be passed to nested navigators
*
* @param action Action object to check.
*/
shouldActionPropagateToChildren(action: NavigationAction): boolean;
/**
* Whether the action should also change focus in parent navigator
*

View File

@@ -67,13 +67,11 @@ export default function useOnAction({
}
}
if (router.shouldActionPropagateToChildren(action)) {
for (let i = listeners.length - 1; i >= 0; i--) {
const listener = listeners[i];
for (let i = listeners.length - 1; i >= 0; i--) {
const listener = listeners[i];
if (listener(action, visitedNavigators)) {
return true;
}
if (listener(action, visitedNavigators)) {
return true;
}
}
} else {

View File

@@ -199,10 +199,6 @@ export default function TabRouter({
}
},
shouldActionPropagateToChildren(action) {
return action.type === 'NAVIGATE';
},
shouldActionChangeFocus(action) {
return action.type === 'NAVIGATE';
},