Skip to content
This repository was archived by the owner on May 3, 2023. It is now read-only.

Conversation

mdevlamynck
Copy link

This adds the boolean option useShadowDom (defaults to false to avoid breaking changes) to the register() function. When enabled it wraps the div elm renders to in a shadow dom. This also adds a section in the README for documenting the feature.

Copy link
Contributor

@stephencookdev stephencookdev left a comment

Choose a reason for hiding this comment

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

Nice 🙂 I'm a fan of this change

Left a couple of small comments, but I think this will be a nice addition

src/index.js Outdated
setupPorts(elmElement.ports)
} else if (elmVersion === '0.18') {
const elmElement = ElmComponent.embed(this, flags)
const elmElement = ElmComponent.embed(elmDiv, flags)
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this not be parentDiv? Or if Elm rendering on 0.18 can't work, we should log a warning here if the flag was active

Copy link
Author

Choose a reason for hiding this comment

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

That's probably a bug, good catch. I'll update the PR but I don't have time to test the change right now. I'll try it out during the week.

Copy link
Author

Choose a reason for hiding this comment

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

I confirm that it was a bug and that the last change fixed it.

src/index.js Outdated
context.flags = flags

var elmDiv = this;
var parentDiv = this;
Copy link
Contributor

Choose a reason for hiding this comment

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

We should use const/let rather than var here.

const parentDiv = useShadowDom ? this.attachShadow({ mode: 'open' }) : this;

maybe?

Copy link
Author

Choose a reason for hiding this comment

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

Indeed that's cleaner. And combined with your previous comment, I can use `const elmDiv in the 0.19 branch.

@jackfranklin
Copy link
Contributor

@mdevlamynck thank you for this! I'll merge now and we'll post a new version shortly

@jackfranklin jackfranklin merged commit 62e4a26 into thread:master Jan 21, 2020
@stoivo
Copy link

stoivo commented Feb 1, 2020

I a bit late to the party 🎉. (please don't get mad at me for commenting on a closed MR)
I want to learn. When do we want it and how does it help? If you got some links that would be goot too :D

@mdevlamynck
Copy link
Author

It helps isolate the style of the component from the style of the page so that the rendering of component is not affected by the page embedding it. The idea is to ease the building of reusable component independently of where there are going to be used.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

Successfully merging this pull request may close these issues.

4 participants