Skip to content

Instantly share code, notes, and snippets.

@lukemorton
Created January 19, 2016 09:11
Show Gist options
  • Save lukemorton/6b377eda5c2e015954af to your computer and use it in GitHub Desktop.
Save lukemorton/6b377eda5c2e015954af to your computer and use it in GitHub Desktop.
import { actions } from 'tarnish';
function handleResponse(form) {
return function ({ token, errors }) {
if (errors) {
return actions.form.validationErrors(form, errors);
} else {
return actions.state.merge({ page: 'home#Index', token });
}
};
}
export function createSession(form) {
return actions.chain(actions.http.post('https://api/sessions.json', form.values),
handleResponse(form));
}
import { actions } from 'tarnish';
export function createSession(form) {
const { errors, token } = actions.http.post('https://api/sessions.json', form.values);
if (errors.length) {
return actions.form.validationErrors(form, errors);
} else {
return actions.state.merge({ page: 'home#Index', token });
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment