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

Support bindings on non-AMP elements #895

Open
wants to merge 1 commit into
base: ampstart-2.0
Choose a base branch
from

Conversation

sebastianbenz
Copy link
Collaborator

Going with a wrapper based approach for none AMP elements for now:

<AmpBind bindText="greeting">
  <div />
</AmpBind>

I don't see a different way to support the bindX shortcut for non-AMP
elements.

Going with a wrapper based approach for none AMP elements for now:

```
<AmpBind bindText="greeting">
  <div />
</AmpBind>
```

I don't see a different way to support the `bindX` shortcut for non-AMP
elements.
const newProps = {};
Object.keys(rest).forEach(key => {
if (/^bind[A-Z]/g.test(key)) {
const newKey = `data-amp-bind-${key.substring(4).toLowerCase()}`;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you want to lower case the whole string or just the first character of the string? I know standard HTML elements won't have hyphenated names, but just felt a little risking assuming nothing else ever will.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The React toString serializer will automatically lowercase attribute names. So I think it's fine to lowercase by default.


```
<div data-amp-bind-text="hello"/>
<button on="tap:AMP.setState({ "hello": "world" })">
<AmpBind bindText="greeting">
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is a pity extra markup is required find bind attributes, but if there is no alternative supported by Next.js then a wrapper element names sense.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not happy about it either. I see two other options:

  1. HTML Element specific components:
    <AmpDiv bindText/>
    This would have the added benefit of element specific auto completion. But it's probably more confusing than it helps.
  2. Add bindX types to the HTML elements and rename the attributes in AMP Optimizer. This would work best, but the downside is that it means we have to move Next.js specific features into AMP Optimizer.

@CLAassistant
Copy link

CLAassistant commented Oct 8, 2020

CLA assistant check
All committers have signed the CLA.

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

Successfully merging this pull request may close these issues.

3 participants