Open dvoytenko opened 4 years ago
Related to upgrade race conditions, the enqueueAction implements action queueing. This is probably not a useful feature in Bento mode, but should be analyzed.
Another way to solve the race condition would be to queue up the api calls until upgrade has completed, then call them all.
Another way to solve the race condition would be to queue up the api calls until upgrade has completed, then call them all.
This is what we do in AMP mode. But I don't think we can do that in Bento. IMHO it should be up to the developer. For instance, an API call might be time-sensitive and would trigger a failure to play a video, or a failure to open a popup if timing is missed. And if that's what a developer wants, they can also do it themselves if we give them some sort of whenReady
API. E.g. this is kind of like a queue, but by another name:
whenReady(element).then(() => element.api.play())
Currently the imperative Preact API (
useImperativeHandle
) is available toPreactBaseElement
bridge (see https://github.com/ampproject/amphtml/pull/30046). For instance, this is howPreactBaseElement
subclasses implementon
-actions.However, this APIs also need to be exported in Bento mode so that developers can call these APIs on a DOM AMP element instance. E.g. a developer needs to be able to call:
Currently it's possible using
CustomElement.enqueueAction
API. However, this method has always been meant as an internal API and thus has serious issues with ergonomics.In general the solution can be fairly straightforward simply proxying the Preact component's API on an element. However, some key nuances to be solved here are:
element.pause()
is always ok, or we can call itelement.ampPause()
(poor ergonomics), orelement.api.pause()
or similar. The naming is subject to bikeshed of course.element.api.pause()
might work well because we can useelement.api === undefined
as an indication that the component/API are not ready yet.enqueueAction
implements action queueing. This is probably not a useful feature in Bento mode, but should be analyzed.