lib/component-helpers.js
function initialize(component) {
  if (typeof component.update !== 'function') {
    throw new Error('Etch components must implement `update(props, children)`.')
  }

  let virtualNode = component.render()
  if (!isValidVirtualNode(virtualNode)) {
    let namePart = component.constructor && component.constructor.name ? ' in ' + component.constructor.name : ''
    throw new Error('invalid falsy value ' + virtualNode + ' returned from render()' + namePart)
  }

  applyContext(component, virtualNode)

  component.refs = {}
  component.virtualNode = virtualNode
  component.element = render(component.virtualNode, {
    refs: component.refs, listenerContext: component
  })
}
function initialize(component) {
  if (typeof component.update !== 'function') {
    throw new Error('Etch components must implement `update(props, children)`.')
  }

  let virtualNode = component.render()
  if (!isValidVirtualNode(virtualNode)) {
    let namePart = component.constructor && component.constructor.name ? ' in ' + component.constructor.name : ''
    throw new Error('invalid falsy value ' + virtualNode + ' returned from render()' + namePart)
  }

  applyContext(component, virtualNode)

  component.refs = {}
  component.virtualNode = virtualNode
  component.element = render(component.virtualNode, {
    refs: component.refs, listenerContext: component
  })
}
function initialize ( component ) { if ( typeof component . update !== 'function' ) { throw new Error ( 'Etch components must implement `update(props, children)`.' ) } let virtualNode = component . render ( ) if ( ! isValidVirtualNode ( virtualNode ) ) { let namePart = component . constructor && component . constructor . name ? ' in ' + component . constructor . name : '' throw new Error ( 'invalid falsy value ' + virtualNode + ' returned from render()' + namePart ) } applyContext ( component , virtualNode ) component . refs = { } component . virtualNode = virtualNode component . element = render ( component . virtualNode , { refs : component . refs , listenerContext : component } ) }
This function associates a component object with a DOM element by calling the components `render` method, assigning an `.element` property on the object and also returning the element.  It also assigns a `virtualNode` property based on the return value of the `render` method. This will be used later by `performElementUpdate` to diff the new results of `render` with the previous results when updating the component's element.  Finally, this function also associates the component with a `refs` object, which is populated with references to elements based on `ref` properties on nodes of the `virtual-dom` tree. Before calling into `virtual-dom` to create the DOM tree, it pushes this `refs` object to a shared stack so it can be accessed by hooks during the creation of individual elements.
This function associates a component object with a DOM element by calling the components render method assigning an . element property on the object and also returning the element . It also assigns a virtualNode property based on the return value of the render method . This will be used later by performElementUpdate to diff the new results of render with the previous results when updating the component s element . Finally this function also associates the component with a refs object which is populated with references to elements based on ref properties on nodes of the virtual - dom tree . Before calling into virtual - dom to create the DOM tree it pushes this refs object to a shared stack so it can be accessed by hooks during the creation of individual elements .