##// END OF EJS Templates
added support for two arguments (props, children) form of fucntional components
cin -
r66:e3c05e9785a2 default
parent child
Show More
@@ -29,7 +29,7
29 29 "eslint": "6.8.0",
30 30 "requirejs": "2.3.6",
31 31 "tslint": "^6.1.3",
32 "typescript": "4.0.2",
32 "typescript": "4.2.4",
33 33 "yaml": "~1.7.2"
34 34 }
35 35 }
@@ -2,25 +2,28 import { argumentNotNull } from "@implab
2 2 import { RenditionBase } from "./RenditionBase";
3 3
4 4 export class FunctionRendition extends RenditionBase<Node> {
5 private _component: (props: any) => any;
5 private _component: (...args: any[]) => any;
6 6
7 7 private _node: Node | undefined;
8 8
9 constructor(component: (props: any) => any) {
9 constructor(component: (...args: any[]) => any) {
10 10 super();
11 11 argumentNotNull(component, "component");
12 12
13 13 this._component = component;
14 14 }
15 15
16 _create(attrs: object, children: any[]) {
16 protected _create(attrs: object, children: any[]) {
17 17 const _attrs: any = attrs || {};
18 _attrs.children = children.map(x => this.getItemDom(x));
19
20 this._node = this.getItemDom(this._component.call(null, _attrs));
18 const _children = children.map(x => this.getItemDom(x));
19 this._node = this.getItemDom(
20 this._component.length === 2 ?
21 this._component.call(null, { ..._attrs }, _children) :
22 this._component.call(null, { ..._attrs, children: _children })
23 );
21 24 }
22 25
23 _getDomNode() {
26 protected _getDomNode() {
24 27 if (!this._node)
25 28 throw new Error("The instance of the widget isn't created");
26 29 return this._node;
General Comments 0
You need to be logged in to leave comments. Login now