batch()
command with Redux saga ( https://react-redux.js.org/api/batch )?
takeEvery
, takeLatest
, etc) process the API method, it assigns a unique Id to each request and tracks it in the store so the component can check the status. This works great for takeEvery
, but when 3 components request the same endpoint simultaneously while using takeLeading
, the subsequent tasks get ignored. This leaves entries in my Redux store that are still designated as isFetching
, and my components think their data is still loading. How can I track (a) which tasks were actually taken, (b) which were ignored, and (c) dispatch an action to tell my component that the request was superseded?
Hey guys.. I'm having response is undefined on my request using sagas
export function* getCompanies({ payload }: any) {
try {
const { data: response } = yield call(api.get, '/companies-list', {
params: {
keyword: payload,
},
});
console.error(response);
const { data } = response;
yield put(handleFetchCompaniesAsync.success(data.companies));
} catch ({ response }) {
yield all([
put(handleFetchCompaniesAsync.failure(response.data)),
put(handleAsyncNotification(response.data)),
]);
}
}
export default function* companySagas() {
yield takeLatest(handleFetchCompaniesAsync.request, getCompanies);
}
What could be the problem here?
eventChannel
s that are never closed. I've read redux-saga/redux-saga#1961 but I don't think helps me figure out how to properly close my channels. The pattern I'm using here is something like this:const channel = eventChannel(…) // Unsubscribe is returned etc.
yield takeEvery(channel, process)
takeEvery
returns a task (and is non-blocking) so I would need some way to say "wait until this saga is cancelled, and then close the channel" but I don't know how to express that.
yield all([takeEvery(…), takeEvery(…), takeEvery(…)])
Hey guys, I have a more of a conceptual problem I've been struggling with in the past couple of days.
I have to subscribe to N event streams and react to the events occurring in them. Those are standard Node-like event-emitters.
I also have a facade API which should merge those N event streams together into a single one.
My initial thought was to convert the subscription into an async generator:
async function* subscribe({ fromBlock = 0, toBlock = 'latest', filter = {} } = {}) {
let res;
let rej;
let promise = new Promise((resolve, reject) => {
res = resolve;
rej = reject;
});
const subscription = linguo.events.allEvents({ fromBlock, toBlock, filter });
subscription
.on('data', event => {
res(event);
promise = new Promise((resolve, reject) => {
res = resolve;
rej = reject;
});
})
.on('error', err => {
rej(err);
promise = new Promise((resolve, reject) => {
res = resolve;
rej = reject;
});
});
while (true) {
try {
const event = await promise;
yield event;
} catch (err) {
console.warn(`Canceling event subscription for contract ${linguo.options.address}`, err);
break;
}
}
subscription.unsubscribe();
}
Then to combine the multiple subscribe()
calls, I've found this merge operator from the repeatable
library.
Then I happily wrote my saga:
export async function* subscribeSaga(action) {
const { fromBlock, toBlock, filter } = action.payload ?? {};
const linguoApi = yield getContext('linguoApi');
const subscription = yield call([linguoApi, 'subscribe'], { fromBlock, toBlock, filter });
for await (const evt of subscription) {
console.log('>>>', evt);
}
}
Only to find out then that redux-saga
does not support async generators :/
Any ideas?
retry
work only one time?
Hi developers
We are Ukraine based IT startup and we are looking forward to hiring 2 (two) React.js developers in a few days.
Recruitment process is simple.
If you are interested, DM me
Regards.
Andrei
Hello Everyone, MERN Stack Boilerplate provides starter kits for building web, desktop and mobile apps in pure JavaScript.
https://www.npmjs.com/package/create-mernjs-app
If you have any query or suggestions. Please let me know.
Hello Everyone,
MERN Micro Framework provides starter kits for building web, desktop and mobile apps in pure JavaScript.
https://www.npmjs.com/package/create-mernjs-app
If you have any query or suggestions. Please let me know.
function* workGetCardsFetch() {
const cards = yield call(() => axios.get('http://127.0.0.1:8000/'))
yield put(getCardsSuccess(cards.data))
}
# Post action starts here
function* workCreateCard(action) {
try {
const word = action.payload
const options = {headers: { "content-type": "application/json" }}
yield call(() => axios.post('http://127.0.0.1:8000/words/new/', { word }, options))
# I added yield workGetCardsFetch() to reload the data
# because the state in the reducer doesn't receive the new id created in the backEnd from a post request.
yield workGetCardsFetch()
} catch (error) {
console.log(error.message)
}
}
Hello Everyone
Set up a modern web, mobile & desktop app by running one command.
dependabot[bot] on npm_and_yarn
(compare)
dependabot[bot] on npm_and_yarn
(compare)
dependabot[bot] on npm_and_yarn
(compare)