Skip to content

Latest commit

 

History

History
88 lines (60 loc) · 1.96 KB

v6.0.0.md

File metadata and controls

88 lines (60 loc) · 1.96 KB

v6.0.0 Migration Guide

This version contains the following breaking changes:

  1. The middleware now requires an adapter to be initialized
  2. requestWithKey and setFromRequest have been removed
  3. stubRequest has been renamed to createStubRequest

Adapter

The main breaking change in this version is that middleware now requires an adapter when it is initialized:

applyMiddleware(
  middleware(adapter, options)
)

The adapter is a function that will be used to execute each request you make. It receives the options passed by your action creators and returns a promise.

Previous version(s) of this library used lp-requests by default to make requests. To continue using this library, simply pass the http module as the adapter:

// Important note: this requires lp-requests@>=4.

import { http } from 'lp-requests'

const defaultOptions = { ... }

applyMiddleware(
  middleware(http, defaultOptions)
)

However, you are also free to use any adapter you like, as long as it fits the defined interface:

import axios from 'axios'

const defaultOptions = { ... }

applyMiddleware(
  middleware(axios, defaultOptions)
)

Removed functions

The following deprecated functions have been removed from this library:

  • requestWithKey
  • setFromRequest

You can replace these function with the following functions respectively:

  • createRequest
  • setOnSuccess

Here's an example of this replacement:

// apiActions.js

- const REQ_USER = 'REQ_USER'

- function fetchUser (id) {
-   return requestWithKey(REQ_USER, {
-     url: '/users/' + id,
-   })
- }

+ const fetchUser = createRequest('FETCH_USER', (id) => ({
+   url: '/users/' + id,
+ }))

// reducer.js

const reducer = handleActions({
-   ...setFromRequest(apiActions.REQ_USER, 'user'),
+   [apiActions.fetchUser]: setOnSuccess('user')
})

...

const selectors = {
-  user: select('user.success'),
+  user: select('user'),
}