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-requests/core v1.1.1

Published by klis87 about 4 years ago

Made type property or RequestAction interface optional. When it is required, for some reason Typescript complains when using it with redux-smart-actions, it might be a Typescript bug but for now this is enough to make things work.

redux-requests - @redux-requests/react v1.1.0

Published by klis87 about 4 years ago

The same as in the @redux-requests/core v1.1.0, just for useQuery and Query.

redux-requests - @redux-requests/core v1.1.0

Published by klis87 about 4 years ago

Massively improved Typescript types. Added generics to RequestAction type, so that you can define data structure there, for example:

import { RequestAction } from '@redux-requests/core';

const fetchBooks: () => RequestAction<
  { raw: boolean },
  { parsed: boolean }
> = () => {
  return {
    type: 'FETCH_BOOKS',
    request: {
      url: '/books',
    },
    meta: {
      getData: data => ({ parsed: data.raw }),
    },
  };
};

2nd generic defaults to 1st, it is useful when you transform data in getData.

Ok, but why do we even care? It would be easy to just add types to getData if we needed.

The answer is, that those data types are now automatically inferred in querySelector and getQuerySelector if you define request actions with libraries like redux-smart-actions, redux-act or redux-actions - that's it, when you don't write constants and you pass actions themselves as type.

So, if you do:

import { RequestAction } from '@redux-requests/core';
import { createSmartAction } from 'redux-smart-actions';

const fetchBooks: () => RequestAction<
  { raw: boolean },
  { parsed: boolean }
> = createSmartAction(() => {
  return {
    request: {
      url: '/books',
    },
    meta: {
      getData: data => ({ parsed: data.raw }),
    },
  };
});

then if you use getQuery:

const booksQuery = getQuery(state, { type: fetchBooks });

then booksQuery.data will be automatically typed! Even if you have only fetchBooks written in typescript, but for some reason getQuery is in js file, then still you will get this like autocomplete for free! So the point is, add type only in request actions and enjoy types automatically everywhere you read query state.

redux-requests - @redux-requests/core v1.0.0

Published by klis87 about 4 years ago

First major release! This is really the same as the previous version, just some dependencies like Babel or Webpack were updated so it should be safe to upgrade.

redux-requests - @redux-requests/core v0.31.0

Published by klis87 over 4 years ago

  • changed function signature of clearRequestsCache to match abortRequests and resetRequests for consistence
  • allowed possibility to add more keys to response than data in batched requests
  • moved docs to https://redux-requests.klisiczynski.com
redux-requests - @redux-requests/fetch v0.12.0

Published by klis87 over 4 years ago

Added headers and status keys to response (next to data).

redux-requests - redux-requests/axios v0.10.0

Published by klis87 over 4 years ago

Added headers and status keys to response (next to data).

redux-requests - @redux-requests/graphql v0.4.2

Published by klis87 over 4 years ago

Fixed request abort handling, which was not properly propagated to the core.

redux-requests - @redux-requests/mock v0.4.0

Published by klis87 over 4 years ago

Successful responses and errors are defined in actions themselves, not passed to createDriver anymore.

redux-requests - @redux-requests/core v0.30.1

Published by klis87 over 4 years ago

  • added meta.cacheKey - if it changes, cache is invalidated
  • added showcase example
  • added logo - thx to @strdr4605 and his friend!
redux-requests - @redux-requests/core v0.29.1

Published by klis87 over 4 years ago

  • fixed onRequest which did not work properly for FSA actions (when you have action.payload.request not action.request)
  • removed babel regenerator-runtime from all packages so bundles for some packages are smaller
redux-requests - @redux-requests/core v0.29.0

Published by klis87 over 4 years ago

  • added pristine flag to queries - you could see it with getQuery for instance, it was added to distinguish between situations where data is null because no request for a given query was made yet or because truly server response is null
  • resetRequests also resets pristine to true
  • improved SSR, now you can have mutliple error actions on the server, so for instance you can have 404 error, still render React on the server and error will be passed to the client, it might require onError interceptor to adjust how errors are structured, because error has to be serializable in order to pass it to the client
redux-requests - @redux-requests/core v0.28.2

Published by klis87 over 4 years ago

Dispatch of requests actions now rejects promise in case of a syntax error (not related to network issues) not to swallow those errors. Now they should be visible in console.

redux-requests - @redux-requests/core v0.28.1

Published by klis87 over 4 years ago

Fixed some problems with FSA actions after removing sagas.

redux-requests - @redux-requests/core v0.28.0

Published by klis87 over 4 years ago

As you probably noticed, we just moved to scoped npm packages. Also, we removed redux-saga from dependencies! So you don't have to use redux-saga anymore with this project, albeit it is totally compatible with redux-saga.

What changed:

  • the library logic no longer uses sagas, now it is based only on pure promises and redux middleware
  • due to migration to scoped packages, you need to replace redux-saga-requests with @redux-requests/core, redux-saga-requests-axios with @redux-requests/axios and so on
  • new promise driver, thx @strdr4605 for the idea and implementation and very clever idea to use AbortController to make it abortable!
  • because sagas were removed, sendRequest does not exist anymore, but it is not needed, just dispatch request action, and if you need a response, await promise to be resolved, also all interceptor based options etc are handled by action.meta
  • again, due to removing sagas, handleRequests does not return requestsSagas anymore
  • changed interceptors to be promised based
  • added local interceptors, so for instance you can have action.meta.onResponse interceptor only for a specific action
  • meta.getData has currentData passed as 2nd argument in case you need it
  • pending counter for cached and ssr actions is not updated, which improves performance and prevents ssr flickering
  • removed meta.asPromise, promisify and autoPromisify from handleRequests, because all requests are always promisified, this doesn't hurt, simplifies API and allows you to dispatch actions instead of sendRequest without any worry
  • related to above, no matter what result, whether success, error or abort, dispatching of request actions always returns promise which will be resolved, never rejected, see https://github.com/klis87/redux-requests#promisified-dispatches for usage and justification
  • added new abortRequests action and at the same time removed onAbort
  • resetRequests aborts actions by default, you can change this by passing false as 2nd argument
  • fixed TS type for getQuerySelector and getMutationSelector
redux-requests - @redux-requests/promise v0.1.1

Published by klis87 over 4 years ago

A new driver, useful if you connect if an API with a promise based libraries or functions. See https://github.com/klis87/redux-requests/tree/master/packages/redux-requests-promise

redux-requests - redux-saga-requests-axios v0.8.0

Published by klis87 over 4 years ago

See redux-saga-requests v0.27.0

redux-requests - redux-saga-requests-fetch v0.10.0

Published by klis87 over 4 years ago

See redux-saga-requests v0.27.0

redux-requests - redux-saga-requests-graphql v0.3.0

Published by klis87 over 4 years ago

See redux-saga-requests v0.27.0

redux-requests - redux-saga-requests-mock v0.2.0

Published by klis87 over 4 years ago

See redux-saga-requests v0.27.0

Package Rankings
Top 2.88% on Npmjs.org
Badges
Extracted from project README
npm version gzip size dependencies dev dependencies peer dependencies Build Status Coverage Status Known Vulnerabilities lerna code style: prettier