Skip to content

Instantly share code, notes, and snippets.

// 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:
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))
// 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,
// 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,
// 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,
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({
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({
@ccorcos
ccorcos / gist:6cf8c9b44bd4ce836c39
Created March 9, 2015 00:34
How to use tracker autorun to queue up events
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()
})
@ccorcos
ccorcos / untitled
Created December 19, 2014 02:30
breadth first search find coffeescript
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
@ccorcos
ccorcos / theano_test.py
Created November 20, 2014 22:57
theano shape error
import theano
import theano.tensor as T
import numpy
# The model basically looks like this:
#
# o_t a_t
# | |
# | |