Skip to content

Instantly share code, notes, and snippets.

@oguzgelal
Last active September 25, 2018 13:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save oguzgelal/844c361f09c76d1551fffd2e4c498b5c to your computer and use it in GitHub Desktop.
Save oguzgelal/844c361f09c76d1551fffd2e4c498b5c to your computer and use it in GitHub Desktop.
{
on: 'login_submitted',
when: ({ event }) => isValid(event.email, event.password),
reaction: ({ event }) => broadcast('on_request', {
type: 'login',
path: '/api/login',
params: { ...event }
}),
reactionElse: () => alert('Invalid parameters'),
},
{
on: 'request_success',
when: ({ event }) => event.type === 'login',
reducer: ({ state, event }) => ({ ...state, user: event.user }),
reaction: () => broadcast('on_route_change', { to: 'dashboard' })
},
{
on: 'request_fail',
when: ({ event }) => event.type === 'login',
reaction: ({ event }) => alert(`Failed: ${event.message}`)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment