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

Intent to Implement: Premutate amp-bind state #12811

Closed
josh313 opened this issue Jan 11, 2018 · 0 comments
Closed

Intent to Implement: Premutate amp-bind state #12811

josh313 opened this issue Jan 11, 2018 · 0 comments

Comments

@josh313
Copy link
Contributor

josh313 commented Jan 11, 2018

Background

amp-bind allows developers to create interactive pages that can change content and show/hide different sections through user interactions. In some cases, it would be useful for an AMP viewer to be able to “deep-link” the user into a specific part of the page by setting the page’s AMP state.

Proposal

We should make amp-bind support a new message from the viewer called premutate which sets the amp-bind state of the AMP doc and re-computes all bindings. The message payload would have a single key state whose value is the state to set in the page. In order to allow a given AMP doc to be premutated like this, the page developer would have to add an overridable attribute to any amp-states that they would like to allow to be premutated by the viewer. The AMP doc responds to the premutate message with a list of the top-level state keys that were set.

Example

For the following AMP document:

...
<amp-state id="foo" overridable>
  <script type="application/json">
    {
      "data": 1
    }
  </script>
</amp-state>
<amp-state id="bar">
  <script type="application/json">
    {
      "data": 2
    }
  </script>
</amp-state>
...

If the viewer sent a premutate message with:

{
  "type": "q",
  "name": "premutate",
  "payload": {
    "state": {
      "foo": {
        "data": 3
      },
      "bar": {
        "data": 4
      }
    }
  }
}

The resulting state would be:

{
  "foo": {
    "data": 3
  },
  "bar": {
    "data": 2
  }
}

The foo state gets updated (because it has the overridable attribute), but the bar state doesn’t (because it doesn’t have the overridable attribute). The AMP doc would respond with the following message:

{
  "type": "s",
  "name": "premutate",
  "payload": {
    "updatedKeys": ["foo"],
    "ignoredKeys": ["bar"]
  }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants