This version contains the following breaking changes:
- The middleware now requires an
adapter
to be initialized requestWithKey
andsetFromRequest
have been removedstubRequest
has been renamed tocreateStubRequest
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)
)
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'),
}