-
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
I2I: Allow amp-list to have its json data sourced from amp-state #26009
Comments
Use cases to think throughinitial load
refreshing (incl option to have a loading indicator)
|
updated proposal (after conversations with chmoux and jridgewell)
This now means that if one points an
|
@samouri I mentioned in #26034 that I'd like to work on #25719 and @choumx suggested I touch base with you on this I2I. At face value, I think the feature I would like to implement (explained in more detail here: #25988) is different than what you're aiming to complete, but I do see areas of overlap in that we could share a means of delivering modified content to |
Sure! I'll ping you on our Slack channel. |
@mattwomple and I just met to discuss overlap between this I2I and Protocol Adapters. It does look like having
Matt, feel free to add in anything I missed! |
Agree on (1). There's also a similar issue of Assuming we can make performance acceptable, I'd prefer a more generic mechanism over a one-off. |
Thanks for posting the notes @samouri. @choumx do you have any initial feedback on # 3? The overhead of directly using |
Hm, one nice feature Re: (2), a nice property of With regard to size, I think decoupling amp-state from amp-bind should be doable and probably desirable anyways. |
Using the default assumptions
results
|
There's one other consideration we should keep in mind. Right now, EDIT: Thanks for posting the performance numbers @samouri . At the very least, that's further evidence that |
Another consideration to keep in mind: |
I spent much of today measuring init performance for new numbers
opportunities for closing the gap
|
For amp-bind, there's actually no functional dependency on |
A note: I do like the
As the humble suggester of the |
Each This stops holding true in the protocol adapters use-case. Users may call For example: <html>
…
<body>
<amp-list src="amp-state:animals">... </amp-list>
<amp-script script="local-script"></amp-script>
<script id="local-script" type="text/plain" target="amp-script">
AMP.setState({ animals: ['cat', 'dog', 'okapi'] });
</script>
</body>
</html> Please let me know if you think I'm missing something and/or if you still have a strong preference for |
I see your point! So, essentially, we're decoupling state variable names from HTML IDs. I'm excited to see your |
There was some good discussion here. I'm going to close this issue though in favor of multiple more specific I2Is (one just for initialization, and another for the more general protocol adapters use-case) |
summary
We've had multiple requests to support having
amp-list
source its data from anamp-state
(1). In order to make this happen, there are multiple problems we must solve:amp-list
to a key ofamp-state
. Note that this does not necessarilly need to correspond with a literal<amp-state>
in the HTML.amp-list
ofamp-state
metadata. Specifically, a piece of state being requested may be in one of four states:NotRequested | Loaded | Errored | Refreshing
. This is so thatamp-list
can decide to render a loading placeholder, error message, or the data.AMP.setState
to cause component rerenders unless there was a user gesture. We'd still want anamp-list
to render on pageload though even without user interaction.What follows are my proposals for solving each of these issues. I'm new to amp and won't take any harsh criticisms personally, so please feel free to be critical of these ideas!
syntax proposal
In #15647, there were a few good proposals for syntax, and I'd vote we stick with this one:
What I like about this syntax is that it is abundantly clear to the reader that the component is pointed at
amp-state
without being too verbose. One of the alternatives was to usesrc=#json.path
. With that suggestion I'd fear that a developer could think it must point to anid
on the page.metadata proposal
This is the part where I go off the deep end. In order for
amp-list
to render properly it needs state metadata, where the state always is the result of a fetch. When I think fetch I thinkPromise
. What if you could callAMP.setState
with a promise? That would allowamp-state
to seamlessly and separately keep track of state metadata.amp-list
could then depend on that key.For example:
What would this mean? From the developer's perspective, it is expected that the type of the promise is
Promise<!JsonObject>
. Once the promise resolves, it will be deep-merged at the specified key just like a regularsetState
call. The developer shouldn't need to worry about how the state metadata is being tracked.Initial load proposal
On initial load, we could create a small time window for an
amp-list
to subscribe toamp-state
and await the registration of a promise for its state json.path.The text was updated successfully, but these errors were encountered: