Last active
September 26, 2016 17:02
-
-
Save tusharmath/08069b84df9f08599a5465e34728ac23 to your computer and use it in GitHub Desktop.
create web components using cyclejs
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
function transform(i: Object, fun: (value: any, key: string) => any) { | |
const out = {} | |
const keys = Object.keys(i) | |
keys.map((key, index) => out[key] = fun(i[key], key)) | |
return out | |
} | |
export class CycleHTMLElement extends HTMLElement { | |
private __main: Function | |
private __drivers: { [name: string]: Function } | |
private __run: Function | |
private __dispose: Function | |
private shadowRoot: Document | |
constructor(run: Function, main: Function, drivers: any) { | |
super() | |
this.__run = run | |
this.__main = main | |
this.__drivers = transform( | |
drivers, | |
(driver) => (sources) => driver(sources, this) | |
) | |
} | |
createdCallback() { | |
this.shadowRoot = this.attachShadow({ mode: "open" }) | |
this.__dispose = this.__run(this.__main, this.__drivers) | |
} | |
detachedCallback() { | |
this.__dispose() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment