Skip to content

Commit

Permalink
navSelectors: Remove, after inlining last remaining function.
Browse files Browse the repository at this point in the history
As mentioned in a previous commit, navSelectors and navActions are
kind of relics from before zulip#3804, and we already have zulip#4417 for
removing most or all of navActions.

Might as well remove navSelectors.
  • Loading branch information
chrisbobbe committed Jul 14, 2021
1 parent 17cc64f commit e2acbe5
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 25 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
/* @flow strict-local */
import deepFreeze from 'deep-freeze';

import { getSameRoutesCount } from '../navSelectors';
import { navigateBack } from '../navActions';
import * as NavigationService from '../NavigationService';

describe('getSameRoutesCount', () => {
describe('navigateBack', () => {
test('if no routes the count of same routes is 0', () => {
// $FlowFixMe[cannot-write] Make Flow understand about mocking.
NavigationService.getState = jest.fn().mockReturnValue(
Expand All @@ -13,9 +13,9 @@ describe('getSameRoutesCount', () => {
}),
);

const count = getSameRoutesCount();
const action = navigateBack();

expect(count).toEqual(0);
expect(action.payload.count).toEqual(0);
});

test('if last route differs from routes the count of same routes is 0', () => {
Expand All @@ -26,9 +26,9 @@ describe('getSameRoutesCount', () => {
}),
);

const count = getSameRoutesCount();
const action = navigateBack();

expect(count).toEqual(1);
expect(action.payload.count).toEqual(1);
});

test('if several of the routes are the same ignore the params and return their count', () => {
Expand All @@ -45,8 +45,8 @@ describe('getSameRoutesCount', () => {
}),
);

const count = getSameRoutesCount();
const action = navigateBack();

expect(count).toEqual(3);
expect(action.payload.count).toEqual(3);
});
});
15 changes: 13 additions & 2 deletions src/nav/navActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,22 @@ import {
type GenericNavigationAction,
} from '@react-navigation/native';

import * as NavigationService from './NavigationService';
import type { Message, Narrow, SharedData, UserId } from '../types';
import type { ApiResponseServerSettings } from '../api/settings/getServerSettings';
import { getSameRoutesCount } from '../selectors';

export const navigateBack = (): PopAction => StackActions.pop(getSameRoutesCount());
export const navigateBack = (): PopAction => {
const routes = NavigationService.getState().routes;
let i = routes.length - 1;
while (i >= 0) {
if (routes[i].name !== routes[routes.length - 1].name) {
break;
}
i--;
}
const sameRoutesCount = routes.length - i - 1;
return StackActions.pop(sameRoutesCount);
};

/*
* "Reset" actions, to explicitly prohibit back navigation.
Expand Down
14 changes: 0 additions & 14 deletions src/nav/navSelectors.js

This file was deleted.

1 change: 0 additions & 1 deletion src/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ export * from './chat/fetchingSelectors';
export * from './directSelectors';
export * from './emoji/emojiSelectors';
export * from './message/messageSelectors';
export * from './nav/navSelectors';
export * from './subscriptions/subscriptionSelectors';
export * from './topics/topicSelectors';
export * from './typing/typingSelectors';
Expand Down

0 comments on commit e2acbe5

Please sign in to comment.