aurelia / templating-binding

An implementation of the templating engine's Binding Language abstraction which uses a pluggable command syntax.
MIT License
32 stars 26 forks source link

Feature Request: ability to use angular style named params on delegate/trigger/call #9

Closed yelvert closed 9 years ago

yelvert commented 9 years ago

One of the biggest benefits I experienced with this in angular was the easiness of adapting external libs into an existing code base. It prevented having to rewrite/refactor functions that were called from templates, because you didn't have to worry about the argument order a specific directive expected.

This could be implemented by wrapping the function passed in with one using es6 named params, in the typeahead view model, the select delegate could called like this.select({$item}), then the wrapped function would apply the myVar variable from outside the typeahead's scope.

<typeahead select.delegate="myCustomSelectFunc($item)"></typeahead>and <typeahead select.delegate="myOtherCustomSelectFunc(myVar, $item)"></typeahead> would both work correctly when called from the typeahead custom element with the $item variable being supplied from the typeahead element and myVar coming from the view/view-model containing the typeahead

Let me know if this is the wrong repo for this issue and I'll move it.

EisenbergEffect commented 9 years ago

I feel like I'm not quite understanding the request. Begging your patience....would you mind trying to explain it a little more for me please?

yelvert commented 9 years ago

After rereading it, I can understand the confusion. I'll try to put a "how I would expect it to work" together tomorrow, if I get a chance.

yelvert commented 9 years ago

Something like this. https://gist.github.com/yelvert/1c2eb29b1cde45364fff Basically the equivalent of the &attr scope binding from angular.

jdanyow commented 9 years ago

@EisenbergEffect do we need the equivalent of knockout's $data added to the scope in the same fashion as $event ? Might be better to handle this as a special case in AccessScope and return scope when scope does not have a pre-existing $data property.

Similarly, we could also take care of https://github.com/aurelia/binding/issues/11 by making AccessScope handle a special $global token. This way accessing the global scope is explicit, but not difficult.

Thoughts?

Also wondering what we should name this? $scope? $data?

A duplicate of this issue is here: https://github.com/aurelia/binding/issues/50

EisenbergEffect commented 9 years ago

I was thinking of handling it precisely this way. Also, I was thinking of teaching the AccessScope node about $parent. Using $global is an interesting idea as well. I will need to consider this. Regarding the $data, my inclination was towards using $this as the other issue requests. I could be persuaded either way though.

All that said, I'm a bit nervous about adding any of this until after the binding system re-work. I would like to hold off on these until after that work is done.

EisenbergEffect commented 9 years ago

Ok. This is in master now and will go out in the next release. Thanks @jdanyow