redux-requests

Declarative AJAX requests and automatic network state management for single-page applications

MIT License

Downloads
24.1K
Stars
367
Committers
15

Bot releases are hidden (Show)

redux-requests - redux-saga-requests v0.18.0

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 config
  • success, error, abort, dataKey, errorKey and pendingKey from reducer's config
  • success and getRequestAction from requestsPromiseMiddleware config
redux-requests - redux-saga-requests v0.17.1

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.

redux-requests - redux-saga-requests-mock v0.1.1

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.

redux-requests - redux-saga-requests-fetch v0.9.2

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.

redux-requests - redux-saga-requests-axios v0.7.2

Published by klis87 about 6 years ago

Updated to Babel 7.

redux-requests - redux-saga-requests v0.17.0

Published by klis87 about 6 years ago

  • added multiple driver support, useful especially with new mock driver
  • 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 consistency
  • now driver's sendRequest gets request action passed as 3rd parameter - this might be only important for people who created their own drivers
redux-requests - redux-saga-requests-mock v0.1.0

Published 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.

redux-requests - redux-saga-requests-fetch v0.9.1

Published by klis87 about 6 years ago

Updated dev dependencies.

redux-requests - redux-saga-requests-axios v0.7.1

Published by klis87 about 6 years ago

Updated dev dependencies.

redux-requests - redux-saga-requests v0.16.0

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:

  • for Axios:
  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();
  }
  • for Fetch API:
  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:

  • fixed a bug in which redux-form-saga actions where treated as request actions, thx to @EvgeneOskin for #145 !
  • refactored tests to redux-saga-test-plan, which simplified tests and allowed to reach back 100% test coverage
redux-requests - redux-saga-requests-fetch v0.9.0

Published by klis87 about 6 years ago

Internal refactoring, see more info in redux-saga-requests v0.16.0 release.

redux-requests - redux-saga-requests-axios v0.7.0

Published by klis87 about 6 years ago

Internal refactoring, see more info in redux-saga-requests v0.16.0 release.

redux-requests - redux-saga-requests-fetch v0.8.0

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
    },
  );
redux-requests - redux-saga-requests-fetch v0.7.0

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,
  },
});
redux-requests - redux-saga-requests v0.15.0

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.

redux-requests - redux-saga-requests v0.14.0

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.

redux-requests - redux-saga-requests v0.13.2

Published by klis87 over 6 years ago

Fixed a crash when an action had a structure { type: 'TYPE': payload: null }, thanks to @EvgeneOskin!

redux-requests - redux-saga-requests v0.13.1

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!

redux-requests - redux-saga-requests v0.13.0

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.

redux-requests - redux-saga-requests v0.12.2

Published by klis87 over 6 years ago

Reduced bundle size thanks to upgrade to Webpack 4 (only for UMD build).