investtools/extensible-duck

How to work with sagas?

Closed this issue · 2 comments

First, would like to say that it is a brilliant idea and implementation! Thanks!

Second, would like to point to the mistake in the docs. Instead of:

sagas: {
    fetchData: function* (duck) {
    	try{
        yield put({ type: duck.types.FETCH_PENDING })
        const payload = yield call(Get, 'data')
        yield put({
          type: duck.types.FETCH_FULFILLED,
          payload
        })
      } catch(err) {
        yield put({
          type: duck.types.FETCH_FAILURE,
          err
        })
      }
    }
  },

it should be:

sagas: (duck) => ({
    fetchData: function* (duck) {
    	try{
        yield put({ type: duck.types.FETCH_PENDING })
        const payload = yield call(Get, 'data')
        yield put({
          type: duck.types.FETCH_FULFILLED,
          payload
        })
      } catch(err) {
        yield put({
          type: duck.types.FETCH_FAILURE,
          err
        })
      }
    }
  }),

which means that sagas should be a function that returns object.

Third, I have an issue with firing sagas. Maybe there something else we should know about how to make it work? I am using it with React, in Redux dev tools I see that event for async action is dispatched with the right arguments, but this does not trigger the related function generator.

What should be the problem?

hi @mrpsiho , here you can see an example of implementation: example

If you want run in your local, use this command:

npx @crassa/next init example
cd example
yarn run dev

Thanks!
Your answer was helpful!