FunctionComponentContext.ts
        
        
            
                    33 lines
            
             | 949 B
            
                | video/mp2t
            
             |
                TypeScriptLexer
            
          
        | 
              
  
   | 
            
            r34 | import dom = require("dojo/dom-construct"); | ||
| import attr = require("dojo/dom-attr"); | ||||
| import { argumentNotNull } from "@implab/core-amd/safe"; | ||||
| import { BuildContextBase } from "./BuildContextBase"; | ||||
| 
              
  
   | 
            
            r48 | import registry = require("dijit/registry"); | ||
| 
              
  
   | 
            
            r34 | |||
| 
              
  
   | 
            
            r48 | export class FunctionComponentContext extends BuildContextBase<Node> { | ||
| private _component: (props: any) => any; | ||||
| 
              
  
   | 
            
            r34 | |||
| 
              
  
   | 
            
            r48 | private _node: Node | undefined; | ||
| 
              
  
   | 
            
            r34 | |||
| 
              
  
   | 
            
            r48 | constructor(component: (props: any) => any) { | ||
| 
              
  
   | 
            
            r34 | super(); | ||
| argumentNotNull(component, "component"); | ||||
| this._component = component; | ||||
| } | ||||
| _create(attrs: object, children: any[]) { | ||||
| const _attrs: any = attrs || {}; | ||||
| _attrs.children = children.map(x => this.getChildDom(x)); | ||||
| 
              
  
   | 
            
            r48 | this._node = this.getChildDom(this._component.call(null, _attrs)); | ||
| 
              
  
   | 
            
            r34 | } | ||
| _getDomNode() { | ||||
| 
              
  
   | 
            
            r48 | if (!this._node) | ||
| 
              
  
   | 
            
            r34 | throw new Error("The instance of the widget isn't created"); | ||
| 
              
  
   | 
            
            r48 | return this._node; | ||
| 
              
  
   | 
            
            r34 | } | ||
| } | ||||
