コード例 #1
0
ファイル: jsonToVirtualDOM.js プロジェクト: leftees/act
const jsonToVirtualDOM = (json, history, namespaces) => {
  if (typeof json === 'string') {
    return jsonToVirtualDOM(['span', json], history)
  }

  const [tag, maybeAtsOrChildren, maybeChildren] = json
  let ats = {}
  let children = []

  if (typeof maybeAtsOrChildren !== 'undefined') {
    isAts(maybeAtsOrChildren)
      ? ats = maybeAtsOrChildren
      : children = maybeAtsOrChildren
  }

  if (typeof maybeChildren !== 'undefined') {
    children = maybeChildren
  }

  if (isArrayLike(children)) {
    children = map((el) => processChildren(el, history, tag, children, namespaces), children)
  } else if (typeof children === 'function') {
    if (children.namespace) {
      console.log('TODO namespace when function is single children')
    }
    const fn = children
    try {
      children = map((el) => processChildren(el, history, tag, children, namespaces), children())
    } catch (e) {
      const errorMessage = renderErrorMessage(tag, children, e, fn)
      throw errorMessage
//      if (globalErrorHandler) {
//        console.trace()
//        console.log(errorMessage)
 //       children = jsonToVirtualDOM(globalErrorHandler, history, globalErrorHandler)
  //    } else {
    //    throw errorMessage
     // }
    }
  } else if (children === false) {
    children = undefined
  }

  injectEventHandlers(ats, history, namespaces)

  if (ats['class']) {
    ats['class'] = classLists(...ats['class'])
  }

  return h(tag, attributeToProperty(ats), children)
}
コード例 #2
0
ファイル: jsonToVirtualDOM.js プロジェクト: leftees/act
const processChildren = (el, history, tag, children, namespaces = []) => {
  // To support the case where user does
  // ```
  // condition && ['div', ...]
  // ```
  // and `condition` is false
  if (el === false) {
    return []
  }

  if (isArrayLike(el)) {
    return jsonToVirtualDOM(el, history, namespaces)
  }

  let newChildren
  if (typeof el === 'function') {
    const fn = el
    try {
      newChildren = fn()
      if (el.namespace) {
        namespaces = [...namespaces, el.namespace]
      }
      return jsonToVirtualDOM(newChildren, history, namespaces)
    } catch (e) {
      const errorMessage = renderErrorMessage(tag, newChildren, e, fn)

//      if (globalErrorHandler) {
//        console.log(errorMessage)
//        console.trace()
//
 //       return jsonToVirtualDOM(globalErrorHandler, history)
 //     } else {
      throw errorMessage
 //     }
    }
  }

  return String(el)
}
コード例 #3
0
ファイル: jsonToVirtualDOM.js プロジェクト: leftees/act
const isAts = (maybeAts) =>
  (typeof maybeAts === 'object') && maybeAts !== null && !isArrayLike(maybeAts)