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

Util for mapping an observable array into view models. #307

Open
danielyogel opened this issue Sep 12, 2022 · 3 comments
Open

Util for mapping an observable array into view models. #307

danielyogel opened this issue Sep 12, 2022 · 3 comments

Comments

@danielyogel
Copy link

danielyogel commented Sep 12, 2022

I keep finding myself in a situation, where I need to keep in sync (create/update/delete/move) an array of models (AKA VMs, Classes, factory functions) - with some observable array.

Is there some util of generic solution for that for MobX?

@NaridaL
Copy link
Collaborator

NaridaL commented Sep 12, 2022

Which direction? Maybe a autorun(() => { someObservableArray.forEach(x => update(vm, x)) } suffices?

@danielyogel
Copy link
Author

@NaridaL, Both directions:
When a new item (with a new ID) returned from API - a new VM should be created.
When a VM is deleted - the same item in the observable array should be delete.

Same for update, create, move...

autorun(() => { someObservableArray.forEach(x => update(vm, x)) } won't suffice. Thanks.

@brettwooldridge
Copy link

@danielyogel Did you find a solution to this?

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

3 participants