Search code examples
javascriptreactjsmobxmobx-state-tree

Mobx State Tree Flow. How to Know when it's done?


I am using mobx state tree and mobx for UI Stuff.

Now when I save something to db, after the request is done I want to update the ui(ie my mobx state).

I need to know when the flow is finished.

  myFlow: flow(function* () {
          // do stuff here.
    }),

now I see that a promise is returned, so I thought of just doing

myFlow.then() 

which works but I am wondering if this is the property way or if there is another way to do this(async/await? or some internal thing that flow has?)


Solution

  • a flow returns a promise, so any promise waiting mechanism works: .then, await, or yield inside another flow. If you want to render the state of the flow, take a look at mobxUtils.fromPromise(promise).case(....) of the mobx-utils package