Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
developit committed Jan 19, 2018
0 parents commit 1c2bd89
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
node_modules
npm-debug.log
dist
README.md
package-lock.json
38 changes: 38 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"name": "preact-shadow-root",
"amdName": "Shadow",
"version": "1.0.0",
"description": "Render a Preact subtree into the Shadow DOM.",
"source": "preact-shadow-root.js",
"main": "dist/preact-shadow-root.js",
"module": "dist/preact-shadow-root.es.js",
"umd:main": "dist/preact-shadow-root.umd.js",
"scripts": {
"build": "microbundle",
"prepare": "npm run -s build",
"test": "eslint src && npm run -s build"
},
"eslintConfig": {
"extends": "eslint-config-developit"
},
"files": [
"preact-shadow-root.js",
"dist"
],
"keywords": [
"preact",
"component",
"shadow root",
"shadow dom"
],
"author": "Jason Miller <[email protected]>",
"license": "MIT",
"devDependencies": {
"eslint": "^4.6.1",
"eslint-config-developit": "^1.1.1",
"microbundle": "^0.3.1"
},
"peerDependencies": {
"preact": "*"
}
}
20 changes: 20 additions & 0 deletions preact-shadow-root.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { render } from 'preact';

/* Shadow Root component */
export default class Shadow {
shouldComponentUpdate(nextProps) {
this.update(nextProps);
return false;
}
componentDidMount() {
let parent = this.base && this.base.parentNode;
if (parent) {
this.shadow = parent.attachShadow({ mode: 'open' });
this.update(this.props);
}
}
update(props) {
render(props.children[0], this.shadow, this.shadow.firstChild);
}
render() {}
}

0 comments on commit 1c2bd89

Please sign in to comment.