Skip to content

Commit

Permalink
actions: Make EventAction complete.
Browse files Browse the repository at this point in the history
This resolves the long list of type errors Flow saw in eventToAction.

It also resolves an even longer list of type errors in reducers, which
have been hidden by a curious Flow issue; the next commit applies a
workaround for that issue, which exposes all those errors and is how I
found these types were missing from the EventAction union.

As a nice little bonus, it lets us simplify the definition of Action.
  • Loading branch information
gnprice committed Jan 11, 2019
1 parent f7bb5d5 commit ea2b119
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 25 deletions.
52 changes: 28 additions & 24 deletions src/actionTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,27 @@ export type EventReactionAction = EventReactionAddAction | EventReactionRemoveAc

export type EventTypingAction = EventTypingStartAction | EventTypingStopAction;

export type EventAction = EventSubscriptionAction | EventUserAction;
export type EventAction =
| EventAlertWordsAction
| EventReactionAddAction
| EventReactionRemoveAction
| EventNewMessageAction
| EventMessageDeleteAction
| EventUpdateMessageAction
| EventMutedTopicsAction
| EventPresenceAction
| EventUpdateGlobalNotificationsSettingsAction
| EventStreamAction
| EventSubscriptionAction
| EventTypingAction
| EventRealmEmojiUpdateAction
| EventRealmFiltersAction
| EventUpdateDisplaySettingsAction
| EventUpdateMessageFlagsAction
| EventUserAction
| EventUserGroupAction
| {| type: 'ignore' |}
| {| type: 'unknown', event: {} |};

export type InitRealmEmojiAction = {|
type: typeof INIT_REALM_EMOJI,
Expand Down Expand Up @@ -619,26 +639,15 @@ type AccountAction =
| LoginSuccessAction
| LogoutAction;

type AlertWordsAction = EventAlertWordsAction;

type DraftsAction = DraftUpdateAction;

type LoadingAction = DeadQueueAction | InitialFetchStartAction | InitialFetchCompleteAction;

type MessageAction =
| MessageFetchStartAction
| MessageFetchCompleteAction
| EventReactionAddAction
| EventReactionRemoveAction
| EventNewMessageAction
| EventMessageDeleteAction
| EventUpdateMessageAction;

type MuteAction = EventMutedTopicsAction;
type MessageAction = MessageFetchStartAction | MessageFetchCompleteAction;

type OutboxAction = MessageSendStartAction | MessageSendCompleteAction | DeleteOutboxMessageAction;

type PresenceAction = EventPresenceAction | PresenceResponseAction;
type PresenceAction = PresenceResponseAction;

type RealmAction =
| RealmInitAction
Expand All @@ -660,29 +669,24 @@ type SessionAction =
| DebugFlagToggleAction
| ToggleOutboxSendingAction;

type SettingsAction = SettingsChangeAction | EventUpdateGlobalNotificationsSettingsAction;
type SettingsAction = SettingsChangeAction;

type StreamAction = InitStreamsAction | EventStreamRemoveAction | EventStreamUpdateAction;
type StreamAction = InitStreamsAction;

type SubscriptionsAction =
| InitSubscriptionsAction
| EventSubscriptionAddAction
| EventSubscriptionRemoveAction
| EventSubscriptionUpdateAction;
type SubscriptionsAction = InitSubscriptionsAction;

type TopicsAction = InitTopicsAction;

type TypingAction = EventTypingAction | ClearTypingAction;
type TypingAction = ClearTypingAction;

/** Covers all actions we ever `dispatch`. */
// The grouping here is completely arbitrary; don't worry about it.
export type Action =
| EventAction
| AccountAction
| AlertWordsAction
| DraftsAction
| LoadingAction
| MessageAction
| MuteAction
| OutboxAction
| PresenceAction
| RealmAction
Expand Down
2 changes: 1 addition & 1 deletion src/events/eventToAction.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ const updateDisplaySettings = (
type: EVENT_UPDATE_DISPLAY_SETTINGS,
});

export default (state: GlobalState, event: Object): $FlowFixMe<EventAction> => {
export default (state: GlobalState, event: Object): EventAction => {
switch (event.type) {
case 'alert_words':
return alertWords(state, event);
Expand Down

0 comments on commit ea2b119

Please sign in to comment.