esamattis / esamattis/immer-reducer

Redux-Saga api calls

Open
#40 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
223
Forks
15
PR merge metrics
No merged PRs in 30d

Description

Hi @epeli!

I was wondering how you implement Redux-Saga API calls.

If I take the default Redux-Saga readme example:

```
import { call, put, takeEvery, takeLatest } from 'redux-saga/effects'
import Api from '...'

// worker Saga: will be fired on USER_FETCH_REQUESTED actions
function* fetchUser(action) {
try {
const user = yield call(Api.fetchUser, action.payload.userId);
yield put({type: "USER_FETCH_SUCCEEDED", user: user});
} catch (e) {
yield put({type: "USER_FETCH_FAILED", message: e.message});
}
}

/*
Starts fetchUser on each dispatched `USER_FETCH_REQUESTED` action.
Allows concurrent fetches of user.
*/
function* mySaga() {
yield takeEvery("USER_FETCH_REQUESTED", fetchUser);
}
```

The pattern is to dispatch an action (`USER_FETCH_REQUESTED` ) and handle it in the saga. The saga calls the API and puts the result to either `USER_FETCH_SUCCEEDED` or `USER_FETCH_FAILED`.

Now when modeling this in immer-reducer would I get the following?
- an empty method called `UserFetchRequested`
- a method called `UserFetchSucceeded` which would update the draft
- a method called `UserFetchFailed` which would update the draft

Seems kinda weird... especially the empty method just for creating an action.

Would love to hear your view on this.

Thanks,

Michel

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.