Open lexich opened 8 years ago
c6b2eb061a1d18920dc042db18303d68058a1c6a JWT authorization
Performing multiple calls to the same endpoint may also be a useful case. I've documented my approach here, for anyone interested: https://gist.github.com/wvengen/39b561607691e33bc0db050264ebc1e7
@wvengen very good example. Would you like to move you example to docs/MultipleCalls.md
?
@wvengen What do you think about more complicated way?
// a basic redux-api rest store
import reduxApi from 'redux-api';
import adapterFetch from "redux-api/lib/adapters/fetch";
export default ReduxApi({
productCategories: {
url: '/api/v1/products/categories',
postfetch: [
function({data, actions, dispatch, getState, request}) {
if (!data) { return [];}
const { categories } = data;
if (!categories) { return [];}
const requests = categories.map(({id}) => {
const requestParams = { .... };
return actions.productHistogram.request(requestParams);
});
// It very interesting place, maybe postfetch should process Promise
// This allow save all products information in categories
Promise.all(requests).then((data)=> {
dispatch({ type: "PRODUCTS_UPTATES", data })
});
}
]
},
productHistogram: {
url: '/api/v1/products/histogram',
virtual: true,
transformer: (data) => (data || {}).products_histogram,
},
}).use('fetch', adapterFetch(fetch));
My typical use-case includes chaining update and fetching a full list after the update. I can achieve this currently with helpers but having something like postfetch that would delay resolving the original action would simplify the code a lot.
I have "list" and "update" actions separately and currently I need to have the "updateAndFetchList" helper under the "list", which makes it a bit confusing. Currently postfetch is not blocking the resolution of the original action and thus there is a small race condition between update and list being refetched.
I have considered using one reducer but then I lose being able to separate "what" is loading / having error.
Hi @mkoppanen can you create new issue with example of you code. I'll try to help you.
Typical cases.
Feature requests.