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-player] Player refactoring ♻️ #32115

Merged
merged 7 commits into from
Jan 22, 2021

Conversation

Enriqe
Copy link
Contributor

@Enriqe Enriqe commented Jan 22, 2021

  • Gets rid of IframePool.
  • Changes method signatures to only use StoryDef.
  • Moves messagingPromise to be a property of each story.
  • Now uses distance to know when to append a story to the DOM.

Deltas:

dist/amp-story-entry-point-v0.js: Δ -0.34KB
dist/amp-story-entry-point-v0.mjs: Δ -0.33KB
dist/amp-story-player-v0.mjs: Δ -0.35KB
dist/amp-story-player-v0.js: Δ -0.34KB
dist/v0/amp-story-dev-tools-0.1.mjs: Δ -0.34KB
dist/v0/amp-story-dev-tools-0.1.js: Δ -0.40KB
dist/v0/amp-story-player-0.1.js: Δ -0.37KB
dist/v0/amp-story-player-0.1.mjs: Δ -0.36KB

Followup:

  • Save iframe refs as WeakRef so that they can be GC when needed.

@Enriqe Enriqe changed the title wip [amp-story-player] Player refactoring ♻️ Jan 22, 2021
@Enriqe Enriqe requested a review from gmajoulet January 22, 2021 17:13
@Enriqe Enriqe marked this pull request as ready for review January 22, 2021 17:13
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.

Comments for followup PRs:

  • the most important one: we should have only one single code path to update all story positions/load/prerender/etc. One unique method like "update" or "render" or whatever you like. Right now you have different code paths to update stories: from prerenderStories, from add, etc. We should have only one "update" that updates everything: get distance map, set positions, add/remove from DOM, set visibilityStates, loads N+1 when N is ready

  • setSrc_ that handles load of followup stories is a bit weird. That should be fixed by/with the comment above.

  • buildStories_ that can append to DOM, that should be fixed by/with the comment above. This should build the StoryDefs and that's it, no side effects.

  • updateStoryPosition should be the only code path, we should remove "updateCurrent" "updatePrevious" etc (or keep them as private internals, only called from updateStoryPosition). Each StoryDef knows its previous distance/position, so you know if it needs to be removed/added from the DOM, repositioned, or any operations

idx === 0 /** hasPriorityLoading */
).then(() => this.prerenderFirstStoryDeferred_.resolve());
}
this.stories_.forEach((story) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we really loop on all Stories here? I'd like us to simplify the code further, and have one single code path to position/prerender/load stories based on their distance.
Right now it can happen from add or from prerenderStories or other methods. Would be cool if a single method was handling everything. (in a followup)

@@ -843,14 +768,14 @@ export class AmpStoryPlayer {

/** Sends a message muting the current story. */
mute() {
const {iframeIdx} = this.stories_[this.currentIdx_];
this.updateMutedState_(iframeIdx, true);
const story = this.stories_[this.currentIdx_];
Copy link
Contributor

Choose a reason for hiding this comment

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

Pretty nitty but if it's easy I think it'd be cool to pass the StoryDef as a parameter. Right now for ex, you couldn't mute the current story and unmute the next one. I know it wouldn't work on the web anyway but it would be nice to support it eventually, and to have method signature consistency.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Since this is a public API it would mean a breaking change :/

src/amp-story-player/amp-story-player-impl.js Show resolved Hide resolved
@Enriqe Enriqe merged commit 0aad4e8 into ampproject:master Jan 22, 2021
micajuine-ho pushed a commit to micajuine-ho/amphtml that referenced this pull request Jan 25, 2021
* fix tests

* delete iframepool and refactor methods to only use storyDef

* jsdoc

* jsdoc

* cleanups

* delete obsolete test

* jsdoc
powerivq pushed a commit to powerivq/amphtml that referenced this pull request Jan 27, 2021
* fix tests

* delete iframepool and refactor methods to only use storyDef

* jsdoc

* jsdoc

* cleanups

* delete obsolete test

* jsdoc
powerivq pushed a commit to powerivq/amphtml that referenced this pull request Jan 27, 2021
* fix tests

* delete iframepool and refactor methods to only use storyDef

* jsdoc

* jsdoc

* cleanups

* delete obsolete test

* jsdoc
PetrBlaha pushed a commit to PetrBlaha/amphtml that referenced this pull request Jan 28, 2021
* fix tests

* delete iframepool and refactor methods to only use storyDef

* jsdoc

* jsdoc

* cleanups

* delete obsolete test

* jsdoc
@Enriqe Enriqe deleted the player-refactor branch February 26, 2021 20:54
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.

3 participants