Skip to content

Instantly share code, notes, and snippets.

@GrandSchtroumpf
Created April 12, 2018 12:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save GrandSchtroumpf/6dcd8e0566bae74567542161c75c6646 to your computer and use it in GitHub Desktop.
Save GrandSchtroumpf/6dcd8e0566bae74567542161c75c6646 to your computer and use it in GitHub Desktop.
The NGRX reducers
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