-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
example of intercepting a custom element definition
- Loading branch information
1 parent
330f7d9
commit 5321284
Showing
4 changed files
with
48 additions
and
0 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// Proxy ? | ||
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy | ||
|
||
// A | ||
// function customDefine(tagName, BaseClass) { | ||
// console.debug('intercepted customElement.define', { tagName, BaseClass }); | ||
// } | ||
|
||
// new Proxy(customElements.__proto__.define, customDefine) | ||
|
||
// new Proxy(customElements.__proto__, { | ||
// define: customDefine | ||
// }); | ||
|
||
const backupDefine = customElements.define.bind(window.customElements); | ||
|
||
window.customElements.define = (tagName, BaseClass) => { | ||
console.debug('intercepted customElement.define', { tagName, BaseClass }); | ||
|
||
if(BaseClass.__secret) { | ||
console.debug('hmmmm... wonder what could we do here????'); | ||
BaseClass.__secret(); | ||
} | ||
|
||
backupDefine(tagName, BaseClass); | ||
} |
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,16 @@ | ||
class TestComponent extends HTMLElement { | ||
constructor() { | ||
super() | ||
|
||
// TODO have wcc skip over mode / attachShadow, innerHTML, connectedCallback, etc | ||
this.attachShadow({ mode: 'open' }); | ||
} | ||
|
||
static __secret() { | ||
console.debug('sssshhh! this is a secret :)') | ||
} | ||
} | ||
|
||
export { TestComponent } | ||
|
||
customElements.define('wcc-test', TestComponent) |
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