diff --git a/package.json b/package.json index 19b0860ebf..ab23bbd5cc 100644 --- a/package.json +++ b/package.json @@ -152,7 +152,7 @@ "redux-promise-middleware": "6.1.0", "redux-thunk": "2.3.0", "redux-ts-utils": "3.2.2", - "reselect": "4.0.0", + "reselect": "4.1.2", "rimraf": "2.6.2", "ringrtc": "https://github.com/signalapp/signal-ringrtc-node.git#011bdd9a71982a7bbf333bf3641dbd722c8c7bf1", "rotating-file-stream": "2.1.5", diff --git a/ts/components/conversation/Timeline.tsx b/ts/components/conversation/Timeline.tsx index 6b4e164ce5..121cb4874a 100644 --- a/ts/components/conversation/Timeline.tsx +++ b/ts/components/conversation/Timeline.tsx @@ -1,7 +1,7 @@ // Copyright 2019-2021 Signal Messenger, LLC // SPDX-License-Identifier: AGPL-3.0-only -import { debounce, get, isNumber, pick, identity } from 'lodash'; +import { debounce, get, isNumber, pick } from 'lodash'; import classNames from 'classnames'; import type { CSSProperties, ReactChild, ReactNode, RefObject } from 'react'; import React from 'react'; @@ -226,7 +226,7 @@ type StateType = { const getActions = createSelector( // It is expensive to pick so many properties out of the `props` object so we // use `createSelector` to memoize them by the last seen `props` object. - identity, + (props: PropsType) => props, (props: PropsType): PropsActionsType => { const unsafe = pick(props, [ diff --git a/ts/state/selectors/message.ts b/ts/state/selectors/message.ts index accc4c94a5..b5be18a0a0 100644 --- a/ts/state/selectors/message.ts +++ b/ts/state/selectors/message.ts @@ -241,11 +241,7 @@ export const getAttachmentsForMessage = createSelectorCreator(memoizeByRoot)( ({ sticker }: MessageWithUIFieldsType) => sticker, ({ attachments }: MessageWithUIFieldsType) => attachments, - ( - _: MessageWithUIFieldsType, - sticker: MessageWithUIFieldsType['sticker'], - attachments: MessageWithUIFieldsType['attachments'] = [] - ): Array => { + (_, sticker, attachments = []): Array => { if (sticker && sticker.data) { const { data } = sticker; @@ -298,7 +294,7 @@ export const processBodyRanges = createSelectorCreator(memoizeByRoot, isEqual)( }) .sort((a, b) => b.start - a.start); }, - (_: MessageWithUIFieldsType, ranges?: BodyRangesType) => ranges + (_, ranges): undefined | BodyRangesType => ranges ); const getAuthorForMessage = createSelectorCreator(memoizeByRoot)( @@ -307,10 +303,7 @@ const getAuthorForMessage = createSelectorCreator(memoizeByRoot)( getContact, - ( - _: MessageWithUIFieldsType, - convo: ConversationType - ): PropsData['author'] => { + (_, convo: ConversationType): PropsData['author'] => { const { acceptedMessageRequest, avatarPath, @@ -348,25 +341,15 @@ const getAuthorForMessage = createSelectorCreator(memoizeByRoot)( const getCachedAuthorForMessage = createSelectorCreator(memoizeByRoot, isEqual)( // `memoizeByRoot` requirement identity, - getAuthorForMessage, - - ( - _: MessageWithUIFieldsType, - author: PropsData['author'] - ): PropsData['author'] => author + (_, author): PropsData['author'] => author ); export const getPreviewsForMessage = createSelectorCreator(memoizeByRoot)( // `memoizeByRoot` requirement identity, - ({ preview }: MessageWithUIFieldsType) => preview, - - ( - _: MessageWithUIFieldsType, - previews: MessageWithUIFieldsType['preview'] = [] - ): Array => { + (_, previews = []): Array => { return previews.map(preview => ({ ...preview, isStickerPack: isStickerPack(preview.url), @@ -435,7 +418,7 @@ export const getReactionsForMessage = createSelectorCreator( return [...formattedReactions]; }, - (_: MessageWithUIFieldsType, reactions: PropsData['reactions']) => reactions + (_, reactions): PropsData['reactions'] => reactions ); export const getPropsForQuote = createSelectorCreator(memoizeByRoot, isEqual)( @@ -504,7 +487,7 @@ export const getPropsForQuote = createSelectorCreator(memoizeByRoot, isEqual)( }; }, - (_: unknown, quote: PropsData['quote']) => quote + (_, quote): PropsData['quote'] => quote ); export type GetPropsForMessageOptions = Pick< @@ -642,7 +625,12 @@ const getShallowPropsForMessage = createSelectorCreator(memoizeByRoot, isEqual)( (_: unknown, props: ShallowPropsType) => props ); -export const getPropsForMessage = createSelectorCreator(memoizeByRoot)( +export const getPropsForMessage: ( + message: MessageWithUIFieldsType, + options: GetPropsForMessageOptions +) => Omit = createSelectorCreator( + memoizeByRoot +)( // `memoizeByRoot` requirement identity, @@ -654,7 +642,7 @@ export const getPropsForMessage = createSelectorCreator(memoizeByRoot)( getPropsForQuote, getShallowPropsForMessage, ( - _: unknown, + _, attachments: Array, bodyRanges: BodyRangesType | undefined, author: PropsData['author'], @@ -680,7 +668,8 @@ export const getBubblePropsForMessage = createSelectorCreator(memoizeByRoot)( identity, getPropsForMessage, - (_: unknown, data: ReturnType) => ({ + + (_, data): TimelineItemType => ({ type: 'message' as const, data, }) diff --git a/ts/util/memoizeByRoot.ts b/ts/util/memoizeByRoot.ts index cd1b13a5ae..dc182e50b0 100644 --- a/ts/util/memoizeByRoot.ts +++ b/ts/util/memoizeByRoot.ts @@ -20,7 +20,7 @@ import { strictAssert } from './assert'; // eslint-disable-next-line @typescript-eslint/ban-types export function memoizeByRoot( fn: F, - equalityCheck?: (a: T, b: T, index: number) => boolean + equalityCheck?: (a: T, b: T) => boolean ): F { // eslint-disable-next-line @typescript-eslint/ban-types const cache = new WeakMap(); diff --git a/yarn.lock b/yarn.lock index 1add739652..caf59ea223 100644 --- a/yarn.lock +++ b/yarn.lock @@ -15803,10 +15803,10 @@ requizzle@^0.2.2: dependencies: lodash "^4.17.14" -reselect@4.0.0: - version "4.0.0" - resolved "https://registry.yarnpkg.com/reselect/-/reselect-4.0.0.tgz#f2529830e5d3d0e021408b246a206ef4ea4437f7" - integrity sha512-qUgANli03jjAyGlnbYVAV5vvnOmJnODyABz51RdBN7M4WaVu8mecZWgyQNkG8Yqe3KRGRt0l4K4B3XVEULC4CA== +reselect@4.1.2: + version "4.1.2" + resolved "https://registry.yarnpkg.com/reselect/-/reselect-4.1.2.tgz#7bf642992d143d4f3b0f2dca8aa52018808a1d51" + integrity sha512-wg60ebcPOtxcptIUfrr7Jt3h4BR86cCW3R7y4qt65lnNb4yz4QgrXcbSioVsIOYguyz42+XTHIyJ5TEruzkFgQ== reserved-words@^0.1.2: version "0.1.2"