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

Add a @byContent selector for reparenting child content #5

Merged
merged 7 commits into from
Dec 6, 2018

Conversation

cuberoot
Copy link
Contributor

Description

This is the implementation of a @byContent decorator that would allow the capturing of arbitrary DOM content that the web component user has placed into a wrapped web component.

Related Issue

#4

Motivation and Context

Adding this feature would allow us to turn a React container component into a web component. So, we could write containers such as popovers and dialogs in React and wrap them as web components. The user of the web components could pass in arbitrary content to be hosted in the container.

How Has This Been Tested?

I have developed a basic container control using this code and I have added a new test to the test suite to test it.

Screenshots (if appropriate):

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • [x ] New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • [x ] I have signed the Adobe Open Source CLA.
  • [x ] My code follows the code style of this project.
  • [x ] My change requires a change to the documentation.
  • [x ] I have updated the documentation accordingly.
  • [ x] I have read the CONTRIBUTING document.
  • [x ] I have added tests to cover my changes.
  • [x ] All new and existing tests passed.

README.md Outdated
@@ -218,6 +219,44 @@ model ~ {
}
```

#### byContent
This decorator allows you to capture the contents of a child of the element that is matched.
by a CSS selector. The can be used to reparent arbitrary child DOM content, which may not

Choose a reason for hiding this comment

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

Typo here, I think you meant then or the selector

import EmbedNode from './EmbedNode';
import React from 'react';

var _idCount = 0;

Choose a reason for hiding this comment

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

use let please. I will add a eslint config for this.

function findCommentNode(element, selector) {
for(let i = 0; i < element.childNodes.length; i++) {
let node = element.childNodes[i];
if( node.nodeType === 8
Copy link

@alexmirea alexmirea Dec 5, 2018

Choose a reason for hiding this comment

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

Theoretically we can use the constant Node.COMMENT_NODE to make the code clearer.
https://developer.mozilla.org/en-US/docs/Web/API/Node/nodeType

Can you check browser support for that? At the very least you could add a comment to make it clear what 8 is

}
}

DOMNode.prototype.type = 'node';

Choose a reason for hiding this comment

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

I don't think this is needed anymore.

function findCommentNode(element, selector) {
for(let i = 0; i < element.childNodes.length; i++) {
let node = element.childNodes[i];
if( node.nodeType === Node.COMMENT_NODE
Copy link
Contributor Author

@cuberoot cuberoot Dec 5, 2018

Choose a reason for hiding this comment

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

I double checked this against the supported browsers.. The page was missing the info for Safari, Edge and IE. So, I checked all of those and Node.COMMENT_NODE was available.

All that to say, that it's ok to use the constant.

@cuberoot
Copy link
Contributor Author

cuberoot commented Dec 5, 2018

@alex-mirea I fixed up all of the the code review issues that you flagged. Thanks!

@alexmirea alexmirea merged commit d01d2d6 into adobe:master Dec 6, 2018
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.

2 participants