BorisMoore / jsviews

Interactive data-driven views, MVVM and MVP, built on top of JsRender templates
http://www.jsviews.com/#jsviews
MIT License
855 stars 130 forks source link

Two-way binding to helper functions, using get/set should provide the view as this pointer #321

Closed BorisMoore closed 8 years ago

BorisMoore commented 8 years ago

See discussion: https://github.com/BorisMoore/jsviews/issues/100#issuecomment-144892503

<input data-link="~fullName()" />

$.views.helpers("fullName", function fullName() {
  // this pointer is the view
});

fullName.set = function() {
  // this pointer is the view
};

But note that:

<input data-link="~util.fullName()" />

$.views.helpers("util", {fullName: function fullName() {
  // this pointer is ~util
}});

fullName.set = function() {
  // this pointer is ~util
};
BorisMoore commented 8 years ago

I have decided not to make the this pointer the view in the case <input data-link="~util.fullName()" /> - since normal expectations would be that the this pointer is the object util. If access to the view is required, one suggested best-practice would be to add a #view parameter.

For example if you currently have: <input data-link="~util.fullName(reverse)" />, you can instead write <input data-link="~util.fullName(reverse, #view)" /> - and then

$.views.helpers("util", {fullName: function fullName(reverse, view) {
  // this pointer is ~util
}});

(However, there will still not be an immediate access to view in the setter).

BorisMoore commented 8 years ago

Won't fix