W3C home > Mailing lists > Public > public-script-coord@w3.org > July to September 2014

Re: Object.observe()able properties on the web platform

From: Boris Zbarsky <bzbarsky@mit.edu>
Date: Wed, 20 Aug 2014 15:15:59 -0400
Message-ID: <53F4F3EF.3070601@mit.edu>
To: public-script-coord@w3.org
On 8/20/14, 3:03 PM, Domenic Denicola wrote:
>> How would you implement observable properties efficiently?
>
> The efficiency is already solved by the Object.observe implementation. My understanding is that the overhead is close to negligible for cases when nobody observes the object.

The overhead of checking whether something observes the object might be 
quite non-negligible in itself.  Especially so for cases where the 
property value is computed lazily, because then you need some sort of 
extra something to notice when the value might have changed, which you 
don't need without Object.observe.

> If you are asking how you tap into that as a developer, you do something like `this._notifier = Object.getNotifier(this)` in the constructor, and then do `this._notifier.notify({ type: 'update', name: 'propertyName', oldValue: propertyOldValue })` inside the relevant setter.

You just assumed you have the old and new value.

You also constructed an object.  And defined properties on it.  I can 
assure you that doing that is non-negligible in performance terms.

> Obviously real implementations would not use underscored-properties, but you can see how it is very much automatable via a WebIDL binding layer.

It's not entirely, because the bindings layer has no idea when property 
values change, except for the obvious case of writable properties that 
can't change out-of-band.

-Boris
Received on Wednesday, 20 August 2014 19:16:27 UTC

This archive was generated by hypermail 2.4.0 : Friday, 17 January 2020 17:14:22 UTC