googlearchive / observe-js

A library for observing Arrays, Objects and PathValues
1.35k stars 116 forks source link

ArrayObserver and arrays of objects #93

Closed glassresistor closed 9 years ago

glassresistor commented 9 years ago

Just curious if using the ArrayObserver and I do something like

var arr = [object1, object2, object3, object4];
var observer = new ArrayObserver(arr);
arr.reverse();
arr[0].property = 'change';

Will the event fire once or twice? I'm trying to discover if the obeserver recursively checks the objects in the array or what. The behaviour I'd prefer is that the event only fires when the arrays order changes or contents are added/removed and not if the objects in the array are modified.

jmesserly commented 9 years ago

I'm trying to discover if the obeserver recursively checks the objects in the array or what.

it does not.

The behaviour I'd prefer is that the event only fires when the arrays order changes or contents are added/removed and not if the objects in the array are modified.

that's exactly how it works.

you can read more about Array.observe and Object.observe, the underlying primitives: http://www.html5rocks.com/en/tutorials/es7/observe/ https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/observe https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/observe