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

hd.model should wrap model definitions, not constructions #1

Closed thejohnfreeman closed 12 years ago

thejohnfreeman commented 12 years ago

Setting the context of methods is just a convenience.

One option, stack-based method tracking:

Second option, stack-based context tracking:

Second option is more efficient, but will not support case where constructor returns a model object rather than using this.

For model literals, for each property that is a derived variable, its method's context is set to the model.

What about a variable constructed in one place and used in several others:

var x = hd.computed(...);
hd.bind(hd.model({ one: x }), $("#one"));
hd.bind(hd.model({ two: x }), $("#two"));

The context of the method will be changed. Is this even a real-world possibility? If a variable is included in two different models, it probably isn't using the context.