Skip to content

✨ [amp-story-embed] Adds messaging, implements build/layoutcallbacks#26305

Merged
Enriqe merged 13 commits intoampproject:masterfrom
Enriqe:story-embed2messaging
Jan 28, 2020
Merged

✨ [amp-story-embed] Adds messaging, implements build/layoutcallbacks#26305
Enriqe merged 13 commits intoampproject:masterfrom
Enriqe:story-embed2messaging

Conversation

@Enriqe
Copy link
Copy Markdown
Contributor

@Enriqe Enriqe commented Jan 10, 2020

Partial for #24539

This PR adds:

  • Messaging that is needed for communication between the viewer and the STAMPs.
  • Adds an intersection observer that calls layoutCallback() with a fallback that uses a scroll listener.

Things I'm not sure about:

  • Since I'm installing a new package (@ampproject/viewer-messaging), yarn.lock has been updated, but I don't know if that should be in my local gitignore or if it should actually be checked in.

Issue tracker #26308

@Enriqe Enriqe requested review from gmajoulet and newmuis January 10, 2020 20:36
@amp-owners-bot amp-owners-bot bot requested a review from dreamofabear January 10, 2020 20:36
@Enriqe Enriqe changed the title ✨ Adds messaging, implements build/layoutcallbacks ✨ [amp-story-embed] Adds messaging, implements build/layoutcallbacks Jan 10, 2020
Copy link
Copy Markdown
Contributor

@gmajoulet gmajoulet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As commented below, I think some of this PR is taking us further from the end goal.
What we want is a piece of code that loads or prerenders a story, that we can call again and again as the user progresses through the feed of story.
This PR moves away from this and loads all the stories at the same time, which is a piece of code we'll never need in the final library.

@Enriqe
Copy link
Copy Markdown
Contributor Author

Enriqe commented Jan 14, 2020

Decided to move the loading one iframe + prerendering the next ones logic to another PR, to keep this one small and focused.

PTAL.

@Enriqe Enriqe force-pushed the story-embed2messaging branch from ab0e69a to 28b71cc Compare January 14, 2020 23:24
Copy link
Copy Markdown
Contributor

@gmajoulet gmajoulet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add some basic unit tests? I know we want to ship this asap but I believe it'll save us time :)

@Enriqe Enriqe force-pushed the story-embed2messaging branch from b024467 to 578c398 Compare January 16, 2020 19:29
@Enriqe
Copy link
Copy Markdown
Contributor Author

Enriqe commented Jan 16, 2020

PTAL @gmajoulet

also need owners approval from @jridgewell / @choumx for build-system/* and package.json

@Enriqe Enriqe force-pushed the story-embed2messaging branch from c4b1d85 to f6f7c6e Compare January 16, 2020 20:31
});

let inputUrl = addParamsToUrl(href, params);
inputUrl = inputUrl.replace('amp_js_v=0.1', 'amp_js_v=0.1#');
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this going to leave an extra & after the #?

Also, this won't work as addParamsToUrl seems to be adding the query parameter before the hash. You'd break the canonical URL by having the original hash at the very end of the URL.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch! I am now extracting the original fragment param first before prepending it again after adding the new parameters.

@Enriqe Enriqe force-pushed the story-embed2messaging branch from f6f7c6e to bb6eb39 Compare January 17, 2020 19:45
@Enriqe
Copy link
Copy Markdown
Contributor Author

Enriqe commented Jan 17, 2020

PTAL @gmajoulet

@Enriqe
Copy link
Copy Markdown
Contributor Author

Enriqe commented Jan 22, 2020

Friendly ping

Copy link
Copy Markdown
Contributor

@gmajoulet gmajoulet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good :))

this.win_ = win;

/** @private {?AmpStoryEmbed} */
this.currentEmbed_ = null;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: we should not write code that's only used for unit testing purposes (this and the getEmbed() method). Do you have another way of writing your test that wouldn't need this piece of code?
getEmbed returns you a pretty arbitrary embed (the last one), and currentEmbed doesn't make sense if there are two embeds side to side in the page

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

return;
}

this.layoutFallback_(embedImpl);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be easier to read with an early return after this one line?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

this.messagingFor_ = {};

/** @private {!Array<!Element>} */
this.iframes_ = [];
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few thoughts for another PR: I'm almost wondering if we should just store the story URLs instead of the iframes, so you can rotate through 3 or 5 iframe elements. Storing the actual iframes will make it harder/impossible to re-use the iframe elements.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, this was one of the approaches I was thinking for my next PRs when enabling multiple stories and I agree we should rotate through a fixed amount of iframes.

Copy link
Copy Markdown
Contributor Author

@Enriqe Enriqe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PTAL

this.win_ = win;

/** @private {?AmpStoryEmbed} */
this.currentEmbed_ = null;
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

return;
}

this.layoutFallback_(embedImpl);
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Copy link
Copy Markdown
Contributor

@gmajoulet gmajoulet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great! 👍

@Enriqe Enriqe force-pushed the story-embed2messaging branch from cdd32c6 to b466435 Compare January 23, 2020 18:15
@Enriqe
Copy link
Copy Markdown
Contributor Author

Enriqe commented Jan 23, 2020

/to @jridgewell @choumx for OWNERS approval

@Enriqe
Copy link
Copy Markdown
Contributor Author

Enriqe commented Jan 24, 2020

PTAL @jridgewell @choumx

@Enriqe
Copy link
Copy Markdown
Contributor Author

Enriqe commented Jan 27, 2020

Ping @jridgewell

Copy link
Copy Markdown
Contributor

@jridgewell jridgewell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One last question, but LGTM otherwise.

@Enriqe
Copy link
Copy Markdown
Contributor Author

Enriqe commented Jan 28, 2020

Thanks all, merging!

@Enriqe Enriqe merged commit 0b9623c into ampproject:master Jan 28, 2020
@Enriqe Enriqe deleted the story-embed2messaging branch January 28, 2020 22:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants