Experimental implementation of Object.observe & JS Utility library now available

Steve Sanderson flares at gmail.com
Wed Aug 22 03:34:05 PDT 2012

This is fantastic - thanks for pushing this forwards, Rafael!

For context, I'm part of the knockout.js (a JavaScript MV* library) team,
so I have some interest in how this could work out. This spec has a lot of
potential to make MVC-style coding far simpler and more robust, both for
framework developers and web app developers. Although the semantics of the
Object.observe proposal are different in a few ways from what Knockout and
similar frameworks use for observability, it certainly looks applicable
enough to the same design patterns and APIs.

There's one significant extra aspect of observability that Knockout,
Batman, CanJS, and other MVC-type frameworks rely on that isn't covered as
far as I can tell by the proposal so far. These frameworks can
automatically determine the dependencies of an arbitrary block of code. For
example, if there is a block of code that determines the output of a
computed property, like this:

    function fullName() { return firstName + " " + lastName };

... then if you use such a function during a declarative binding, those
frameworks' observability mechanisms will automatically know which
underlying observable properties it depends on. This is possible because
the frameworks' observabilty mechanisms can notify on read as well as on
write. This ends up being a very powerful and flexible feature whereby the
framework can manage arbitrary and dynamically-changing dependency chains,
and the developer can robustly call arbitrary custom functions in computed
property evaluators and bindings.

These facilities could be made possible in the Object.observe proposal by
adding one further primitive feature. Just as you can register for
notifications on *write*, you'd ideally also be able to register for
separate notifications on *read*. Typically only framework code would do
that - application code wouldn't usually need to. The actual dependency
detection logic would differ depending on whether read notifications were
delivered synchronously or asynchronously, but then everything else can be
built on top of that primitive.

Please let me know if you want more detailed descriptions of how any of
this works in Knockout/etc. I'd be happy to suggest how a comparable API
might look in the Object.observe world!

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20120822/28a40851/attachment.html>

More information about the es-discuss mailing list