Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Limitation #19

Open
rdewolff opened this issue Jul 27, 2019 · 3 comments
Open

Limitation #19

rdewolff opened this issue Jul 27, 2019 · 3 comments

Comments

@rdewolff
Copy link

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?

@rdewolff
Copy link
Author

Anyone?

@rznzippy
Copy link

rznzippy commented Nov 19, 2020

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?

@rdewolff
Copy link
Author

Hey @rznzippy ! Am not using classy-mst on my projects. So I cannot provide you any examples.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants