Declarative AJAX requests and automatic network state management for single-page applications
MIT License
Bot releases are hidden (Show)
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.
Published by klis87 about 4 years ago
The same as in the @redux-requests/core v1.1.0
, just for useQuery
and Query
.
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.
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.
Published by klis87 over 4 years ago
clearRequestsCache
to match abortRequests
and resetRequests
for consistencedata
in batched requestsPublished by klis87 over 4 years ago
Added headers
and status
keys to response (next to data
).
Published by klis87 over 4 years ago
Added headers
and status
keys to response (next to data
).
Published by klis87 over 4 years ago
Fixed request abort handling, which was not properly propagated to the core.
Published by klis87 over 4 years ago
Successful responses and errors are defined in actions themselves, not passed to createDriver
anymore.
Published by klis87 over 4 years ago
meta.cacheKey
- if it changes, cache is invalidatedPublished by klis87 over 4 years ago
onRequest
which did not work properly for FSA actions (when you have action.payload.request
not action.request
)Published by klis87 over 4 years ago
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
onError
interceptor to adjust how errors are structured, because error has to be serializable in order to pass it to the clientPublished 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.
Published by klis87 over 4 years ago
Fixed some problems with FSA actions after removing sagas.
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:
redux-saga-requests
with @redux-requests/core
, redux-saga-requests-axios
with @redux-requests/axios
and so onsendRequest
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.metahandleRequests
does not return requestsSagas
anymoremeta.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 worryabortRequests
action and at the same time removed onAbort
resetRequests
aborts actions by default, you can change this by passing false as 2nd argumentgetQuerySelector
and getMutationSelector
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
Published by klis87 over 4 years ago
See redux-saga-requests v0.27.0
Published by klis87 over 4 years ago
See redux-saga-requests v0.27.0
Published by klis87 over 4 years ago
See redux-saga-requests v0.27.0
Published by klis87 over 4 years ago
See redux-saga-requests v0.27.0