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