Skip to content

Commit

Permalink
exampleData types: Annotate exported example actions.
Browse files Browse the repository at this point in the history
Following Greg's recommendation at
  https://chat.zulip.org/#narrow/stream/243-mobile-team/topic/Flow.20types-first/near/1237928.

This will help move us along toward Flow's new "Types-First" mode;
switching entirely is zulip#4907.
  • Loading branch information
chrisbobbe committed Aug 4, 2021
1 parent 6ffe4c0 commit bbc89eb
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 19 deletions.
31 changes: 17 additions & 14 deletions src/__tests__/lib/exampleData.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ import type {
} from '../../api/modelTypes';
import { makeUserId } from '../../api/idTypes';
import type {
AccountSwitchAction,
LoginSuccessAction,
RealmInitAction,
MessageFetchStartAction,
MessageFetchCompleteAction,
Action,
GlobalState,
CaughtUpState,
Expand Down Expand Up @@ -561,18 +566,18 @@ export const realmState = (extra?: $Rest<RealmState, { ... }>): RealmState =>
* Complete actions which need no further data.
*/

export const action = deepFreeze({
account_switch: {
export const action = Object.freeze({
account_switch: (deepFreeze({
type: ACCOUNT_SWITCH,
index: 0,
},
login_success: {
}): AccountSwitchAction),
login_success: (deepFreeze({
type: LOGIN_SUCCESS,
realm: selfAccount.realm,
email: selfAccount.email,
apiKey: selfAccount.apiKey,
},
realm_init: {
}): LoginSuccessAction),
realm_init: (deepFreeze({
type: REALM_INIT,
data: {
last_event_id: 34,
Expand Down Expand Up @@ -678,14 +683,14 @@ export const action = deepFreeze({
user_status: {},
},
zulipVersion,
},
message_fetch_start: {
}): RealmInitAction),
message_fetch_start: (deepFreeze({
type: MESSAGE_FETCH_START,
narrow: HOME_NARROW,
numBefore: 0,
numAfter: 20,
},
message_fetch_complete: {
}): MessageFetchStartAction),
message_fetch_complete: (deepFreeze({
type: MESSAGE_FETCH_COMPLETE,
messages: [],
narrow: HOME_NARROW,
Expand All @@ -695,14 +700,12 @@ export const action = deepFreeze({
foundNewest: undefined,
foundOldest: undefined,
ownUserId: selfUser.user_id,
},
}): MessageFetchCompleteAction),
// If a given action is only relevant to a single test file, no need to
// provide a generic example of it here; just define it there.
});

// Ensure every `eg.action.foo` is some well-typed action. (We don't simply
// annotate `action` itself, because we want to keep the information of
// which one has which specific type.)
// Ensure every `eg.action.foo` is some well-typed action.
/* eslint-disable-next-line no-unused-expressions */
(action: {| [string]: Action |});

Expand Down
10 changes: 5 additions & 5 deletions src/actionTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ type DismissServerCompatNoticeAction = {|
type: typeof DISMISS_SERVER_COMPAT_NOTICE,
|};

type AccountSwitchAction = {|
export type AccountSwitchAction = {|
type: typeof ACCOUNT_SWITCH,
index: number,
|};
Expand All @@ -149,7 +149,7 @@ type AccountRemoveAction = {|
index: number,
|};

type LoginSuccessAction = {|
export type LoginSuccessAction = {|
type: typeof LOGIN_SUCCESS,
realm: URL,
email: string,
Expand All @@ -160,7 +160,7 @@ type LogoutAction = {|
type: typeof LOGOUT,
|};

type RealmInitAction = {|
export type RealmInitAction = {|
type: typeof REALM_INIT,
data: InitialData,
zulipVersion: ZulipVersion,
Expand All @@ -185,7 +185,7 @@ type AckPushTokenAction = {|
pushToken: string,
|};

type MessageFetchStartAction = {|
export type MessageFetchStartAction = {|
type: typeof MESSAGE_FETCH_START,
narrow: Narrow,
numBefore: number,
Expand Down Expand Up @@ -216,7 +216,7 @@ type MessageFetchErrorAction = {|
error: Error,
|};

type MessageFetchCompleteAction = {|
export type MessageFetchCompleteAction = {|
type: typeof MESSAGE_FETCH_COMPLETE,
messages: Message[],
narrow: Narrow,
Expand Down

0 comments on commit bbc89eb

Please sign in to comment.