From 2e80bd07554324b6f4d52f5b9a9097af1faf18bf Mon Sep 17 00:00:00 2001 From: Chris Bobbe Date: Mon, 12 Jul 2021 20:10:53 -0400 Subject: [PATCH] navSelectors [nfc]: Remove, after inlining last remaining function. As mentioned in a previous commit, navSelectors and navActions are kind of relics from before #3804, and we already have #4417 for removing most or all of navActions. Might as well remove navSelectors. --- .../{navSelectors-test.js => navActions-test.js} | 16 ++++++++-------- src/nav/navActions.js | 15 +++++++++++++-- src/nav/navSelectors.js | 14 -------------- src/selectors.js | 1 - 4 files changed, 21 insertions(+), 25 deletions(-) rename src/nav/__tests__/{navSelectors-test.js => navActions-test.js} (79%) delete mode 100644 src/nav/navSelectors.js diff --git a/src/nav/__tests__/navSelectors-test.js b/src/nav/__tests__/navActions-test.js similarity index 79% rename from src/nav/__tests__/navSelectors-test.js rename to src/nav/__tests__/navActions-test.js index 9075bb41df4..955cbe75e48 100644 --- a/src/nav/__tests__/navSelectors-test.js +++ b/src/nav/__tests__/navActions-test.js @@ -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( @@ -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', () => { @@ -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', () => { @@ -45,8 +45,8 @@ describe('getSameRoutesCount', () => { }), ); - const count = getSameRoutesCount(); + const action = navigateBack(); - expect(count).toEqual(3); + expect(action.payload.count).toEqual(3); }); }); diff --git a/src/nav/navActions.js b/src/nav/navActions.js index 3adbe631220..fb3641fe03d 100644 --- a/src/nav/navActions.js +++ b/src/nav/navActions.js @@ -6,12 +6,23 @@ import { type GenericNavigationAction, } from '@react-navigation/native'; +import * as NavigationService from './NavigationService'; import type { Message, Narrow, UserId } from '../types'; import type { SharedData } from '../sharing/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. diff --git a/src/nav/navSelectors.js b/src/nav/navSelectors.js deleted file mode 100644 index 589b4d603a0..00000000000 --- a/src/nav/navSelectors.js +++ /dev/null @@ -1,14 +0,0 @@ -/* @flow strict-local */ -import * as NavigationService from './NavigationService'; - -export const getSameRoutesCount = (): number => { - const routes = NavigationService.getState().routes; - let i = routes.length - 1; - while (i >= 0) { - if (routes[i].name !== routes[routes.length - 1].name) { - break; - } - i--; - } - return routes.length - i - 1; -}; diff --git a/src/selectors.js b/src/selectors.js index 66a0cd62aa9..c5c57d90aa9 100644 --- a/src/selectors.js +++ b/src/selectors.js @@ -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';