forked from jsdom/jsdom
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial work for Custom Elements support
Changes here paired with jsdom/webidl2js#44 will enable `./test-web-components.js` to work. You will need to `npm install` before running `node ./test-web-components.js`.
- Loading branch information
Showing
5 changed files
with
66 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// Modified JSDOM to allow `super` on `HTMLElement`. | ||
const { JSDOM } = require('./'); | ||
const { window } = new JSDOM('<!doctype html>') | ||
|
||
// FIXME Necessary for now to get MyShinyComponent in the shared JSDOM window. | ||
global.window = window; | ||
|
||
// Web Components on the way...! | ||
const { HTMLElement, document, customElements } = window; | ||
|
||
// Plain ole Custom Element... | ||
class MyShinyComponent extends HTMLElement { | ||
constructor(props = { someMessage: 'Set via innerHTML' }) { | ||
super(); | ||
|
||
this.innerHTML = `<span>${props.someMessage}</span>`; | ||
} | ||
} | ||
|
||
// Define into the internal JSDOM CustomElementsRegistry | ||
customElements.define('my-shiny-component', MyShinyComponent); | ||
|
||
// Helper function to create a regular DOM Node or upgraded Custom Element. | ||
function makeElement(tagName, props) { | ||
const Constructor = customElements.get(tagName); | ||
|
||
if (Constructor) { | ||
return new Constructor(props); | ||
} | ||
else { | ||
document.createElement(tagName); | ||
} | ||
} | ||
|
||
//console.log( | ||
// makeElement('my-shiny-component', { someMessage: 'Hello World' }).outerHTML | ||
//); | ||
|
||
document.body.innerHTML = '<my-shiny-component></my-shiny-component>'; | ||
|
||
/** | ||
* | ||
* | ||
* @return | ||
*/ | ||
console.log(document.body.outerHTML); |