-
Notifications
You must be signed in to change notification settings - Fork 150
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
base: ampstart-2.0
Are you sure you want to change the base?
Conversation
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()}`; |
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.
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.
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.
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"> |
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 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.
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'm not happy about it either. I see two other options:
- 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. - 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.
Going with a wrapper based approach for none AMP elements for now:
I don't see a different way to support the
bindX
shortcut for non-AMPelements.