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 visible (Hide)

redux-requests - redux-saga-requests-react v0.3.0

Published by klis87 over 4 years ago

See redux-saga-requests v0.27.0

redux-requests - redux-saga-requests v0.27.0

Published by klis87 over 4 years ago

It was a long time since the last release, it was for a reason. This is a very big release,
which is the first step to achieve 1.0 version. It was not splited into smaller releases
not to trouble you constantly with breaking changes plus many things depended on each other.

The easiest way to see what changed is just to quickly read new Readme actually.
But to give you some hints, those are most notable changes:

  • removed watchRequests, requestsReducer, networkReducer, all middleware from public API, it was replaced
    by handleRequests function which returns all the necessary pieces like reducer, saga, middleware in the right order etc, which simplifies usage, and requires less documentation
  • handleRequests returns requestsReducer, but this is actually old networkReducer, old requestsReducer is not supported anymore, in order to support new features it had to be removed, not to mention supporting two different APIs was very bad for maintenance and docs
  • added automatic but optional data normalisation, similar to GraphQL Apollo but for any API, including REST!
  • refactored drivers to simple promises (actually cancellable promises like in Bluebird)
  • getQuery and getMutation are actually selectors now, not selector creators, selector creators are available as
    getQuerySelector and getMutationSelector
  • query and mutation selectors are memoized per action type and even request key, you don't need to worry about using selectors in multiple places or in components directly anymore, there is just not possible to invalidate cache by accident
  • removed meta.resetOn, replaced it with resetRequests action
  • simplified meta.getData and meta.updateData payload, see docs or examples for current usage
  • cache and SSR state is kept in reducer, so usage is simplified and for instance cache is compatible with SSR
  • mutations work for cached queries and together with requestKey
  • reducer is pure function now, it doesn't have any internal state, so time travel works now and also
    you can use JS closures in meta.getData etc in request actions
  • removed meta.mutations[TYPE].getRequestKey and replaced it with meta.requestKey
  • meta.requestKey is also possible for queries, so you can store data for query with the same type independently
  • meta.cacheKey was removed, as meta.requestKey serves the same purpose, but with or without cache
  • replaced meta.cacheSize with meta.requestsCapacity due to the same reason
  • sendRequest usage is encouraged only in intereceptors, also dispatchRequestAction default is true
  • successful response contains only data for now, no headers or status, usually we care about those
    in error responses, possibly this will be updated in the furure, for now it had to be standardized for cache feature
redux-requests - redux-saga-requests-react v0.2.1

Published by klis87 about 5 years ago

Fixed incorrect useMemo dependencies array in useQuery and useMutation, which could cause some update issues on prop changes or PureComponent optimisations.

redux-requests - redux-saga-requests v0.26.0

Published by klis87 about 5 years ago

This is a very big release related to new networkReducer, which is a manager of requestsReducers, so you won't need to write reducers for remote state anymore. Its introducing was followed with below changes:

  • introduced concept of queries and mutations (old operations), queries are requests which fetch data like GET requests, mutations can change data and usually they use methods like POST, PUT, DELETE, PATCH
  • removed redundant createRequestsReducer as you could just create requestsReducer wrapper with functional programming technique
  • removed possibility to merge requestsReducer with a custom reducer, just use a separate reducer instead and merge them with selectors if needed
  • added local mutations (previously we would call them as local operations), so that you can update data with ordinary actions, not only request ones
  • added networkReducer which you can read about in the docs, I recommend to use it as probably requestsReducer will be removed in future versions
  • added getQuery and getMutation selector creators, useful especially with networkReducer, so you don't need to write selectors for your remote data manually, it requires reselect 4 as peer dependency so make sure you have it installed
redux-requests - redux-saga-requests-react v0.2.0

Published by klis87 about 5 years ago

Changes too big to mentioned here, but related to redux-saga-requests update to 0.26.0. So only update redux-saga-requests-react to 0.2.0 only if you upgraded redux-saga-requests to 0.26.0. Please refer docs to see how new API looks like, but we could sum up changes in the following points:

  • renamed Operation into Mutation and RequestContainer into Query to match core library naming convention
  • added React hooks useQuery and useMutation
  • removed connected components versions as Query and Mutation are connected by default
redux-requests - redux-saga-requests-graphql v0.2.0

Published by klis87 about 5 years ago

Added headers support, useful especially for authentication.

redux-requests - redux-saga-requests v0.25.0

Published by klis87 over 5 years ago

