Skip to content

Instantly share code, notes, and snippets.

@justin808
Last active September 11, 2016 02:25
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 justin808/b83f1803b389911605edab0b4a073bd9 to your computer and use it in GitHub Desktop.
Save justin808/b83f1803b389911605edab0b4a073bd9 to your computer and use it in GitHub Desktop.

Redux

  1. Use Immutable.js for non primitives, such as lists, objects, maps, etc.
  2. Store keys of Immutable.js values should be named with prefix $$ Store should be of the shape:
export type StoreType = {
  $$commentsStore: $$Map<string, any>,
  $$profileStore: $$Map<string, any>,
};

Action Creators

This is boilerplate code that creates Redux "actions". These a functions to initiate a mesasge to Redux, which can update the store via reducers, kick off a redux saga, trigger other middleware, etc.

Each action creator has the following parts:

  1. actionType: Unique string which identifies the action. All the redux listeners will use this actionType.
  2. List of param values.

Selectors

Functions of the form (flow syntax)

(store: {}) => {}

Notes:

  1. Store contains Immutable.js
  2. Selectors convert Immutable, like this: (store) => store.$$somePartOfStore.toJS()
  3. Note that we know that toJS is on the $$somePartOfStore, as it's named with the $$
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment