-
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
amp-script: Interop with [on] actions #24763
Comments
/cc @samouri |
@sebastianbenz, can you help me understand the use case for: "(1) Actions calling into amp-script Specifically I'm trying to figure out what kind of amp-script behaviors a publisher would want to call via [on] handlers, and is it more ergonomic than alternatives. In which situations would this remove the need for I'm probably missing something, but all the situations I'm thinking of either still require |
Could be helpful to augment preexisting pages with a little "amp-script magic". Also composing AMP components with |
Use cases:
Not requiring amp-state is not the main use case, but a positive side-effect in a few cases. |
Thank you both for the replies! I'm still struggling to understand the use cases, so I'm going to think-out-loud through the three use cases to try an understand how the alternative implementations would stack up.
So this would involve creating a new action via <script id="example" type="text/plain" target="amp-script">
const elements = document.querySelectorAll('...');
elements.forEach(el => {
el.addEventListener(() => triggerBackendAction());
})
</script>
Unless the amp-script function were modifying re. the layout constraints: now that
Ah. Is this because an |
There's a subtree/nesting problem (more below). You might want to be able to fire the same action from different elements on the page.
How would you fire a repeatable action using amp-state? E.g. send out a request every time a button is clicked?
This could work in some cases, but would mean that you couldn't have a small self-updating amp-script on the same page. |
Adding access to other AMP actions from |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 7 days if no further activity occurs. Thank you for your contributions. |
This is still needed and important.
… Message ID: ***@***.***>
|
Stale bot shouldn't have closed this. Line 1 in 265e0b0
|
This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 7 days if no further activity occurs. Thank you for your contributions. |
Overview
Bidirectional interoperation has two parts:
amp-script
can define custom actions and other elements can call them.amp-script
can call actions on other elements.(1) Actions calling into
amp-script
It'd be great if amp-script had the ability to define custom actions. The advantages are:
For example:
Inside the script you could implement a handler:
Alternative
The same thing could be accomplished with
AMP.setState(...)
and a counter:where the amp-script listens to state changes to the
fetch
variable. However, this is hacky and always requires using amp-bind.(2)
amp-script
calling actions on other elementsIt'd be useful to be able to trigger AMP Actions from within an amp-script. Use cases would be:
A positive side-effect would be that scripts can target elements outside the amp-script element's scope.
The text was updated successfully, but these errors were encountered: