melanke / Watch.JS

watch the changes of any object or attribute

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Sequential changes to a property just fire the watcher one time

fedevegili opened this issue · comments

While trying to run the "Try out" example from "Remove a watcher" on main page, I just figured out that not all alerts were firing like they sould.

I forked the fiddle to a more direct approach:
http://jsfiddle.net/fedevegili/2fmc4kLL/

I think that the alert should fire for all the object changes, not only the last one.

This behaviour has caused me problems before, but I worked them around.

Is it expected behaviour or a bug?

From what I can recall I think that's the expected behaviour for object properties but for arrays you can you WatchJS.onChange to monitor array changes:

var obj = ["buddy"];

showAlert = function(changes){
  console.log(changes);
  console.log(changes.splices);
}

WatchJS.onChange(obj,  showAlert);

obj.push("johnny");
obj.push("phil");
obj.push("william");
obj.push("homer");