mobx-utils icon indicating copy to clipboard operation
mobx-utils copied to clipboard

Util for mapping an observable array into view models.

Open danielyogel opened this issue 2 years ago • 3 comments

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?

danielyogel avatar Sep 12 '22 08:09 danielyogel

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

NaridaL avatar Sep 12 '22 08:09 NaridaL

@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.

danielyogel avatar Sep 12 '22 09:09 danielyogel

@danielyogel Did you find a solution to this?

brettwooldridge avatar Feb 03 '23 16:02 brettwooldridge