-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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 variable references in action method arg values #6723
Add variable references in action method arg values #6723
Conversation
/to @dvoytenko PTAL! |
@@ -628,7 +690,7 @@ class ParserTokenizer { | |||
const value = convertValues && (s == 'true' || s == 'false') ? | |||
s == 'true' : s; | |||
newIndex = end - 1; | |||
return {type: TokenType.LITERAL, value, index: newIndex}; | |||
return {type: TokenType.ID, value, index: newIndex}; |
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 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
.
}); | ||
return applied; | ||
} | ||
return args; |
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.
Move on top as if (!args) {return args;}
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.
Done.
const value = token.value; | ||
if (token.type == TokenType.LITERAL) { | ||
return () => value; | ||
} else if (token.type == TokenType.ID) { |
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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
Event
object that triggered them. For example:If
myEvent
is triggered with aCustomEvent.detail = {foo: 'bar'}
, thenmyMethod()
will be called with args{key: 'bar'}
.