Skip to content

Instantly share code, notes, and snippets.

@kamescg
Created July 2, 2018 00:32
Show Gist options
  • Save kamescg/49f4797094c9d9ebc4a6dd63f7b6e18f to your computer and use it in GitHub Desktop.
Save kamescg/49f4797094c9d9ebc4a6dd63f7b6e18f to your computer and use it in GitHub Desktop.
A demonstration of simplified Redux reducers using a delta identifier.
import { initialState } from './selectors'
import actions from './actions'
export default (state = initialState, {type, payload, metadata, batch, entity} ) => {
if(!!(metadata && metadata.delta) && entity === 'ethers') {
return {
...state,
[metadata.delta]: {
...state[metadata.delta],
status: {
REQUESTED: undefined,
SUCCESS: true,
FAILURE: false
}[batch],
data: payload
}
}
} else{
switch (type) {
case actions.PROVIDER_CHANGE:
return {
...state,
provider: payload
}
case actions.CHAIN_CHANGE:
return {
...state,
chain: payload
}
case actions.JSONRPC_URL_CHANGE:
return {
...state,
url: payload
}
default:
return state
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment