-
-
Notifications
You must be signed in to change notification settings - Fork 33.7k
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
Add $arguments variable in component events inline statement #1945 #1949
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,13 +32,18 @@ export default function (Vue) { | |
|
||
function registerComponentEvents (vm, el) { | ||
var attrs = el.attributes | ||
var name, handler | ||
for (var i = 0, l = attrs.length; i < l; i++) { | ||
name = attrs[i].name | ||
let name = attrs[i].name | ||
if (eventRE.test(name)) { | ||
name = name.replace(eventRE, '') | ||
handler = (vm._scope || vm._context).$eval(attrs[i].value, true) | ||
vm.$on(name.replace(eventRE), handler) | ||
const scope = vm._scope || vm._context | ||
const handler = scope.$eval(attrs[i].value, true) | ||
vm.$on(name.replace(eventRE), function (...args) { | ||
scope.$arguments = args | ||
const result = handler.apply(this, args) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. One disadvantage of doing wrapper here instead of here is, if this statement There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good point. Let's wrap it in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. got it |
||
scope.$arguments = null | ||
return result | ||
}) | ||
} | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does it ok to use ES6 syntax here? i searched whole src codes and found there is no ES6 syntax used except modules.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's ok to use
let
andconst
. I am only using features that do not increase compiled file size at the moment.