GianlucaGuarini / icaro

Smart and efficient javascript object observer, ideal for batching DOM updates (~1kb)
MIT License
573 stars 29 forks source link

Feature request: Propagate changes of objects in array to parent #14

Open luffs opened 7 years ago

luffs commented 7 years ago
const blogPosts = icaro([
  {id: 1, topic: "First",content:"..."},
  {id: 2, topic: "Second",content:"..."}
]);

blogPosts.listen(function(changes){
 console.log("changes", changes)
});

blogPosts[0].topic= "Hello";
blogPosts[1].topic = "World";

This doesn't trigger the blogPosts listener, and maybe it would be neat if it did?

Example use case: I want to use icaro with riot.js, and while I can set an individual listener on the blogPosts-elements to update each \<blog-post>, I'm not sure how to trigger the update of the \<blog-post-list>, which just contains the topics of the blogposts, not the content.

Edit: Made pull request #15 with a simple fix. Has the drawback that it doesn't include the index of the modified element though.