Skip to content

Latest commit

 

History

History
60 lines (48 loc) · 1.42 KB

awesome-redux.md

File metadata and controls

60 lines (48 loc) · 1.42 KB
title category
Awesome-redux
Ruby

Create action creators in flux standard action format.

increment = createAction('INCREMENT', amount => amount)
increment = createAction('INCREMENT')  // same

err = new Error()
increment(42) === { type: 'INCREMENT', payload: 42 }
increment(err) === { type: 'INCREMENT', payload: err, error: true }

A standard for flux action objects.

{ type: 'ADD_TODO', payload: { text: 'Work it' } }
{ type: 'ADD_TODO', payload: new Error(), error: true }

An action may have an error, payload and meta and nothing else.

Pass promises to actions. Dispatches a flux-standard-action.

increment = createAction('INCREMENT')  // redux-actions
increment(Promise.resolve(42))

Pass side effects declaratively to keep your actions pure.

{
  type: 'EFFECT_COMPOSE',
  payload: {
    type: 'FETCH'
    payload: {url: '/some/thing', method: 'GET'}
  },
  meta: {
    steps: [ [success, failure] ]
  }
}

Dispatch multiple actions in one action creator.

store.dispatch([
  { type: 'INCREMENT', payload: 2 },
  { type: 'INCREMENT', payload: 3 }
])