Strictify index.tsx

Summary: As per title

Reviewed By: danielbuechele

Differential Revision: D17265679

fbshipit-source-id: 664f92f803a44dd485fb7078b59c88e95998decf
This commit is contained in:
Pritesh Nandgaonkar
2019-09-10 10:34:31 -07:00
committed by Facebook Github Bot
parent 428f6b4fc1
commit b75a3dc56b
7 changed files with 29 additions and 18 deletions

View File

@@ -9,6 +9,7 @@ import {remote} from 'electron';
import uuidv1 from 'uuid/v1'; import uuidv1 from 'uuid/v1';
import {ReactElement} from 'react'; import {ReactElement} from 'react';
import CancellableExportStatus from '../chrome/CancellableExportStatus'; import CancellableExportStatus from '../chrome/CancellableExportStatus';
import {Actions} from './';
export const ACTIVE_SHEET_PLUGIN_SHEET: 'PLUGIN_SHEET' = 'PLUGIN_SHEET'; export const ACTIVE_SHEET_PLUGIN_SHEET: 'PLUGIN_SHEET' = 'PLUGIN_SHEET';
export const ACTIVE_SHEET_BUG_REPORTER: 'BUG_REPORTER' = 'BUG_REPORTER'; export const ACTIVE_SHEET_BUG_REPORTER: 'BUG_REPORTER' = 'BUG_REPORTER';
export const ACTIVE_SHEET_PLUGIN_DEBUGGER: 'PLUGIN_DEBUGGER' = export const ACTIVE_SHEET_PLUGIN_DEBUGGER: 'PLUGIN_DEBUGGER' =
@@ -139,7 +140,10 @@ const initialState: () => State = () => ({
flipperRating: null, flipperRating: null,
}); });
export default function reducer(state: State, action: Action): State { export default function reducer(
state: State | undefined,
action: Actions,
): State {
state = state || initialState(); state = state || initialState();
if ( if (
action.type === 'leftSidebarVisible' || action.type === 'leftSidebarVisible' ||

View File

@@ -14,6 +14,7 @@ import iosUtil from '../fb-stubs/iOSContainerUtility';
import {performance} from 'perf_hooks'; import {performance} from 'perf_hooks';
import {SAVED_PLUGINS_COUNT} from '../Client'; import {SAVED_PLUGINS_COUNT} from '../Client';
import isHeadless from '../utils/isHeadless'; import isHeadless from '../utils/isHeadless';
import {Actions} from '.';
const WelcomeScreen = isHeadless() const WelcomeScreen = isHeadless()
? require('../chrome/WelcomeScreenHeadless').default ? require('../chrome/WelcomeScreenHeadless').default
: require('../chrome/WelcomeScreen').default; : require('../chrome/WelcomeScreen').default;
@@ -130,7 +131,7 @@ const INITAL_STATE: State = {
staticView: WelcomeScreen, staticView: WelcomeScreen,
}; };
const reducer = (state: State = INITAL_STATE, action: Action): State => { const reducer = (state: State = INITAL_STATE, action: Actions): State => {
switch (action.type) { switch (action.type) {
case 'SET_STATIC_VIEW': { case 'SET_STATIC_VIEW': {
const {payload} = action; 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); const nextState = reducer(state, action);
if (nextState.selectedDevice) { if (nextState.selectedDevice) {

View File

@@ -28,10 +28,11 @@ import plugins, {
} from './plugins'; } from './plugins';
import user, {State as UserState, Action as UserAction} from './user'; import user, {State as UserState, Action as UserAction} from './user';
import {persistReducer} from 'redux-persist'; import {persistReducer, PersistPartial} from 'redux-persist';
import storage from 'redux-persist/lib/storage/index.js';
import {Store as ReduxStore, MiddlewareAPI as ReduxMiddlewareAPI} from 'redux'; 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 = export type Actions =
| ApplicationAction | ApplicationAction
@@ -43,19 +44,19 @@ export type Actions =
| {type: 'INIT'}; | {type: 'INIT'};
export type State = { export type State = {
application: ApplicationState; application: ApplicationState & PersistPartial;
connections: DevicesState; connections: DevicesState & PersistPartial;
pluginStates: PluginStatesState; pluginStates: PluginStatesState;
notifications: NotificationsState; notifications: NotificationsState & PersistPartial;
plugins: PluginsState; plugins: PluginsState;
user: UserState; user: UserState & PersistPartial;
}; };
export type Store = ReduxStore<State, Actions>; export type Store = ReduxStore<State, Actions>;
export type MiddlewareAPI = ReduxMiddlewareAPI<Dispatch<Actions>, State>; export type MiddlewareAPI = ReduxMiddlewareAPI<Dispatch<Actions>, State>;
export default combineReducers<State, Actions>({ export default combineReducers<State, Actions>({
application: persistReducer( application: persistReducer<ApplicationState, Actions>(
{ {
key: 'application', key: 'application',
storage, storage,
@@ -63,7 +64,7 @@ export default combineReducers<State, Actions>({
}, },
application, application,
), ),
connections: persistReducer( connections: persistReducer<DevicesState, Actions>(
{ {
key: 'connections', key: 'connections',
storage, storage,

View File

@@ -5,7 +5,7 @@
* @format * @format
*/ */
import {Notification} from '../plugin'; import {Notification} from '../plugin';
import {Actions} from './';
export type PluginNotification = { export type PluginNotification = {
notification: Notification; notification: Notification;
pluginId: string; pluginId: string;
@@ -60,7 +60,7 @@ const INITIAL_STATE: State = {
export default function reducer( export default function reducer(
state: State = INITIAL_STATE, state: State = INITIAL_STATE,
action: Action, action: Actions,
): State { ): State {
switch (action.type) { switch (action.type) {
case 'SET_ACTIVE_NOTIFICATIONS': { case 'SET_ACTIVE_NOTIFICATIONS': {

View File

@@ -5,6 +5,8 @@
* @format * @format
*/ */
import {Actions} from '.';
export type State = { export type State = {
[pluginKey: string]: Object; [pluginKey: string]: Object;
}; };
@@ -29,8 +31,8 @@ export type Action =
const INITIAL_STATE: State = {}; const INITIAL_STATE: State = {};
export default function reducer( export default function reducer(
state: State = INITIAL_STATE, state: State | undefined = INITIAL_STATE,
action: Action, action: Actions,
): State { ): State {
if (action.type === 'SET_PLUGIN_STATE') { if (action.type === 'SET_PLUGIN_STATE') {
const newPluginState = action.payload.state; const newPluginState = action.payload.state;

View File

@@ -7,6 +7,7 @@
import {FlipperPlugin, FlipperDevicePlugin} from '../plugin'; import {FlipperPlugin, FlipperDevicePlugin} from '../plugin';
import {PluginDefinition} from '../dispatcher/plugins'; import {PluginDefinition} from '../dispatcher/plugins';
import {Actions} from '.';
export type State = { export type State = {
devicePlugins: Map<string, typeof FlipperDevicePlugin>; devicePlugins: Map<string, typeof FlipperDevicePlugin>;
@@ -51,8 +52,8 @@ const INITIAL_STATE: State = {
}; };
export default function reducer( export default function reducer(
state: State = INITIAL_STATE, state: State | undefined = INITIAL_STATE,
action: Action, action: Actions,
): State { ): State {
if (action.type === 'REGISTER_PLUGINS') { if (action.type === 'REGISTER_PLUGINS') {
const {devicePlugins, clientPlugins} = state; const {devicePlugins, clientPlugins} = state;

View File

@@ -5,6 +5,8 @@
* @format * @format
*/ */
import {Actions} from './';
export type User = { export type User = {
name?: string; name?: string;
profile_picture?: { profile_picture?: {
@@ -27,7 +29,7 @@ const INITIAL_STATE: State = {};
export default function reducer( export default function reducer(
state: State = INITIAL_STATE, state: State = INITIAL_STATE,
action: Action, action: Actions,
): State { ): State {
if (action.type === 'LOGOUT') { if (action.type === 'LOGOUT') {
return {}; return {};