Upgrade to Pro — share decks privately, control downloads, hide ads and more …

How to Write Bad Code in Redux

Avatar for adam klein adam klein
November 11, 2018

How to Write Bad Code in Redux

We've been using Redux since it just started, and we learned a lot from dozens of projects, big and small.
This is a taste of a collection of tools and best practices that work great for us.

Avatar for adam klein

adam klein

November 11, 2018
Tweet

More Decks by adam klein

Other Decks in Programming

Transcript

  1. Reducers import { handleActions } from 'redux-actions'; const myReducer =

    handleActions( { [MY_ACTION]: (state: MyState, action: MyAction): MyState => set('key', action.payload, state) }, ... );
  2. Reducers import { handleActions } from 'redux-actions'; const myReducer =

    handleActions( { [MY_ACTION]: (state: MyState, action: MyAction): MyState => set('key', action.payload, state) }, ... );
  3. { users: { 1: { id: 1, name: 'User1' },

    2: { id: 2, name: 'User2' } }, selectedUserIds: { 1: true } } State Design
  4. { users: { 1: { id: 1, name: 'User1' },

    2: { id: 2, name: 'User2' } }, selectedUserIds: { 1: true } } State Design
  5. { users: { 1: { id: 1, name: 'User1' },

    2: { id: 2, name: 'User2' } }, selectedUserIds: { 1: true } } Reload server data State Design
  6. { users: { 1: { id: 1, name: 'User1' },

    2: { id: 2, name: 'User2' } }, selectedUserIds: { 1: true } } Save & restore from
 Localstorage State Design
  7. State Design { users: { pendingRequests: 1, data: { ...

    } }, groups: { pendingRequests: 1, data: { ... } } } { network: { users: 0, groups: 0 } }