javascript - Make single MobX autorun or reaction for observable property of all objects in array -


i have class @observable (all examples typescript/pseudocode)

class page {    id: number = 0;     @observable    isvisible: boolean = false; }  let array = [new page(), new page(), new page()]; 

and functions like:

changevisibility(obj) {     //ajax call .post("/api/changevisibility/", {id:obj.id, isvisible:obj.isvisible}) } 

and want react on isvisible change on object.

i can enumerate array , make like:

array.foreach(el => {     reaction(         () => el.isvisible,         isvis => changevisibility(el);     }); }); 

but can 1 function?
kind of "array observer reacts element's property change".

something this:

 reaction(array, //source        (el) => el.isvisible, //observable react        (el) => changevisibility(el) //callback object     ) 

if reaction responsible sending the update of individual page, setup reaction in page constructor or have utility function in page that, don't have keep pages array in sync reaction disposers array (but best practice, dispose reaction if want delete page)


Comments

Popular posts from this blog

php - How to display all orders for a single product showing the most recent first? Woocommerce -

asp.net - How to correctly use QUERY_STRING in ISAPI rewrite? -

angularjs - How restrict admin panel using in backend laravel and admin panel on angular? -