From bbc89eb3123bab8051ccaf66d7c0b84bcf191c68 Mon Sep 17 00:00:00 2001 From: Chris Bobbe Date: Wed, 4 Aug 2021 10:25:58 -0400 Subject: [PATCH] exampleData types: Annotate exported example actions. 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 #4907. --- src/__tests__/lib/exampleData.js | 31 +++++++++++++++++-------------- src/actionTypes.js | 10 +++++----- 2 files changed, 22 insertions(+), 19 deletions(-) diff --git a/src/__tests__/lib/exampleData.js b/src/__tests__/lib/exampleData.js index 29b64584eb6..c3b569baf8f 100644 --- a/src/__tests__/lib/exampleData.js +++ b/src/__tests__/lib/exampleData.js @@ -18,6 +18,11 @@ import type { } from '../../api/modelTypes'; import { makeUserId } from '../../api/idTypes'; import type { + AccountSwitchAction, + LoginSuccessAction, + RealmInitAction, + MessageFetchStartAction, + MessageFetchCompleteAction, Action, GlobalState, CaughtUpState, @@ -561,18 +566,18 @@ export const realmState = (extra?: $Rest): 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, @@ -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, @@ -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 |}); diff --git a/src/actionTypes.js b/src/actionTypes.js index 8cbce7cc064..ac0136a0546 100644 --- a/src/actionTypes.js +++ b/src/actionTypes.js @@ -139,7 +139,7 @@ type DismissServerCompatNoticeAction = {| type: typeof DISMISS_SERVER_COMPAT_NOTICE, |}; -type AccountSwitchAction = {| +export type AccountSwitchAction = {| type: typeof ACCOUNT_SWITCH, index: number, |}; @@ -149,7 +149,7 @@ type AccountRemoveAction = {| index: number, |}; -type LoginSuccessAction = {| +export type LoginSuccessAction = {| type: typeof LOGIN_SUCCESS, realm: URL, email: string, @@ -160,7 +160,7 @@ type LogoutAction = {| type: typeof LOGOUT, |}; -type RealmInitAction = {| +export type RealmInitAction = {| type: typeof REALM_INIT, data: InitialData, zulipVersion: ZulipVersion, @@ -185,7 +185,7 @@ type AckPushTokenAction = {| pushToken: string, |}; -type MessageFetchStartAction = {| +export type MessageFetchStartAction = {| type: typeof MESSAGE_FETCH_START, narrow: Narrow, numBefore: number, @@ -216,7 +216,7 @@ type MessageFetchErrorAction = {| error: Error, |}; -type MessageFetchCompleteAction = {| +export type MessageFetchCompleteAction = {| type: typeof MESSAGE_FETCH_COMPLETE, messages: Message[], narrow: Narrow,