Skip to content

Commit

Permalink
Type getState, fix type errors (#4299)
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcoPolo authored Sep 17, 2016
1 parent b62d769 commit 01517dd
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 6 deletions.
3 changes: 2 additions & 1 deletion shared/actions/config/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,14 +118,15 @@ function _registerListeners (): AsyncAction {
let bootstrapSetup = false
export function bootstrap (): AsyncAction {
return (dispatch, getState) => {
const state = getState()
if (!bootstrapSetup) {
bootstrapSetup = true
console.log('[bootstrap] registered bootstrap')
engine().listenOnConnect('bootstrap', () => {
console.log('[bootstrap] bootstrapping on connect')
dispatch(bootstrap())
})
} else if (getState().dev.reloading) {
} else if (state.dev && state.dev.reloading) {
// Let's still register the listeners
dispatch(_registerListeners())
} else {
Expand Down
2 changes: 1 addition & 1 deletion shared/actions/config/index.platform.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export function saveDevSettings (): AsyncAction {
const {config: {devConfig}} = getState()

console.info(devConfig)
NativeModules.App.setDevConfig(devConfig.configured)
devConfig && NativeModules.App.setDevConfig(devConfig.configured)

return dispatch({
type: Constants.devConfigSaved,
Expand Down
5 changes: 4 additions & 1 deletion shared/actions/kbfs/index.platform.desktop.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,10 @@ function openInWindows (openPath: string = Constants.defaultKBFSPath): AsyncActi
// On windows the path isn't /keybase
// We can figure it out by looking at the extendedConfig though
if (kbfsPath === Constants.defaultKBFSPath) {
const extendedConfigPromise = Promise.resolve(state.config.extendedConfig)
const extendedConfig = state.config.extendedConfig
const extendedConfigPromise = extendedConfig
? Promise.resolve(extendedConfig)
: Promise.reject()

extendedConfigPromise
.then(formKbfsPathWindows)
Expand Down
14 changes: 14 additions & 0 deletions shared/actions/login/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,10 @@ export function doneRegistering (): TypedAction<'login:doneRegistering', void, v
function setCodePageOtherDeviceRole (otherDeviceRole: DeviceRole) : AsyncAction {
return (dispatch, getState) => {
const store = getState().login.codePage
if (store.myDeviceRole == null) {
console.warn("my device role is null, can't setCodePageOtherDeviceRole. Bailing")
return
}
dispatch(setCodePageMode(defaultModeForDeviceRoles(store.myDeviceRole, otherDeviceRole, false)))
dispatch({type: Constants.setOtherDeviceCodeState, payload: otherDeviceRole})
}
Expand Down Expand Up @@ -195,6 +199,16 @@ function setCameraBrokenMode (broken) : AsyncAction {
dispatch({type: Constants.cameraBrokenMode, payload: broken})

const root = getState().login.codePage
if (root.myDeviceRole == null) {
console.warn("my device role is null, can't setCameraBrokenMode. Bailing")
return
}

if (root.otherDeviceRole == null) {
console.warn("other device role is null, can't setCameraBrokenMode. Bailing")
return
}

dispatch(setCodePageMode(defaultModeForDeviceRoles(root.myDeviceRole, root.otherDeviceRole, broken)))
}
}
Expand Down
12 changes: 10 additions & 2 deletions shared/actions/profile.js
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,14 @@ function _checkProof (sigID: string, currentlyAdding: boolean): AsyncAction {
}
}

function openURLIfNotNull (nullableThing, url, metaText) {
if (nullableThing == null) {
console.warn("Can't openURL because we have a null", metaText)
return
}
openURL(url)
}

function outputInstructionsActionLink (): AsyncAction {
return (dispatch, getState) => {
const profile = getState().profile
Expand All @@ -404,13 +412,13 @@ function outputInstructionsActionLink (): AsyncAction {
openURL(`https://coinbase.com/${profile.username}#settings`)
break
case 'twitter':
openURL(`https://twitter.com/home?status=${profile.proof}`)
openURLIfNotNull(profile.proofText, `https://twitter.com/home?status=${profile.proofText || ''}`, 'twitter url')
break
case 'github':
openURL('https://gist.github.com/')
break
case 'reddit':
openURL(profile.proof)
openURLIfNotNull(profile.proofText, profile.proofText, 'reddit url')
break
default:
break
Expand Down
2 changes: 2 additions & 0 deletions shared/constants/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type {ConfigState} from '../reducers/config'
import type {FavoriteState} from '../constants/favorite'
import type {LoginState} from '../reducers/login'
import type {RootPinentryState} from '../reducers/pinentry'
import type {SignupState} from '../reducers/signup'
import type {State as GregorState} from '../reducers/gregor'
import type {State as PgpState} from '../reducers/pgp'
import type {State as ProfileState} from '../constants/profile'
Expand All @@ -19,6 +20,7 @@ export type TypedState = {
pinentry: RootPinentryState,
profile: ProfileState,
search: SearchState,
signup: SignupState,
tracker: TotalTrackerState,
unlockFolders: UnlockFoldersState,
}
Expand Down
3 changes: 2 additions & 1 deletion shared/constants/types/flux.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/* @flow */
import type {TypedState} from '../reducer'

export type TypedAction<T, P, E> = {
error?: false,
Expand All @@ -13,7 +14,7 @@ export type TypedAction<T, P, E> = {
export type NoErrorTypedAction<T, P> = TypedAction<T, P, P>

export type Action = TypedAction<any, any, any>
export type GetState = () => Object
export type GetState = () => TypedState
export type AsyncAction = (dispatch: Dispatch, getState: GetState) => ?Promise<*>
export type Dispatch = (action: AsyncAction | Action) => ?Promise<*>

Expand Down

0 comments on commit 01517dd

Please sign in to comment.