Created
August 29, 2016 23:35
-
-
Save ccorcos/4594418d305b4795a2a18b2b5e1de18b 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
// mutators.js | |
export const closeModal = s => s.set('modalOpen', false) | |
export const stopLoading = s => s.set('loading', false) | |
export const updateLoan = loan => s => s.setIn(['loans', loan.id], Immutable.fromJS(loan)) | |
export const setPaymentError = error => s => s.set('paymentError', error) | |
// utils.js | |
const applyFn = (state, fn) => fn(state) | |
export const pipe = (fns, state) => | |
state.withMutations(s => fns.reduce(applyFn, s)) | |
// reducer.js | |
import * as mutate from './mutators' | |
export default function reducer(state=initialState, action) { | |
switch(action.type) { | |
case defs.MAKE_PAYMENT_SUCCESS: | |
return pipe([ | |
mutate.closeModal, | |
mutate.stopLoading, | |
mutate.updateLoan(action.loan), | |
], state) | |
case defs.MAKE_PAYMENT_FAILED: | |
return pipe([ | |
mutate.closeModal, | |
mutate.stopLoading, | |
mutate.setPaymentError(action.error), | |
], state) | |
// ... | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment