Skip to content
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

Merged
merged 2 commits into from Jul 14, 2017

Conversation

lannka
Copy link
Contributor

@lannka lannka commented Jul 14, 2017

Fixes #8852

@lannka lannka requested a review from dvoytenko July 14, 2017 17:23
@lannka lannka merged commit ce6416b into ampproject:master Jul 14, 2017
@lannka lannka deleted the analytics-vars-in-amp-ad branch July 14, 2017 17:56
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;
Copy link
Contributor

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];
  }
}

Copy link
Contributor

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?

Copy link
Contributor

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.

Copy link
Contributor Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants