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

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

Merged
merged 13 commits into from
Jan 28, 2020

Conversation

Enriqe
Copy link
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 changed the title ✨ Adds messaging, implements build/layoutcallbacks ✨ [amp-story-embed] Adds messaging, implements build/layoutcallbacks Jan 10, 2020
src/amp-story-embed.js Outdated Show resolved Hide resolved
src/amp-story-embed.js Outdated Show resolved Hide resolved
src/amp-story-embed.js Outdated Show resolved Hide resolved
src/amp-story-embed.js Outdated Show resolved Hide resolved
src/amp-story-embed.js Outdated Show resolved Hide resolved
src/amp-story-embed.js Outdated Show resolved Hide resolved
Copy link
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.

examples/amp-story/embed.html Outdated Show resolved Hide resolved
examples/amp-story/embed.html Outdated Show resolved Hide resolved
package.json Outdated Show resolved Hide resolved
src/amp-story-embed.js Outdated Show resolved Hide resolved
src/amp-story-embed.js Outdated Show resolved Hide resolved
src/amp-story-embed.js Outdated Show resolved Hide resolved
src/amp-story-embed.js Outdated Show resolved Hide resolved
src/amp-story-embed.js Outdated Show resolved Hide resolved
src/amp-story-embed.js Show resolved Hide resolved
src/amp-story-embed.js Outdated Show resolved Hide resolved
@Enriqe
Copy link
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.

Copy link
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 :)

src/amp-story-embed.js Outdated Show resolved Hide resolved
src/amp-story-embed.js Outdated Show resolved Hide resolved
src/amp-story-embed.js Outdated Show resolved Hide resolved
src/amp-story-embed.js Outdated Show resolved Hide resolved
src/amp-story-embed.js Outdated Show resolved Hide resolved
src/amp-story-embed.js Outdated Show resolved Hide resolved
src/amp-story-embed.js Outdated Show resolved Hide resolved
src/amp-story-embed.js Outdated Show resolved Hide resolved
@Enriqe
Copy link
Contributor Author

Enriqe commented Jan 16, 2020

PTAL @gmajoulet

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

src/amp-story-embed.js Outdated Show resolved Hide resolved
src/amp-story-embed.js Outdated Show resolved Hide resolved
src/amp-story-embed.js Outdated Show resolved Hide resolved
src/amp-story-embed.js Outdated Show resolved Hide resolved
src/amp-story-embed.js Outdated Show resolved Hide resolved
src/amp-story-embed.js Outdated Show resolved Hide resolved
});

let inputUrl = addParamsToUrl(href, params);
inputUrl = inputUrl.replace('amp_js_v=0.1', 'amp_js_v=0.1#');
Copy link
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
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.

test/unit/test-amp-story-embed.js Outdated Show resolved Hide resolved
test/unit/test-amp-story-embed.js Outdated Show resolved Hide resolved
@Enriqe
Copy link
Contributor Author

Enriqe commented Jan 17, 2020

PTAL @gmajoulet

@Enriqe
Copy link
Contributor Author

Enriqe commented Jan 22, 2020

Friendly ping

Copy link
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
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
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
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
Contributor Author

Choose a reason for hiding this comment

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

Done.

src/amp-story-embed-manager.js Outdated Show resolved Hide resolved
this.messagingFor_ = {};

/** @private {!Array<!Element>} */
this.iframes_ = [];
Copy link
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
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
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
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
Contributor Author

Choose a reason for hiding this comment

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

Done.

src/amp-story-embed-manager.js Outdated Show resolved Hide resolved
Copy link
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
Copy link
Contributor Author

Enriqe commented Jan 23, 2020

/to @jridgewell @choumx for OWNERS approval

src/amp-story-embed-manager.js Outdated Show resolved Hide resolved
src/amp-story-embed-manager.js Show resolved Hide resolved
src/amp-story-embed-manager.js Show resolved Hide resolved
src/amp-story-embed-manager.js Show resolved Hide resolved
src/amp-story-embed-manager.js Outdated Show resolved Hide resolved
@Enriqe
Copy link
Contributor Author

Enriqe commented Jan 24, 2020

PTAL @jridgewell @choumx

@Enriqe
Copy link
Contributor Author

Enriqe commented Jan 27, 2020

Ping @jridgewell

Copy link
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.

src/amp-story-embed-manager.js Outdated Show resolved Hide resolved
src/amp-story-embed-manager.js Outdated Show resolved Hide resolved
@Enriqe
Copy link
Contributor Author

Enriqe commented Jan 28, 2020

Thanks all, merging!

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