Open rdewolff opened 5 years ago
Anyone?
Hey Rom,
Could you give an example of async action that mutate model/store state?
To make it work with classy-mst
I end up with the following code:
import { types, flow } from 'mobx-state-tree';
import { mst, shim, action } from 'classy-mst';
const AsyncData = types.model({ data: '' });
class AsyncCode extends shim(AsyncData) {
@action
run() {
const self = this; // <-- I have to add this ugly self pointer to make it work inside generator.
function* generate() {
const response = yield Promise.resolve('This gets lost');
self.data = response; // <-- `this` will not work here, since generator has different scope.
}
return(flow(generate)());
}
}
const Async = mst(AsyncCode, AsyncData);
Async.create().run().then(
(result) => console.log(result)
);
P.S Overall async actions looks pretty messy, do you have plan to work this around?
Hey @rznzippy ! Am not using classy-mst
on my projects. So I cannot provide you any examples.
Hello
Thanks for trying to build a classy layer on top of mobx-state-tree.
I remember reading few months ago somewhere (on your repo? blog?) about some limitation of classy-mst. Are there any MST usage we cannot do with it?