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

fix: theme logic #448

Merged
merged 5 commits into from
Jan 30, 2023
Merged

fix: theme logic #448

merged 5 commits into from
Jan 30, 2023

Conversation

luwes
Copy link
Contributor

@luwes luwes commented Jan 23, 2023

  • removes audio from template vars, this is set manually on the <media-theme> element so this was a mistake
  • fix the overwrite priority so media theme attributes set the by the consumer override the vars that are automatically injected.
  • add inner template caching

@luwes luwes self-assigned this Jan 23, 2023
@vercel
Copy link

vercel bot commented Jan 23, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated
media-chrome ✅ Ready (Inspect) Visit Preview 💬 Add your feedback Jan 30, 2023 at 5:26PM (UTC)
media-chrome-docs ✅ Ready (Inspect) Visit Preview 💬 Add your feedback Jan 30, 2023 at 5:26PM (UTC)

@vercel
Copy link

vercel bot commented Jan 23, 2023

@luwes is attempting to deploy a commit to the Mux Team on Vercel.

A member of the Team first needs to authorize it.

@heff
Copy link
Collaborator

heff commented Jan 24, 2023

add inner template caching

What's that mean?

templateInstances.set(part, tpl);
} else {
templateInstances.get(part)?.update(state);
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@heff this code is the gist of the template caching.

it's related to the inner templates (directives), they themselves are an extension of a child node part but instead of having a simple text node or element as value they have another template instance as contents.

when creating a new TemplateInstance (extension of DocumentFragment) basically what happens is the is cloned, the contents is appended to the TemplateInstance, it's parsed for parts, parts are created and stored in an array together with the string expressions, TemplateInstance.update(state) is called which calls the template processor and loops through the parts and updates the part's values.

tldr; when the template associated with the part did not change we can call templateInstance.update() directly without creating a new templateInstance and blowing away the previous html fragment.

(next = cur.nextSibling), parent.removeChild(cur), (cur = next);
}

return b;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I put in this minimal node list differ because something was wrong with my remove/add logic and it left an element from a previous permutation in the DOM.

Copy link
Collaborator

Choose a reason for hiding this comment

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

nice!

...Array.from(this.mediaController?.attributes ?? [])
.filter(({ name }) => {
return observedMediaAttributes[name] || name.startsWith('breakpoint-')
})
}),
...Array.from(this.attributes),
Copy link
Collaborator

Choose a reason for hiding this comment

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

question(non-blocking): In other words, you want attributes to effectively function as overrides for any coming from media-controller?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes indeed, I needed this behavior in Mux player so when stream-type is set manually it takes effect instantly and overrides the one coming from Media Chrome

Copy link
Collaborator

Choose a reason for hiding this comment

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

Cool that sounds like the right contract/precedence imo.

@@ -9,7 +9,6 @@ export * from './utils/template-parts.js';
const observedMediaAttributes = {
'media-target-live-window': 'targetLiveWindow',
'media-stream-type': 'streamType',
'audio': 'audio',
Copy link
Collaborator

Choose a reason for hiding this comment

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

thought(non-blocking): We may want to eventually re-add this for convenience, though most (non-player) theme use cases will likely either be audio or video anyway, so this likely doesn't need to be a priority (also not a priority for Mux Player, given how we manage audio only).

}

this.#nodes = normalisedNodes;
this.#nodes = swapdom(
Copy link
Collaborator

Choose a reason for hiding this comment

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

praise: 😎

Copy link
Collaborator

@cjpillsbury cjpillsbury left a comment

Choose a reason for hiding this comment

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

🚢 🇮🇹

@luwes luwes merged commit f502f19 into muxinc:main Jan 30, 2023
@luwes luwes deleted the fix-theme-logic branch January 30, 2023 18:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants