UNPKG

@finos/perspective-viewer

Version:

The `<perspective-viewer>` Custom Element, frontend for Perspective.js

45 lines (39 loc) 1.33 kB
export function bootstrap(psp, name, clsname, statics) { const cls = psp[clsname]; const proto = cls.prototype; class x extends HTMLElement { constructor() { super(); this._instance = new cls(this); } } const names = Object.getOwnPropertyNames(proto); for (const key of names) { if ('get' in Object.getOwnPropertyDescriptor(proto, key)) { Object.defineProperty(x.prototype, key, { get: function() { return this._instance[key]; } }); } else { Object.defineProperty(x.prototype, key, { value: function(...args) { return this._instance[key].call(this._instance, ...args); } }); } } for (const key of statics) { Object.defineProperty(x, key, { value: function(...args) { return psp[key].call(psp, ...args); } }); } Object.defineProperty(x, '__wasm_module__', { get() { return psp; }, }); customElements.define(name, x); }