FunctionRendition.ts
32 lines
| 996 B
| video/mp2t
|
TypeScriptLexer
cin
|
r65 | import { argumentNotNull } from "@implab/core-amd/safe"; | ||
import { RenditionBase } from "./RenditionBase"; | ||||
export class FunctionRendition extends RenditionBase<Node> { | ||||
cin
|
r66 | private _component: (...args: any[]) => any; | ||
cin
|
r65 | |||
private _node: Node | undefined; | ||||
cin
|
r66 | constructor(component: (...args: any[]) => any) { | ||
cin
|
r65 | super(); | ||
argumentNotNull(component, "component"); | ||||
this._component = component; | ||||
} | ||||
cin
|
r66 | protected _create(attrs: object, children: any[]) { | ||
cin
|
r65 | const _attrs: any = attrs || {}; | ||
cin
|
r66 | const _children = children.map(x => this.getItemDom(x)); | ||
this._node = this.getItemDom( | ||||
this._component.length === 2 ? | ||||
this._component.call(null, { ..._attrs }, _children) : | ||||
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; | ||||
} | ||||
} | ||||