Skip to content

Instantly share code, notes, and snippets.

@tusharmath
Last active September 26, 2016 17:02
Show Gist options
  • Save tusharmath/08069b84df9f08599a5465e34728ac23 to your computer and use it in GitHub Desktop.
Save tusharmath/08069b84df9f08599a5465e34728ac23 to your computer and use it in GitHub Desktop.
create web components using cyclejs
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