Declarative AJAX requests and automatic network state management for single-page applications
MIT License
Bot releases are hidden (Show)
Published by klis87 almost 6 years ago
Added reducer operations, which allow you to easier update data
with different actions, as well as giving you error
and pending
state for each operation which you could for instance use to show spinners or error messages. See more info in Readme, as well as new operations example.
Also, removed API for changing naming conventions (BREAKING
), which just made this package more complex than it has to be. Now API is smaller and you don't have a situation where changing a naming convention in your actions forces you to do the same for reducers. So, removed:
getActionWithSuffix
function letting you create your own success
, error
and abort
success
, error
, abort
, successAction
, errorAction
and abortAction
from createRequestInstance
configsuccess
, error
, abort
, dataKey
, errorKey
and pendingKey
from reducer's configsuccess
and getRequestAction
from requestsPromiseMiddleware
configPublished by klis87 about 6 years ago
Updated to Babel 7 and added @babel/runtime
to dependencies, so you don't need to polyfill generators in environments which support them natively anymore.
Published by klis87 about 6 years ago
Updated to Babel 7 and added @babel/runtime
to dependencies, so you don't need to polyfill generators in environments which support them natively anymore.
Published by klis87 about 6 years ago
Updated to Babel 7 and added @babel/runtime
to dependencies, so you don't need to polyfill generators in environments which support them natively anymore.
Published by klis87 about 6 years ago
Updated to Babel 7.
Published by klis87 about 6 years ago
sendRequest
now mutates initial request action by overriding request
key with request you return from onRequest
interceptor - usually it doesn't matter but this change improves consistencysendRequest
gets request action passed as 3rd parameter - this might be only important for people who created their own driversPublished by klis87 about 6 years ago
Initial release of a new driver useful for mocking and testing. See readme for examples and documentation. Make sure you use redux-saga-requests
version at least 0.17.0
.
Published by klis87 about 6 years ago
Updated dev dependencies.
Published by klis87 about 6 years ago
Updated dev dependencies.
Published by klis87 about 6 years ago
This is quite an important release, which refactors how drivers are implemented. This needed to be done to allow developing more powerful drivers in the future. When you upgrade redux-saga-requests
to this version, please also upgrade Axios driver to version 0.7.0
or Fetch API driver to version 0.9.0
(depending on what you use).
Here is the migration path:
import axios from 'axios';
import { createRequestInstance, watchRequests } from 'redux-saga-requests';
- import axiosDriver from 'redux-saga-requests-axios';
+ import { createDriver } from 'redux-saga-requests-axios';
function* rootSaga() {
- yield createRequestInstance(axios, { driver: axiosDriver });
+ yield createRequestInstance({ driver: createDriver(axios) });
yield watchRequests();
}
import 'isomorphic-fetch';
import { createRequestInstance, watchRequests } from 'redux-saga-requests';
- import fetchApiDriver from 'redux-saga-requests-fetch';
+ import { createDriver } from 'redux-saga-requests-fetch';
function* rootSaga() {
- yield createRequestInstance(window.fetch, {
- driver: axiosDriver,
- baseURL: 'https://my-domain.com',
- AbortController: window.AbortController,
+ yield createRequestInstance({
+ driver: createDriver(
+ window.fetch,
+ {
+ baseURL: 'https://my-domain.com',
+ AbortController: window.AbortController,
+ },
+ ),
});
yield watchRequests();
}
Apart from the above:
redux-form-saga
actions where treated as request actions, thx to @EvgeneOskin for #145 !redux-saga-test-plan
, which simplified tests and allowed to reach back 100% test coveragePublished by klis87 about 6 years ago
Internal refactoring, see more info in redux-saga-requests v0.16.0 release.
Published by klis87 about 6 years ago
Internal refactoring, see more info in redux-saga-requests v0.16.0 release.
Published by klis87 about 6 years ago
Added an optional AbortController
support, so fetch request can be trully aborted - previously aborts were just ignored and only abort action was dispatched.
To use it, just pass AbortController
class to createRequestInstance
, like:
yield createRequestInstance(
window.fetch,
{
driver: fetchDriver,
baseURL: 'https://my-domain.com',
AbortController: window.AbortController, // or a ponyfill
},
);
Published by klis87 over 6 years ago
Now streams are automatically read and saved as response.data
, so you never need to use response
methods like response.json()
, response.blob()
etc. This is also done for error instances.
Also, added responseType
null
option, which is useful for responses with no body, like with 204
status code, for which response.json()
would fail, or when you don't care about a response body - then it could you some milliseconds as a json parse won't be done in vain. For example:
const fetchEmptyBody = () => ({
type: 'FETCH_EMPTY_BODY',
request: {
url: '/endpoint',
responseType: null,
},
});
Published by klis87 over 6 years ago
Added possibility to define takeLatest
in watchRequest
as function action => boolean
.
Also (BREAKING
), above enhancement has been used to change takeLatest
default - before it was set to true
for all requests, now it depends on request's method - GET
requests use takeLatest
true
, the rest ones use takeLatest
false
. Usually this is what you need. Most often you are only interested in the latest response of read only GET
requests. However, for side effect requests, like POST
, for example when adding a new comment, you will need to react to all new comment responses, otherwise you could miss some updates. If you don't like it, you can always provide your own takeLatest
implementation in watchRequests
config.
Published by klis87 over 6 years ago
BREAKING
- requestsPromiseMiddleware
doesn't promisify all requests actions automatically anymore. Now you have to add meta.asPromise
to request actions, for example:
const requestAction = {
type: 'FETCH_STH',
request: { url: '/sth' },
meta: { asPromise: true },
};
If you with to revert to previous behaviour, pass auto: true
to requestsPromiseMiddleware
:
requestsPromiseMiddleware({ auto: true });
Big thanks to @mowbell for the idea.
Published by klis87 over 6 years ago
Fixed a crash when an action had a structure { type: 'TYPE': payload: null }
, thanks to @EvgeneOskin!
Published by klis87 over 6 years ago
Fixed bug when using Axios driver - action with request error was incorrectly interpret as a request. There was a similar issue #101 already solved, but it exluded response errors, it didn't consider potential request error, due to lack of internet connection for instance. Details can be seen in #133. Big thanks to @nemosupremo for spotting and fixing this issue!
Published by klis87 over 6 years ago
A small change of default onRequest
handler in requestsReducer
- it doesn't touch data
anymore, it only resets error
and updates pending
counter.
Published by klis87 over 6 years ago
Reduced bundle size thanks to upgrade to Webpack 4 (only for UMD build).