FunctionRendition.ts
30 lines
| 922 B
| video/mp2t
|
TypeScriptLexer
cin
|
r65 | import { argumentNotNull } from "@implab/core-amd/safe"; | ||
cin
|
r98 | import { getItemDom } from "./render"; | ||
cin
|
r65 | import { RenditionBase } from "./RenditionBase"; | ||
export class FunctionRendition extends RenditionBase<Node> { | ||||
cin
|
r109 | private readonly _component: (...args: unknown[]) => unknown; | ||
cin
|
r65 | |||
private _node: Node | undefined; | ||||
cin
|
r109 | constructor(component: (...args: unknown[]) => unknown) { | ||
cin
|
r65 | super(); | ||
argumentNotNull(component, "component"); | ||||
this._component = component; | ||||
} | ||||
cin
|
r109 | protected _create(attrs: object, children: unknown[]) { | ||
const _attrs = attrs || {}; | ||||
cin
|
r101 | const _children = children.map(x => getItemDom(x)); | ||
cin
|
r96 | this._node = getItemDom( | ||
cin
|
r101 | this._component.call(null, { ..._attrs, children: _children })); | ||
cin
|
r65 | } | ||
cin
|
r66 | protected _getDomNode() { | ||
cin
|
r65 | if (!this._node) | ||
throw new Error("The instance of the widget isn't created"); | ||||
return this._node; | ||||
} | ||||
} | ||||