Skip to content

Instantly share code, notes, and snippets.

@laat
Last active April 26, 2016 11:57
Show Gist options
  • Save laat/568959702e74d49c6ebff7de76fb11c2 to your computer and use it in GitHub Desktop.
Save laat/568959702e74d49c6ebff7de76fb11c2 to your computer and use it in GitHub Desktop.

forces

Forces always come in pairs - known as "action-reaction force pairs."

It is basically the same concept as redux-modular-ducks but with a less loaded term in programming circles.

rules

A force:

  1. MUST export default a function called reducer()
  2. MUST export its action creators as functions
  3. MAY export its action types as UPPER_SNAKE_CASE, if an external reducer needs to listen for them, or if it is a published reusable library

example

// message.js

const SHOW = 'my-app/message/SHOW';
const HIDE = 'my-app/message/HIDE';

export default function reducer(state = {}, action = {}) {
  switch (action.type) {
    // do reducer stuff
    default: return state;
  }
}

export function showMessage() {
  return { type: SHOW };
}

export function hideMessage() {
  return { type: HIDE };
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment