Created
April 12, 2018 12:13
-
-
Save GrandSchtroumpf/6dcd8e0566bae74567542161c75c6646 to your computer and use it in GitHub Desktop.
The NGRX reducers
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
import { GET_ACCOUNTS_SUCCESS, SELECT_ACCOUNT, AccountsActions } from './eth.actions'; | |
export interface State { | |
selected: string, | |
accounts: string[] | |
} | |
const initialState: State = { | |
selected: null, | |
accounts: [] | |
} | |
export const reducers = (state = initialState, action: AccountsActions): State => { | |
switch (action.type) { | |
case (GET_ACCOUNTS_SUCCESS): { | |
return {...state, accounts: action.payload }; | |
}; | |
case (SELECT_ACCOUNT): { | |
return {...state, selected: action.payload }; | |
}; | |
default: { | |
return state; | |
} | |
} | |
} | |
/** | |
* Ethereum Global State | |
*/ | |
export interface EthState { | |
eth: State | |
} | |
export const ethReducer: ActionReducerMap<EthState> = { | |
eth: reducers | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment