I maintain a Shim of Object.observe (
https://github.com/jdarling/Object.observe) that has been gaining in
popularity since Chrome implemented the functionality in their public
release.  It had some usage before but it has really started picking up
since.

That being beside the point, someone asked us about implementing the update
to deliverChangeRecords (
https://github.com/jdarling/Object.observe/issues/13).  It seems that at
some time deliverChangeRecords moved from the ObjectNotifier to Object
itself.

Per the spec at
http://wiki.ecmascript.org/doku.php?id=harmony:observe_public_api

Object.deliverChangeRecords

A new function Object.deliverChangeRecords(callback) is added, which
behaves as follows:

   1. If IsCallable(*callback*) is not *true*, throw a TypeError exception.
   2. Call [[DeliverChangeRecords]] with arguments: *callback* repeatedly
   until it returns false (no records were pending for delivery and callback
   no invoked).
   3. Return.


This seems very grey and not well defined at all.  One would assume that
per the above the following code would function calling changeHandler2 for
all change records (and maybe, its unclear from the above, changeHandler1
as well).


var obj = {};
var changeHandler1 = function(changes) {
  console.log('1)', changes);
};

var changeHandler2 = function(changes) {
  console.log('2)', changes);
};

Object.observe(obj, changeHandler);
obj.test = 5;

while(Object.deliverChangeRecords(changeHandler2)){
  console.log('got a change')
}

So we went to Chrome 36 and looked at how it handled the above code.  To
our surprise changeHandler1 got called with the change but changeHandler2
did not get called, also 'got a change' was never logged to the console.

This lead us to assume that the handler must be one that was already
registered with Object.observe.  So we tried the following code instead:

var obj = {};
var changeHandler = function(changes) {
  console.log('1)', changes);
};

Object.observe(obj, changeHandler);
obj.test = 5;

while(Object.deliverChangeRecords(changeHandler)){
  console.log('got a change')
}

When running the above changeHandler seems to be called via the normal
Object.observe pipe and still 'got a change' is not recorded in the
console.  Basically making Object.deliverChangeRecords appear to be a noop
that actually ignores the callback that has been passed into it.

So, after all the above, here is my question; What exactly is
Object.deliverChangeRecords supposed to do?  As a follow on to that, can
someone post a test scenario that actually covers its proposed actions so
we can implement it?

Seems to me, to add it in the way Chrome as so far we could just noop it
and go on, but that just doesn't feel right in the grand scheme of things.

Thanks,
 - Jeremy
_______________________________________________
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to