HotDrink / hotdrink

JavaScript MVVM library with support for multi-way dependencies and generic, rich UI behaviors.
http://hotdrink.github.io/hotdrink/
58 stars 9 forks source link

Expressions in bindings #3

Open thejohnfreeman opened 12 years ago

thejohnfreeman commented 12 years ago

We should make an effort to support expressions in bindings.

It is important to note before the below discussion that we cannot know the type of an option value---e.g., normal function vs variable vs other type---before running the binding monad. We can, with the help of a parser, know if it is a function expression vs an identifier vs something else, but that might not be enough: a plain identifier could name anything.

To support expressions, they could be wrapped in a computed variable:

var option = hd.computed(function () {
  return <expression>;
});

Consider each kind of expression:

thejohnfreeman commented 12 years ago

Another case:

thejohnfreeman commented 12 years ago

Revisiting the function expression / method expression cases:

These functions might be subscribed to events, and as such will receive an event parameter. They should be sure to wrap the functions specified by the programmer so that the programmer's function gets called with $this.