Rematch: How To trigger a reducer action from another model?

Created on 14 May 2018  路  6Comments  路  Source: rematch/rematch

Hi all, thx for this awesome library!!!

Could someone give me a live example on how to trigger an action in a Model B when I'm inside an action in Model A?

For me it is not clear in the documentation how to do it ^_^

wontfix

Most helpful comment

I second @titouancreach's proposal. That's a brilliant way to keep everything bound to models.

All 6 comments

This should work:

import { dispatch } from '@rematch/core'

const modelA = {
  effects: {
    callModelB() {
       dispatch.modelB.someAction()
    }
  }
}

I think this is better:

const modelA = {
  reducers: {
    doSomething(state) {
      return state;
    }
  },
  effects: {
    doSomethingEffect() {
       // side effect here
       this.doSomething();
    }
  }
}

And create a reducer in modelB called modelA/doSomething

I second @titouancreach's proposal. That's a brilliant way to keep everything bound to models.

Thank youu!!! I'll do it this way ^_^

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

do you mean this?? Will the reducers then respond to the doSomething action?

const modelB = {
  reducers: {
    "modelA/doSomething": state => {
      return state;
    }
  },
Was this page helpful?
0 / 5 - 0 ratings