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
match = (obj, properties) -> | |
for k,v of properties | |
if not k of obj | |
return false | |
else if v instanceof Object | |
if not match obj[k], v | |
return false | |
else if obj[k] isnt v | |
return false | |
return true |
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
var a = {} | |
var b = new ReactiveVar(1); | |
var c = new ReactiveVar(2); | |
var needsUpdate = new Tracker.Dependency() | |
Tracker.autorun(function(){ | |
a.b = b.get() | |
needsUpdate.changed() | |
}) |
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
export function makePayment(loanId, amount, paymentMethodId) { | |
return dispatch => { | |
dispatch(makePaymentSent()) | |
fetch(`/api/loans/${loanId}/payments`, { | |
headers: new Headers({ | |
'Content-Type': 'application/json', | |
}), | |
credentials: 'same-origin', | |
method: 'POST', | |
body: JSON.stringify({ |
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
// api.js | |
export function makePayment(loanId, amount, paymentMethodId) { | |
return fetch(`/api/loans/${loanId}/payments`, { | |
headers: new Headers({ | |
'Content-Type': 'application/json', | |
}), | |
credentials: 'same-origin', | |
method: 'POST', | |
body: JSON.stringify({ | |
'amount': amount, |
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
// api.js | |
export function makePayment(loanId, amount, paymentMethodId) { | |
return fetch(`/api/loans/${loanId}/payments`, { | |
headers: new Headers({ | |
'Content-Type': 'application/json', | |
}), | |
credentials: 'same-origin', | |
method: 'POST', | |
body: JSON.stringify({ | |
'amount': amount, |
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
// api.js | |
export function makePayment(loanId, amount, paymentMethodId) { | |
return fetch(`/api/loans/${loanId}/payments`, { | |
headers: new Headers({ | |
'Content-Type': 'application/json', | |
}), | |
credentials: 'same-origin', | |
method: 'POST', | |
body: JSON.stringify({ | |
'amount': amount, |
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
export function makePayment(loanId, amount, paymentMethodId) { | |
return async dispatch => { | |
dispatch(makePaymentSent()) | |
const response = await api.makePayment(loanId, amount, paymentMethodId) | |
dispatch(closeModal()) | |
if (response.status !== 200) { | |
dispatch(makePaymentFailed(response.statusText)) | |
} else { | |
const result = await response.json() | |
dispatch(makePaymentSuccess(result.data)) |
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
// reducer.js | |
export default function reducer(state=initialState, action) { | |
switch(action.type) { | |
case defs.MAKE_PAYMENT_SUCCESS: | |
return state.withMutations(s => | |
s.set('modalOpen', false) | |
.set('loading', false) | |
.setIn(['loans', action.loan.id], Immutable.fromJS(action.loan)) | |
) | |
case defs.MAKE_PAYMENT_FAILED: |
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
// actions/sync.js | |
export const makePaymentSent = () => ({ | |
type: defs.MAKE_PAYMENT_SENT, | |
}) | |
export const makePaymentFailed = (error) => ({ | |
type: defs.MAKE_PAYMENT_FAILED, | |
error, | |
}) | |
export const makePaymentSuccess = (loan) => ({ | |
type: defs.MAKE_PAYMENT_SUCCESS, |
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
export default function reducer(state=initialState, action) { | |
switch(action.type) { | |
case defs.MAKE_PAYMENT_SUCCESS: | |
return state.withMutations(s => | |
s.set('modalOpen', false) | |
.set('loading', false) | |
.setIn(['loans', action.loan.id], Immutable.fromJS(action.loan)) | |
) | |
case defs.MAKE_PAYMENT_FAILED: | |
return state.withMutations(s => |