-
Notifications
You must be signed in to change notification settings - Fork 23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
jQuery event is not passed on when adding arguments to binding #296
Comments
This would be a welcome addition for Blaze ViewModel too. |
1+ |
I've been thinking about this (both React and Blaze) and the least worse option I can think of is to send the event as a magical last parameter to the function:
This is a bad position because I don't know what I dislike the most, parameters that do something based on the name of the variable used (event, evt, etc.), or stealth parameters sent to functions at the end. I'm leaning towards the latter but I still on the fence about it. |
You know what, someone had to have thought of this already. Let's split the work of finding out how things are done elsewhere and pick the best one. @juho Find out how Aurelia would deal with a situation like this. Right now our best option (IMO) is to pass the event as an implicit last parameter. |
Aurelia and Knockout seem to do some magic binding stuff. IMO passing the event as the last prop is the best approach, then you can use it if you want to and it's a simple 1 line addition to the docs. |
FYI Manuel it would be great if the main files would be in JS at some point instead of Coffeescript, that kinda limits my contributions to code atm. Would like to take a look at perf problems or offer a bounty for one but the code's (mostly) uncommented and in CS, so it's a drawback as you're probably the only one who understands how all of it works. :) |
When calling without parameters, KnockOut behaves partly similar to ViewModel. The event is provided as the last parameter and the calling model is provided as the first parameter.
If the developer wants to add parameters, using a function literal is the Knockout-way (I'm not an immediate fan):
When using the first method, Knockout also calls Btw, I didn't quite understand what's not to like about adding the Also, I'm 100% with @juho on ViewModel being converted to modern JavaScript instead of CoffeeScript to make it easier to contribute. Just so happens I tried this two days ago with Decaffeinate and Prettier, but as expected, it wasn't that easy. Also, some comments on the code might make it easier for other people to contribute! |
From Vue (https://vuejs.org/v2/api/#v-on), related to
So they have a special parameter that you can pass into the template string, which I think would work great, I wouldn't mind it being passed as the last argument either, just because I need it in some of my functions, mostly to stop propagation and prevent default actions. |
Adding another prop to the template kinda goes against the less is more idea imo, just passing the event as the last prop seems like the most elegant thing and easier to start take advantage of. Currently it feels like |
After this discussion it's clear that passing it as a last (implicit) parameter is the way to go. Like juho mentioned, it's the way it works right now if no parameters are given. I was probably against it because the first impression of using a convention parameter like I should be able to add quickly to both VM versions. As for VM-Blaze switching to JS, we have to work out a way for someone (one of you?) to own the project. Right now I can only give minimal love to VM-Blaze (relatively small enhancements like this one, bug fixes, etc.) More on that on the other thread. btw, Angular uses a named variable too |
|
Cool, thanks! |
Work great, thank you. |
This passes the jQuery event to
addTag
, but:this does not, therefore preventing use of
preventDefault()
(and getting the element viacurrentTarget
etc.) on events. Would be nice if the event is the last argument passed to it automatically so it could be implemented likeThe text was updated successfully, but these errors were encountered: