Add variable references in action method arg values#6723
Add variable references in action method arg values#6723dreamofabear merged 6 commits intoampproject:masterfrom
Conversation
|
/to @dvoytenko PTAL! |
| const value = convertValues && (s == 'true' || s == 'false') ? | ||
| s == 'true' : s; | ||
| newIndex = end - 1; | ||
| return {type: TokenType.LITERAL, value, index: newIndex}; |
There was a problem hiding this comment.
It sounds like if it's true or false - this should still be LITERAL, right? A literal boolean value? Since we likewise have literal numeric values....
There was a problem hiding this comment.
Yea, ID probably isn't a good name. I wasn't sure how JS-like we should make this since non-quoted strings are currently treated as string literals.
Changed so that true, false and numerics won't be classified as ID.
src/service/action-impl.js
Outdated
| Object.keys(args).forEach(key => { | ||
| applied[key] = args[key].call(null, data); | ||
| }); | ||
| return applied; |
There was a problem hiding this comment.
Move on top as if (!args) {return args;}
src/service/action-impl.js
Outdated
| */ | ||
| function getActionInfoArgValue(token) { | ||
| const value = token.value; | ||
| if (token.type == TokenType.LITERAL) { |
There was a problem hiding this comment.
So, this changes the spec in described in the https://github.com/ampproject/amphtml/blob/master/spec/amp-html-format.md#on
Looks like the docs should be changed. How compatible are we with the current doc?
Looks like we fallback to the literal value. Would that look strange per doc?
There was a problem hiding this comment.
Looks like the docs should be changed. How compatible are we with the current doc?
I was planning to wait until at least one component supports exposing event data before updating the docs. There's no viable use case yet.
Looks like we fallback to the literal value. Would that look strange per doc?
Agreed. As discussed, I changed the format to allow dereferencing only through . operator in argument values, e.g. on="event:method(key=event.variable).
dbaeed5 to
a09c6d7
Compare
* implement var dereferencing in action arg values * fix type error * add unit tests for applyActionInfoArgs() * fix lint error * PR comments * fix lint errors
* implement var dereferencing in action arg values * fix type error * add unit tests for applyActionInfoArgs() * fix lint error * PR comments * fix lint errors
Partial for #6199.
This allows method calls to reference data in the
Eventobject that triggered them. For example:If
myEventis triggered with aCustomEvent.detail = {foo: 'bar'}, thenmyMethod()will be called with args{key: 'bar'}.