Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3700528
D11656.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
2 KB
Referenced Files
None
Subscribers
None
D11656.diff
View Options
diff --git a/lib/selectors/account-selectors.js b/lib/selectors/account-selectors.js
--- a/lib/selectors/account-selectors.js
+++ b/lib/selectors/account-selectors.js
@@ -1,6 +1,7 @@
// @flow
import _memoize from 'lodash/memoize.js';
+import * as React from 'react';
import { createSelector } from 'reselect';
import {
@@ -8,12 +9,13 @@
sessionIDSelector,
deviceTokensSelector,
} from './keyserver-selectors.js';
+import { useDerivedObject } from '../hooks/objects.js';
import type {
LogInExtraInfo,
DeviceTokenUpdateRequest,
} from '../types/account-types.js';
import type { CalendarFilter } from '../types/filter-types.js';
-import type { KeyserverInfos } from '../types/keyserver-types.js';
+import type { KeyserverInfo } from '../types/keyserver-types.js';
import type { BaseNavInfo } from '../types/nav-types.js';
import type { AppState, BaseAppState } from '../types/redux-types.js';
import type {
@@ -77,29 +79,30 @@
basePreRequestUserStateForSingleKeyserverSelector,
);
-const preRequestUserStateSelector: (state: AppState) => PreRequestUserState =
- createSelector(
- (state: AppState) => state.currentUserInfo,
- (state: AppState) => state.keyserverStore.keyserverInfos,
- (currentUserInfo: ?CurrentUserInfo, keyserverInfos: KeyserverInfos) => {
- const cookiesAndSessions: {
- [string]: PreRequestUserKeyserverSessionInfo,
- } = {};
- for (const keyserverID in keyserverInfos) {
- cookiesAndSessions[keyserverID] = {
- cookie: keyserverInfos[keyserverID].cookie,
- sessionID: keyserverInfos[keyserverID].sessionID,
- };
- }
- return {
- currentUserInfo,
- cookiesAndSessions,
- };
- },
- );
+const createPreRequestUserKeyserverSessionInfoSelector: () => KeyserverInfo => PreRequestUserKeyserverSessionInfo =
+ () =>
+ createSelector(
+ (keyserverInfo: KeyserverInfo) => keyserverInfo.cookie,
+ (keyserverInfo: KeyserverInfo) => keyserverInfo.sessionID,
+ (cookie: ?string, sessionID: ?string) => ({ cookie, sessionID }),
+ );
function usePreRequestUserState(): PreRequestUserState {
- return useSelector(preRequestUserStateSelector);
+ const currentUserInfo = useSelector(state => state.currentUserInfo);
+ const keyserverInfos = useSelector(
+ state => state.keyserverStore.keyserverInfos,
+ );
+ const cookiesAndSessions = useDerivedObject(
+ keyserverInfos,
+ createPreRequestUserKeyserverSessionInfoSelector,
+ );
+ return React.useMemo(
+ () => ({
+ currentUserInfo,
+ cookiesAndSessions,
+ }),
+ [currentUserInfo, cookiesAndSessions],
+ );
}
export {
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Wed, Jan 8, 4:55 PM (4 h, 31 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2820455
Default Alt Text
D11656.diff (2 KB)
Attached To
Mode
D11656: [lib] Use useDerivedObject to reduce renders due to preRequestUserState
Attached
Detach File
Event Timeline
Log In to Comment