component / reactive

Tiny reactive template engine
382 stars 48 forks source link

3rd parameter in custom bindings #135

Closed elidupuis closed 10 years ago

elidupuis commented 10 years ago

In the docs, its says a custom binding "will accept two arguments" but it appears that the model is passed as a third argument.

Is this something that's safe to use (as in, it's unlikely to change in the future)? If so, can the docs reflect that?

If not, what's the best approach to accessing many model properties in a custom binding?

chemzqm commented 10 years ago

Not quite sure, but I would prefer that to be stable.

defunctzombie commented 10 years ago

I think that was left over from some older each code. The better approach I would recommend would be to get the reactive instance from the binding instance and then get the model from that.

https://github.com/component/reactive/blob/master/lib/each.js#L7

var binding = this;
binding.reactive.model;

Inside of the binding, the this is the binding instance (as you already know) and that has a reactive property which is the current reactive instance.

elidupuis commented 10 years ago

Thanks @defunctzombie, that works great!