diff --git a/lib/keyserver-conn/call-keyserver-endpoint-provider.react.js b/lib/keyserver-conn/call-keyserver-endpoint-provider.react.js --- a/lib/keyserver-conn/call-keyserver-endpoint-provider.react.js +++ b/lib/keyserver-conn/call-keyserver-endpoint-provider.react.js @@ -26,9 +26,6 @@ keyserverID: string, ) => ServerCallSelectorParams => CallServerEndpoint; type CallKeyserverEndpointContextType = { - +bindCookieAndUtilsIntoCallServerEndpoint: ( - params: BindServerCallsParams, - ) => CallServerEndpoint, +createCallSingleKeyserverEndpointSelector: CreateCallSingleKeyserverEndpointSelector, }; @@ -48,7 +45,7 @@ +isSocketConnected: boolean, +lastCommunicatedPlatformDetails: ?PlatformDetails, }; -export type BindServerCallsParams = $ReadOnly<{ +type BindServerCallsParams = $ReadOnly<{ ...ServerCallSelectorParams, +keyserverID: string, }>; @@ -232,13 +229,9 @@ const value = React.useMemo( () => ({ - bindCookieAndUtilsIntoCallServerEndpoint, createCallSingleKeyserverEndpointSelector, }), - [ - bindCookieAndUtilsIntoCallServerEndpoint, - createCallSingleKeyserverEndpointSelector, - ], + [createCallSingleKeyserverEndpointSelector], ); return ( diff --git a/lib/utils/keyserver-call.js b/lib/utils/keyserver-call.js --- a/lib/utils/keyserver-call.js +++ b/lib/utils/keyserver-call.js @@ -11,10 +11,7 @@ import { promiseAll } from './promises.js'; import { useSelector, useDispatch } from './redux-utils.js'; import { useDerivedObject } from '../hooks/objects.js'; -import { - useCallKeyserverEndpointContext, - type BindServerCallsParams, -} from '../keyserver-conn/call-keyserver-endpoint-provider.react.js'; +import { useCallKeyserverEndpointContext } from '../keyserver-conn/call-keyserver-endpoint-provider.react.js'; import type { PlatformDetails } from '../types/device-types.js'; import type { Endpoint } from '../types/endpoints.js'; import type { KeyserverInfo } from '../types/keyserver-types.js'; @@ -35,52 +32,6 @@ allKeyserverIDs: $ReadOnlyArray, ) => Args => Promise; -// _memoize memoizes the function by caching the result. -// The first argument of the memoized function is used as the map cache key. -const baseCreateBoundServerCallsSelector = ( - keyserverID: string, - bindCookieAndUtilsIntoCallServerEndpoint: ( - params: BindServerCallsParams, - ) => CallServerEndpoint, -): (BindServerCallsParams => CallServerEndpoint) => - createSelector( - (state: BindServerCallsParams) => state.dispatch, - (state: BindServerCallsParams) => state.cookie, - (state: BindServerCallsParams) => state.urlPrefix, - (state: BindServerCallsParams) => state.sessionID, - (state: BindServerCallsParams) => state.currentUserInfo, - (state: BindServerCallsParams) => state.isSocketConnected, - (state: BindServerCallsParams) => state.lastCommunicatedPlatformDetails, - ( - dispatch: Dispatch, - cookie: ?string, - urlPrefix: string, - sessionID: ?string, - currentUserInfo: ?CurrentUserInfo, - isSocketConnected: boolean, - lastCommunicatedPlatformDetails: ?PlatformDetails, - ) => - bindCookieAndUtilsIntoCallServerEndpoint({ - dispatch, - cookie, - urlPrefix, - sessionID, - currentUserInfo, - isSocketConnected, - lastCommunicatedPlatformDetails, - keyserverID, - }), - ); - -type CreateBoundServerCallsSelectorType = ( - keyserverID: string, - bindCookieAndUtilsIntoCallServerEndpoint: ( - params: BindServerCallsParams, - ) => CallServerEndpoint, -) => BindServerCallsParams => CallServerEndpoint; -const createBoundServerCallsSelector: CreateBoundServerCallsSelectorType = - _memoize(baseCreateBoundServerCallsSelector); - type KeyserverInfoPartial = $ReadOnly<{ ...Partial, +urlPrefix: $PropertyType, @@ -136,8 +87,12 @@ currentUserInfo: ?CurrentUserInfo, keyserverCallInfos: { +[keyserverID: string]: KeyserverCallInfo }, ): BindCallKeyserverSelector { - const { bindCookieAndUtilsIntoCallServerEndpoint } = + const { createCallSingleKeyserverEndpointSelector } = useCallKeyserverEndpointContext(); + const getCallSingleKeyserverEndpointSelector = React.useMemo( + () => _memoize(createCallSingleKeyserverEndpointSelector), + [createCallSingleKeyserverEndpointSelector], + ); return React.useMemo( () => _memoize( @@ -158,19 +113,16 @@ lastCommunicatedPlatformDetails, } = keyserverCallInfos[keyserverID]; - const boundCallServerEndpoint = createBoundServerCallsSelector( - keyserverID, - bindCookieAndUtilsIntoCallServerEndpoint, - )({ - dispatch, - currentUserInfo, - cookie, - urlPrefix, - sessionID, - isSocketConnected, - lastCommunicatedPlatformDetails, - keyserverID, - }); + const boundCallServerEndpoint = + getCallSingleKeyserverEndpointSelector(keyserverID)({ + dispatch, + currentUserInfo, + cookie, + urlPrefix, + sessionID, + isSocketConnected, + lastCommunicatedPlatformDetails, + }); return boundCallServerEndpoint( endpoint, @@ -193,7 +145,7 @@ dispatch, currentUserInfo, keyserverCallInfos, - bindCookieAndUtilsIntoCallServerEndpoint, + getCallSingleKeyserverEndpointSelector, ], ); }