ampproject / ampproject/worker-dom

<amp-script>: should AMP.setState() return a Promise?

Open
#806 4 comments 1 reaction 1 assignee Claimed by @samouri View on GitHub
amp-script API
Dominant language
TypeScript
Stars
3.3k
Forks
154
PR merge metrics
No merged PRs in 30d

Description

In ``, `AMP.getState()` returns a Promise. But `AMP.setState()` doesn't. This... is confusing, since I'd assume that both of these depend on sending a message to the main thread. In either case, I think it's confusing that the interface is different for two very similar methods.

I might think it would be simplest if both `getState()` and `setState()` were simply synchronous. I'd guess there aren't a lot of use cases where your script would want to request the contents of a state variable, then go on with other activities until the contents return. Even if this makes any sense, I imagine it's too late to change this now.

On the other hand, what if `setState()` did return a Promise too?

Of course, what would that mean?

What if the Promise was fulfilled when any binding was completed and any resulting DOM mutations had occurred? Then we could still allow the current usage, and make sense out of the Promise version too.

@samouri , I'm sure you can improve this proposal...

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.