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
Makes data-vars-
attribute work in amp-ad.
#10438
Conversation
if (!startsWith(attr.name, 'data-') | ||
// data-vars- is reserved for amp-analytics | ||
// see https://github.com/ampproject/amphtml/blob/master/extensions/amp-analytics/analytics-vars.md#variables-as-data-attribute | ||
|| startsWith(attr.name, 'data-vars-')) { | ||
continue; | ||
} | ||
attributes[dashToCamelCase(attr.name.substr(5))] = attr.value; |
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.
Why aren't we iterating the dataset? We could get rid of dashToCamelcase
, #substr
, and a startsWith
:
const set = element.dataset;
for (const name in set) {
if (!startsWith(name, 'vars')) {
attributes[name] = set[name];
}
}
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.
A very good question. Reviewing this, I did a code search, and it looks like we are thoroughly underusing dataset
. So I opted not to suggest it here. Perhaps we should be using it for this?
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.
I commented on another issue in the last year where they didn't use it because they needed the dash-case strings, which seemed fine. But in this case, I think it's the better choice.
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.
good stuff . addressed in PR #10543
Fixes #8852