-
-
Notifications
You must be signed in to change notification settings - Fork 21
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
Thoughts about mobx-vue #3
Comments
It's so great that met someone thought the same!
@Connect(store)
@Component()
export default class App extends Vue {
mounted() {
this.initStore()
}
destroyed() {
this.destroyStore()
}
} That is not my favour too so maybe I should support initializing the state automatically. class ViewModel() {}
@Connect(ViewModel)
@Component()
export default class App extends Vue {} But the risk of this workaround is that Store and ViewModel are different conceptually, the former lives singleton and the later lives around the component lifecycle, but they are defined the same way(class recipe). For a bindings/connector we shouldn't introduce too much extra concepts imo. Or you can try the special solution with DI which mmlpx provided, you can take a glance althought it not documented well yet😄.
|
What about connecting multiple stores? |
@xrado good question! Actually that is what made me in a dilemma. @nighca @xrado I will realize a version with @Observer
@Component()
export default class App extends Vue {
store = store
vm = new ViewModel()
} and using in template: <div>{{store.user}} {{vm.loading}}</div> Thanks for your feedback! |
@kuitos 👍 Very impressive productivity. To me, it is reasonable to provide another API like |
@nighca Automatic instantiation will introduce several new issues which should not simply construct the ViewModel with class ViewModel {
id: number;
@observable users = [];
constructor(id: number) {
this.id = id;
}
async onInit() {
this.users = await http.get(`/users/${this.id}`)
}
} We need provide the ability to pass parameters to constructor, maybe it looks like this: Connect(ViewModel, 10) And things are moving forward. The parameter cames from vue instance, such as a router query string. We need support another usage: Connect(ViewModel, vm => [vm.$route.query.userId]) In fact that are what mmlpx provided already!😉. With mmlpx you can initialize states like this: import { inject } from 'mmlpx';
class App extends Vue {
@inject()
vm1: ViewModel;
@inject(ViewModel)
vm2;
@inject(ViewModel, 10)
vm3;
@inject(ViewModel, vm => [vm.$routes.userId])
vm4;
} DI should be an independent solution for who don't wanna initilize dependencies manually, and applies to any other framework imo. But |
@kuitos Yes, what I mean is just what mmlpx does. But I'm not sure if mmlpx already suits Vue context well. Maybe there is some more work needed, and if so, it is fine to provide these things within mobx-vue (instead of some other package like mmlpx-vue), just like that mobx-react provides |
I'm kinda wondering what direction this project might take with a "new vue" on the horizon. Since vue seems to move away from classes and therefore decorators is there a happy path to using mobx with vue in 2020? |
Hi there! I've read the docs and came with some ideas:
Mostly what we want is to connect Store instance with Component instance/element, instead of to connect Store instance with Component class/definition. The later may introduce issues when the same Component class/definition used (instantiated) multiple times - different Component instance/element will share the same state. Such behavior suits global-state-situation, while not local-viewModal-state-situation.
Maybe
connect
is not a good idea.connect
defines extra properties on Vue vm in an implicit way. IMO, it will be better not to provide the ability ofconnect
. Offering ability ofobserver
allows developer to organize their state in more explicit way, maybe something like:What do you think?
The text was updated successfully, but these errors were encountered: