Last active
June 26, 2018 17:24
-
-
Save robwormald/ce0c959c944bff7f0d796ab86f15895d to your computer and use it in GitHub Desktop.
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
import {ɵrenderTemplate as renderTemplate} from '@angular/core' | |
export function withNgTemplate(Base = HTMLElement){ | |
return class NgTemplateElement extends HTMLElement { | |
_renderRoot: HTMLElement | ShadowRoot; | |
_host:any; | |
_renderer(root:HTMLElement | ShadowRoot, renderFn:any){ | |
renderFn(); | |
} | |
_render(){ | |
this._host = renderTemplate(this._renderRoot as HTMLElement, (this.constructor as any).ngTemplate, this, { | |
createRenderer(){ return document; } | |
}, this._host, null, null, null ); | |
} | |
detectChanges(){ | |
this._renderer(this._renderRoot, () => this._render && this._render()); | |
} | |
} | |
} |
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
import {withNgTemplate} from '@angular/core' | |
//@Template({}) | |
class MyElement extends withNgTemplate(){ | |
} | |
customElements.define('x-foo', MyElement); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment