Created
October 10, 2018 01:33
-
-
Save peatiscoding/d91e1c4b26e2ff44acc84343ac67f89d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// store/session/actions.ts | |
import { AnyAction } from 'redux'; | |
export interface SetAction { | |
type: 'SET' | |
accessToken: string | |
} | |
export interface Fetching { | |
type: 'SET_FETCHING' | |
isFetching: boolean | |
} | |
export type Action = SetAction | Fetching | |
export const set = (accessToken: string): SetAction => { | |
return { type: 'SET', accessToken } | |
} | |
export const isFetching = (isFetching: boolean): Fetching => { | |
return { type: 'SET_FETCHING', isFetching } | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// store/index.ts | |
import { createStore, combineReducers, applyMiddleware } from 'redux' | |
import sessions, { State as SessionsState } from './session/reducers' | |
export interface RootState { | |
sessions: SessionsState | |
} | |
export default createStore(combineReducers({ | |
sessions | |
})) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// store/session/reducers.ts | |
import { combineReducers } from 'redux' | |
import { Action } from './actions' | |
export interface AccessToken { | |
isFetching: boolean | |
accessToken?: string | |
} | |
export interface State { | |
accessToken: AccessToken | |
} | |
const accessToken = (state = { isFetching: false }, action: Action): AccessToken => { | |
switch (action.type) { | |
case 'SET': | |
return { ...state, accessToken: action.accessToken } | |
case 'SET_FETCHING': | |
return { ...state, isFetching: action.isFetching } | |
} | |
return state | |
} | |
export default combineReducers<State>({ | |
accessToken | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment