Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3367690
D9268.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
D9268.diff
View Options
diff --git a/lib/reducers/user-reducer.js b/lib/reducers/user-reducer.js
--- a/lib/reducers/user-reducer.js
+++ b/lib/reducers/user-reducer.js
@@ -17,6 +17,7 @@
updateUserAvatarActionTypes,
resetUserStateActionType,
} from '../actions/user-actions.js';
+import { updateSpecs } from '../shared/updates/update-specs.js';
import type { BaseAction } from '../types/redux-types.js';
import {
type UserInconsistencyReportCreationRequest,
@@ -74,14 +75,15 @@
action.type === incrementalStateSyncActionType ||
action.type === processUpdatesActionType
) {
- for (const update of action.payload.updatesResult.newUpdates) {
- if (
- update.type === updateTypes.UPDATE_CURRENT_USER &&
- !_isEqual(update.currentUserInfo)(state)
- ) {
- return update.currentUserInfo;
- }
- }
+ return action.payload.updatesResult.newUpdates.reduce(
+ (reducedState, update) => {
+ const { reduceCurrentUser } = updateSpecs[update.type];
+ return reduceCurrentUser
+ ? reduceCurrentUser(reducedState, update)
+ : reducedState;
+ },
+ state,
+ );
} else if (action.type === processServerRequestsActionType) {
const checkStateRequest = action.payload.serverRequests.find(
candidate => candidate.type === serverRequestTypes.CHECK_STATE,
diff --git a/lib/shared/updates/update-current-user-spec.js b/lib/shared/updates/update-current-user-spec.js
--- a/lib/shared/updates/update-current-user-spec.js
+++ b/lib/shared/updates/update-current-user-spec.js
@@ -1,7 +1,17 @@
// @flow
+import _isEqual from 'lodash/fp/isEqual.js';
+
import type { UpdateSpec } from './update-spec.js';
import type { CurrentUserUpdateInfo } from '../../types/update-types.js';
+import type { CurrentUserInfo } from '../../types/user-types.js';
export const updateCurrentUserSpec: UpdateSpec<CurrentUserUpdateInfo> =
- Object.freeze({});
+ Object.freeze({
+ reduceCurrentUser(state: ?CurrentUserInfo, update: CurrentUserUpdateInfo) {
+ if (!_isEqual(update.currentUserInfo)(state)) {
+ return update.currentUserInfo;
+ }
+ return state;
+ },
+ });
diff --git a/lib/shared/updates/update-spec.js b/lib/shared/updates/update-spec.js
--- a/lib/shared/updates/update-spec.js
+++ b/lib/shared/updates/update-spec.js
@@ -4,6 +4,7 @@
import type { RawEntryInfo } from '../../types/entry-types.js';
import type { RawThreadInfos } from '../../types/thread-types.js';
import type { ClientUpdateInfo } from '../../types/update-types.js';
+import type { CurrentUserInfo } from '../../types/user-types.js';
export type UpdateSpec<UpdateInfo: ClientUpdateInfo> = {
+generateOpsForThreadUpdates?: (
@@ -15,4 +16,8 @@
mergedEntryInfos: Array<RawEntryInfo>,
update: UpdateInfo,
) => void,
+ +reduceCurrentUser?: (
+ state: ?CurrentUserInfo,
+ update: UpdateInfo,
+ ) => ?CurrentUserInfo,
};
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Tue, Nov 26, 3:45 PM (19 h, 21 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2585383
Default Alt Text
D9268.diff (2 KB)
Attached To
Mode
D9268: [lib] Move current user updates logic into a spec
Attached
Detach File
Event Timeline
Log In to Comment