Skip to content
This repository has been archived by the owner on Feb 8, 2020. It is now read-only.

Commit

Permalink
refactor: drop shouldActionPropagateToChildren
Browse files Browse the repository at this point in the history
  • Loading branch information
osdnk authored and satya164 committed Aug 5, 2019
1 parent 4601103 commit 1591a1d
Show file tree
Hide file tree
Showing 7 changed files with 7 additions and 64 deletions.
9 changes: 0 additions & 9 deletions packages/core/src/BaseRouter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
},
Expand Down
12 changes: 1 addition & 11 deletions packages/core/src/__tests__/NavigationContainer.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 0 additions & 4 deletions packages/core/src/__tests__/__fixtures__/MockRouter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,6 @@ export default function MockRouter(options: DefaultRouterOptions) {
}
},

shouldActionPropagateToChildren(action) {
return action.type === 'NAVIGATE';
},

shouldActionChangeFocus() {
return false;
},
Expand Down
24 changes: 2 additions & 22 deletions packages/core/src/__tests__/useOnAction.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
8 changes: 0 additions & 8 deletions packages/core/src/types.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down
10 changes: 4 additions & 6 deletions packages/core/src/useOnAction.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 0 additions & 4 deletions packages/routers/src/TabRouter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -199,10 +199,6 @@ export default function TabRouter({
}
},

shouldActionPropagateToChildren(action) {
return action.type === 'NAVIGATE';
},

shouldActionChangeFocus(action) {
return action.type === 'NAVIGATE';
},
Expand Down

0 comments on commit 1591a1d

Please sign in to comment.