diff --git a/src/reducers/application.tsx b/src/reducers/application.tsx index 0d54246ad..51d288ad0 100644 --- a/src/reducers/application.tsx +++ b/src/reducers/application.tsx @@ -9,6 +9,7 @@ import {remote} from 'electron'; import uuidv1 from 'uuid/v1'; import {ReactElement} from 'react'; import CancellableExportStatus from '../chrome/CancellableExportStatus'; +import {Actions} from './'; export const ACTIVE_SHEET_PLUGIN_SHEET: 'PLUGIN_SHEET' = 'PLUGIN_SHEET'; export const ACTIVE_SHEET_BUG_REPORTER: 'BUG_REPORTER' = 'BUG_REPORTER'; export const ACTIVE_SHEET_PLUGIN_DEBUGGER: 'PLUGIN_DEBUGGER' = @@ -139,7 +140,10 @@ const initialState: () => State = () => ({ flipperRating: null, }); -export default function reducer(state: State, action: Action): State { +export default function reducer( + state: State | undefined, + action: Actions, +): State { state = state || initialState(); if ( action.type === 'leftSidebarVisible' || diff --git a/src/reducers/connections.tsx b/src/reducers/connections.tsx index c1fe208fb..3ae1d4b86 100644 --- a/src/reducers/connections.tsx +++ b/src/reducers/connections.tsx @@ -14,6 +14,7 @@ import iosUtil from '../fb-stubs/iOSContainerUtility'; import {performance} from 'perf_hooks'; import {SAVED_PLUGINS_COUNT} from '../Client'; import isHeadless from '../utils/isHeadless'; +import {Actions} from '.'; const WelcomeScreen = isHeadless() ? require('../chrome/WelcomeScreenHeadless').default : require('../chrome/WelcomeScreen').default; @@ -130,7 +131,7 @@ const INITAL_STATE: State = { staticView: WelcomeScreen, }; -const reducer = (state: State = INITAL_STATE, action: Action): State => { +const reducer = (state: State = INITAL_STATE, action: Actions): State => { switch (action.type) { case 'SET_STATIC_VIEW': { const {payload} = action; @@ -417,7 +418,7 @@ const reducer = (state: State = INITAL_STATE, action: Action): State => { } }; -export default (state: State = INITAL_STATE, action: Action): State => { +export default (state: State = INITAL_STATE, action: Actions): State => { const nextState = reducer(state, action); if (nextState.selectedDevice) { diff --git a/src/reducers/index.tsx b/src/reducers/index.tsx index 7f19a05aa..96d5f3814 100644 --- a/src/reducers/index.tsx +++ b/src/reducers/index.tsx @@ -28,10 +28,11 @@ import plugins, { } from './plugins'; import user, {State as UserState, Action as UserAction} from './user'; -import {persistReducer} from 'redux-persist'; -import storage from 'redux-persist/lib/storage/index.js'; +import {persistReducer, PersistPartial} from 'redux-persist'; import {Store as ReduxStore, MiddlewareAPI as ReduxMiddlewareAPI} from 'redux'; +// @ts-ignore: explicitly need to import index.js, otherwise index.native.js is imported, because redux-persist assumes we are react-native, because we are using metro-bundler +import storage from 'redux-persist/lib/storage/index.js'; export type Actions = | ApplicationAction @@ -43,19 +44,19 @@ export type Actions = | {type: 'INIT'}; export type State = { - application: ApplicationState; - connections: DevicesState; + application: ApplicationState & PersistPartial; + connections: DevicesState & PersistPartial; pluginStates: PluginStatesState; - notifications: NotificationsState; + notifications: NotificationsState & PersistPartial; plugins: PluginsState; - user: UserState; + user: UserState & PersistPartial; }; export type Store = ReduxStore; export type MiddlewareAPI = ReduxMiddlewareAPI, State>; export default combineReducers({ - application: persistReducer( + application: persistReducer( { key: 'application', storage, @@ -63,7 +64,7 @@ export default combineReducers({ }, application, ), - connections: persistReducer( + connections: persistReducer( { key: 'connections', storage, diff --git a/src/reducers/notifications.tsx b/src/reducers/notifications.tsx index c520fc196..28dfe276d 100644 --- a/src/reducers/notifications.tsx +++ b/src/reducers/notifications.tsx @@ -5,7 +5,7 @@ * @format */ import {Notification} from '../plugin'; - +import {Actions} from './'; export type PluginNotification = { notification: Notification; pluginId: string; @@ -60,7 +60,7 @@ const INITIAL_STATE: State = { export default function reducer( state: State = INITIAL_STATE, - action: Action, + action: Actions, ): State { switch (action.type) { case 'SET_ACTIVE_NOTIFICATIONS': { diff --git a/src/reducers/pluginStates.tsx b/src/reducers/pluginStates.tsx index f5fc713c1..ee53189aa 100644 --- a/src/reducers/pluginStates.tsx +++ b/src/reducers/pluginStates.tsx @@ -5,6 +5,8 @@ * @format */ +import {Actions} from '.'; + export type State = { [pluginKey: string]: Object; }; @@ -29,8 +31,8 @@ export type Action = const INITIAL_STATE: State = {}; export default function reducer( - state: State = INITIAL_STATE, - action: Action, + state: State | undefined = INITIAL_STATE, + action: Actions, ): State { if (action.type === 'SET_PLUGIN_STATE') { const newPluginState = action.payload.state; diff --git a/src/reducers/plugins.tsx b/src/reducers/plugins.tsx index df0388cfb..771c28720 100644 --- a/src/reducers/plugins.tsx +++ b/src/reducers/plugins.tsx @@ -7,6 +7,7 @@ import {FlipperPlugin, FlipperDevicePlugin} from '../plugin'; import {PluginDefinition} from '../dispatcher/plugins'; +import {Actions} from '.'; export type State = { devicePlugins: Map; @@ -51,8 +52,8 @@ const INITIAL_STATE: State = { }; export default function reducer( - state: State = INITIAL_STATE, - action: Action, + state: State | undefined = INITIAL_STATE, + action: Actions, ): State { if (action.type === 'REGISTER_PLUGINS') { const {devicePlugins, clientPlugins} = state; diff --git a/src/reducers/user.tsx b/src/reducers/user.tsx index 55acfac03..e5a573886 100644 --- a/src/reducers/user.tsx +++ b/src/reducers/user.tsx @@ -5,6 +5,8 @@ * @format */ +import {Actions} from './'; + export type User = { name?: string; profile_picture?: { @@ -27,7 +29,7 @@ const INITIAL_STATE: State = {}; export default function reducer( state: State = INITIAL_STATE, - action: Action, + action: Actions, ): State { if (action.type === 'LOGOUT') { return {};