Changeset View
Changeset View
Standalone View
Standalone View
lib/selectors/server-calls.js
// @flow | // @flow | ||||
import _memoize from 'lodash/memoize.js'; | import _memoize from 'lodash/memoize.js'; | ||||
import { createSelector } from 'reselect'; | import { createSelector } from 'reselect'; | ||||
import { | import { | ||||
cookieSelector, | cookieSelector, | ||||
sessionIDSelector, | sessionIDSelector, | ||||
urlPrefixSelector, | urlPrefixSelector, | ||||
connectionSelector, | connectionSelector, | ||||
lastCommunicatedPlatformDetailsSelector, | lastCommunicatedPlatformDetailsSelector, | ||||
} from './keyserver-selectors.js'; | } from './keyserver-selectors.js'; | ||||
import type { PlatformDetails } from '../types/device-types.js'; | import type { PlatformDetails } from '../types/device-types.js'; | ||||
import type { AppState } from '../types/redux-types.js'; | import type { AppState } from '../types/redux-types.js'; | ||||
import type { | import type { ConnectionInfo } from '../types/socket-types.js'; | ||||
ConnectionInfo, | |||||
ConnectionStatus, | |||||
} from '../types/socket-types.js'; | |||||
import { type CurrentUserInfo } from '../types/user-types.js'; | import { type CurrentUserInfo } from '../types/user-types.js'; | ||||
export type ServerCallState = { | export type ServerCallState = { | ||||
+cookie: ?string, | +cookie: ?string, | ||||
+urlPrefix: ?string, | +urlPrefix: ?string, | ||||
+sessionID: ?string, | +sessionID: ?string, | ||||
+currentUserInfo: ?CurrentUserInfo, | +currentUserInfo: ?CurrentUserInfo, | ||||
+connectionStatus: ?ConnectionStatus, | +isSocketConnected: ?boolean, | ||||
+lastCommunicatedPlatformDetails: ?PlatformDetails, | +lastCommunicatedPlatformDetails: ?PlatformDetails, | ||||
}; | }; | ||||
const baseServerCallStateSelector: ( | const baseServerCallStateSelector: ( | ||||
keyserverID: string, | keyserverID: string, | ||||
) => (state: AppState) => ServerCallState = keyserverID => | ) => (state: AppState) => ServerCallState = keyserverID => | ||||
createSelector( | createSelector( | ||||
cookieSelector(keyserverID), | cookieSelector(keyserverID), | ||||
Show All 9 Lines | ( | ||||
currentUserInfo: ?CurrentUserInfo, | currentUserInfo: ?CurrentUserInfo, | ||||
connectionInfo: ?ConnectionInfo, | connectionInfo: ?ConnectionInfo, | ||||
lastCommunicatedPlatformDetails: ?PlatformDetails, | lastCommunicatedPlatformDetails: ?PlatformDetails, | ||||
) => ({ | ) => ({ | ||||
cookie, | cookie, | ||||
urlPrefix, | urlPrefix, | ||||
sessionID, | sessionID, | ||||
currentUserInfo, | currentUserInfo, | ||||
connectionStatus: connectionInfo?.status, | isSocketConnected: | ||||
connectionInfo?.status !== undefined | |||||
? connectionInfo?.status === 'connected' | |||||
: undefined, | |||||
lastCommunicatedPlatformDetails, | lastCommunicatedPlatformDetails, | ||||
}), | }), | ||||
); | ); | ||||
const serverCallStateSelector: ( | const serverCallStateSelector: ( | ||||
keyserverID: string, | keyserverID: string, | ||||
) => (state: AppState) => ServerCallState = _memoize( | ) => (state: AppState) => ServerCallState = _memoize( | ||||
baseServerCallStateSelector, | baseServerCallStateSelector, | ||||
); | ); | ||||
export { serverCallStateSelector }; | export { serverCallStateSelector }; |