Skip to content

Migration from v3 to v4

Didier Franc edited this page Jul 2, 2018 · 1 revision

Why should I update ?

  • Rewrited from scratch
  • Just code, nothing else
  • Consecutive actions calls
  • Explicit naming, always easier
  • Redux devtools integration by default
  • Tons of improvements, experience from the v3

How to ?

Let's start with the basic counter example

v3

import { initStore } from 'react-waterfall'

const store = {
  initialState: {
    count: 0
  },
  actions: {
    increment: ({ count }) => ({ count: count + 1 })
  }
}

export const { Provider, Consumer, actions, getState, connect, subscribe } = initStore(store)

v4

import createStore from 'react-waterfall' // You'll get only one default export

const config = {
  initialState: { count: 0 },
  actionsCreators: { // `actions` has been renamed to `actionsCreators`, because it's not an actions yet
    increment: ({ count }) => ({ count: count + 1 }),
  },
}

export const { Provider, connect, actions } = createStore(config) 
// Some store methods have been removed to enforce you to use connect for example

What's new ?

  • Actions are available as the second argument of actionsCreators: (state, actions, ...args) => state, a great example here. It's a great improvement for multi-stage action and asynchronous stuff.
  • Consecutive actions call work very well thanks to a simple trick
  • Every action call return a Promise
  • You can provide a state to <Provider />
<Provider initialState={state}>
  <App />
</Provider>
Clone this wiki locally