egoist
3/7/2016 - 9:05 AM

eva_draft.js

import h from 'virtual-dom/h'
import createElement from 'virtual-dom/create-element'

const eva = (...args) => {
  const [tag, props, ...children] = args

  if (typeof tag === 'string') {
    return h(tag, props, children)
  } else if (typeof tag === 'object') {
    const self = {
      props,
      children,
      state: tag.state()
    }
    const res = tag.render.call(self)
    console.log(res)
    return res
  }
}

const render = (tree, selector) => {
  const el = createElement(tree)
  document.querySelector(selector).appendChild(el)
}

export default eva
export {render}