Added server side rendering support with countServerRequests and serverRequestsFilterMiddleware.

redux-requests - redux-saga-requests v0.24.1

Published by klis87 over 5 years ago

Performance and memory usage optimizations in requestsReducer. Thanks @megawac !

redux-requests - redux-saga-requests v0.24.0

Published by klis87 over 5 years ago

Improved cache support, namely added possibility to define cacheKey and cacheSize next to cache in action meta, which allows to keep separate caches within the same request type per defined key. For instance:

const fetchBook = id => ({
  type: FETCH_BOOK,
  request: { url: `/books/${id}`},
  meta: {
    cache: true,
    cacheKey: id, // must be string
    cacheSize: 2 // optional with defined cacheKey to avoid cache growing too big
  },
});

To achieve caching per key, internal caching implementation had to be changed a little, so in contract to previous version, now request and response actions are dispatched even when there is cache hit. Probably it won't affect you, but it might be useful to know. At the same time, sendRequest will also return success response from cache, no { cacheHit: true } object.

There is another small change regarding success action structure, namely now the whole server response is added to action, not only data, for instance:

{
  type: 'DELETE_BOOK_SUCCESS',
  response: { data: 'some data' },
  data: 'some data',
  meta: {
    id: 1, // got from request action meta
    requestAction: {
      type: 'DELETE_BOOK',
      request: {
        url: '/books/1',
        method: 'delete'
      },
      meta: {
        id: 1,
      },
    },
  },
}
redux-requests - redux-saga-requests v0.23.1

Published by klis87 over 5 years ago

Allow using any action in resetOn of requestsReducer. Previously you couldn't use request action (which u pass to actionType, or any response matching action (success, error, or abort), because reset case returned earlier, so request/response logic wasn't even executed.

Thanks to @megawac for the idea and PR!

redux-requests - redux-saga-requests v0.23.0

Published by klis87 over 5 years ago

Added getDefaultData to requestsReducer config. Use instead of multiple, if you want your initial data to be something else than null or [], for instance () => ({ value: null }), set as multiple => (multiple ? [] : null) by default, so this is backward compatible change.

Thanks to @megawac for the idea and PR!

redux-requests - redux-saga-requests-react v0.1.0

Published by klis87 over 5 years ago

First release of new React bindings to redux-saga-requests. See https://github.com/klis87/redux-saga-requests/tree/master/packages/redux-saga-requests-react for more info.

redux-requests - redux-saga-requests v0.22.0

Published by klis87 almost 6 years ago

Small changes which allowed adding GraphQL driver:

  • by default GraphQL queries are run as takeLatest (like REST GET), mutations as takeEvery (like REST POST PUT DELETE etc.)
  • actions with request.query are recognized as request actions
redux-requests - redux-saga-requests-graphql v0.1.0

Published by klis87 almost 6 years ago

A new driver which allows to use redux-saga-requests with GraphQL! See docs and example for more info. It requires redux-saga-requests at least 0.22.0 version.

redux-requests - redux-saga-requests-mock v0.1.5

Published by klis87 almost 6 years ago

Updated Typescript types

redux-requests - redux-saga-requests-fetch v0.9.6

Published by klis87 almost 6 years ago

Updated Typescript types.

redux-requests - redux-saga-requests-axios v0.7.6

Published by klis87 almost 6 years ago

Updated Typescript types.

redux-requests - redux-saga-requests v0.21.0

Published by klis87 almost 6 years ago

redux-requests - redux-saga-requests v0.20.0

Published by klis87 almost 6 years ago

Added support to redux-saga 1.0.0-beta version. Note, that this is a backward compatible change, it still supports 0.16 version!

redux-requests - redux-saga-requests v0.19.0

Published by klis87 almost 6 years ago

  • allowed explicit meta.asPromise: false to overwrite requestsPromiseMiddleware with auto for a given action, thanks to @nemosupremo for the idea and PR!
  • added action meta.runByWatcher flag, which can be used to disable handling it by watchRequests, which is by the way used by default for sendRequest with dispatchRequestAction: true to avoid duplicated requests when you use both watchRequests and sendRequest
  • removed per action config in watchRequests, so if you need to override global abortOn and takeLatest for an action, you can use meta, for example:
const fetchBooks = () => ({
  type: FETCH_BOOKS,
  request: {
    url: '/books',
  },
  meta: {
    takeLatest: false,
    abortOn: 'LOGOUT',
  },
});
  • improved default runOn... options of sendRequests, so for most cases you don't even need to worry about them, see more details in readme