<commit_before>export { h, app }

function app(props, container) {
  var root = (container = container || document.body).children[0]
  var node = vnode(root, [].map)
  var appState = {}
  var appActions = {}
  var lifecycle = []
  var patchLock

  repaint(init(appState, appActions, props, []))
 
  return appActions

  function vnode(element, map) {
    return (
      element &&
      h(
        element.tagName.toLowerCase(),
        {},
        map.call(element.childNodes, function(element) {
          return element.nodeType === 3
            ? element.nodeValue
            : vnode(element, map)
        })
      )
    )
  }

  function repaint() {
    if (props.view && !patchLock) {
      setTimeout(render, (patchLock = !patchLock))
    }
  }

  function render(next) {
    patchLock = !patchLock
    if ((next = props.view(appState, appActions)) && !patchLock) {
      root = patch(container, root, node, (node = next))
    }
    while ((next = lifecycle.pop())) next()
  }

  function init(state, actions, from, path) {
    var modules = from.modules

    initDeep(state, actions, from.actions, path)
    set(state, from.state)

    for (var i in modules) {
      init((state[i] = {}), (actions[i] = {}), modules[i], path.concat(i))
    }
  }

  function initDeep(state, actions, from, path) {
    Object.keys(from || {}).map(function(key) {
      if (typeof from[key] === "function") {
        actions[key] = function(data) {
          var result = from[key]((state = get(path, appState)), actions)

          if (typeof result === "function") {
            result = result(data)
          }

          if (result && result !== state && !result.then) {
            repaint((appState = setDeep(path, merge(state, result), appState)))
          }

          return result
        }
      } else {
        initDeep(
          state[key] || (state[key] = {}),
          (actions[key] = {}),
          from[key],
          path.concat(key)
        )
      }
    })
  }

  function merge(to, from) {
    return set(set({}, to), from)
  }

  function set(to, from) {
    for (var i in from) {
      to[i] = from[i]
    }
    return to
  }

  function setDeep(path, value, from) {
    var to = {}
    return path.length === 0
      ? value
      : ((to[path[0]] =
          1 < path.length
            ? setDeep(path.slice(1), value, from[path[0]])
            : value),
        merge(from, to))
  }

  function get(path, from) {
    for (var i = 0; i < path.length; i++) {
      from = from[path[i]]
    }
    return from
  }

  function createElement(node, isSVG) {
    if (typeof node === "string") {
      var element = document.createTextNode(node)
    } else {
      var element = (isSVG = isSVG || node.type === "svg")
        ? document.createElementNS("http://www.w3.org/2000/svg", node.type)
        : document.createElement(node.type)

      if (node.props.oncreate) {
        lifecycle.push(function() {
          node.props.oncreate(element)
        })
      }

      for (var i = 0; i < node.children.length; i++) {
        element.appendChild(createElement(node.children[i], isSVG))
      }

      for (var i in node.props) {
        setElementProp(element, i, node.props[i])
      }
    }
    return element
  }

  function setElementProp(element, name, value, oldValue) {
    if (name === "key") {
    } else if (name === "style") {
      for (var name in merge(oldValue, (value = value || {}))) {
        element.style[name] = value[name] || ""
      }
    } else {
      try {
        element[name] = null == value ? "" : value
      } catch (_) {}

      if (typeof value !== "function") {
        if (null == value || false === value) {
          element.removeAttribute(name)
        } else {
          element.setAttribute(name, value)
        }
      }
    }
  }

  function updateElement(element, oldProps, props) {
    for (var i in merge(oldProps, props)) {
      var value = props[i]
      var oldValue = i === "value" || i === "checked" ? element[i] : oldProps[i]

      if (value !== oldValue) {
        setElementProp(element, i, value, oldValue)
      }
    }

    if (props.onupdate) {
      lifecycle.push(function() {
        props.onupdate(element, oldProps)
      })
    }
  }

  function removeElement(parent, element, props) {
    if (props && props.onremove) {
      props.onremove(element, done)
    } else {
      done()
    }

    function done() {
      parent.removeChild(element)
    }
  }

  function getKey(node) {
    if (node && node.props) {
      return node.props.key
    }
  }

  function patch(parent, element, oldNode, node, isSVG, nextSibling) {
    if (oldNode == null) {
      element = parent.insertBefore(createElement(node, isSVG), element)
    } else if (node.type != null && node.type === oldNode.type) {
      updateElement(element, oldNode.props, node.props)

      isSVG = isSVG || node.type === "svg"

      var len = node.children.length
      var oldLen = oldNode.children.length
      var oldKeyed = {}
      var oldElements = []
      var keyed = {}

      for (var i = 0; i < oldLen; i++) {
        var oldElement = (oldElements[i] = element.childNodes[i])
        var oldChild = oldNode.children[i]
        var oldKey = getKey(oldChild)

        if (null != oldKey) {
          oldKeyed[oldKey] = [oldElement, oldChild]
        }
      }

      var i = 0
      var j = 0<commit_msg>add short circuit for patching memoized vnodes (#378)<commit_after>export { h, app }

function app(props, container) {
  var root = (container = container || document.body).children[0]
  var node = vnode(root, [].map)
  var appState = {}
  var appActions = {}
  var lifecycle = []
  var patchLock

  repaint(init(appState, appActions, props, []))
 
  return appActions

  function vnode(element, map) {
    return (
      element &&
      h(
        element.tagName.toLowerCase(),
        {},
        map.call(element.childNodes, function(element) {
          return element.nodeType === 3
            ? element.nodeValue
            : vnode(element, map)
        })
      )
    )
  }

  function repaint() {
    if (props.view && !patchLock) {
      setTimeout(render, (patchLock = !patchLock))
    }
  }

  function render(next) {
    patchLock = !patchLock
    if ((next = props.view(appState, appActions)) && !patchLock) {
      root = patch(container, root, node, (node = next))
    }
    while ((next = lifecycle.pop())) next()
  }

  function init(state, actions, from, path) {
    var modules = from.modules

    initDeep(state, actions, from.actions, path)
    set(state, from.state)

    for (var i in modules) {
      init((state[i] = {}), (actions[i] = {}), modules[i], path.concat(i))
    }
  }

  function initDeep(state, actions, from, path) {
    Object.keys(from || {}).map(function(key) {
      if (typeof from[key] === "function") {
        actions[key] = function(data) {
          var result = from[key]((state = get(path, appState)), actions)

          if (typeof result === "function") {
            result = result(data)
          }

          if (result && result !== state && !result.then) {
            repaint((appState = setDeep(path, merge(state, result), appState)))
          }

          return result
        }
      } else {
        initDeep(
          state[key] || (state[key] = {}),
          (actions[key] = {}),
          from[key],
          path.concat(key)
        )
      }
    })
  }

  function merge(to, from) {
    return set(set({}, to), from)
  }

  function set(to, from) {
    for (var i in from) {
      to[i] = from[i]
    }
    return to
  }

  function setDeep(path, value, from) {
    var to = {}
    return path.length === 0
      ? value
      : ((to[path[0]] =
          1 < path.length
            ? setDeep(path.slice(1), value, from[path[0]])
            : value),
        merge(from, to))
  }

  function get(path, from) {
    for (var i = 0; i < path.length; i++) {
      from = from[path[i]]
    }
    return from
  }

  function createElement(node, isSVG) {
    if (typeof node === "string") {
      var element = document.createTextNode(node)
    } else {
      var element = (isSVG = isSVG || node.type === "svg")
        ? document.createElementNS("http://www.w3.org/2000/svg", node.type)
        : document.createElement(node.type)

      if (node.props.oncreate) {
        lifecycle.push(function() {
          node.props.oncreate(element)
        })
      }

      for (var i = 0; i < node.children.length; i++) {
        element.appendChild(createElement(node.children[i], isSVG))
      }

      for (var i in node.props) {
        setElementProp(element, i, node.props[i])
      }
    }
    return element
  }

  function setElementProp(element, name, value, oldValue) {
    if (name === "key") {
    } else if (name === "style") {
      for (var name in merge(oldValue, (value = value || {}))) {
        element.style[name] = value[name] || ""
      }
    } else {
      try {
        element[name] = null == value ? "" : value
      } catch (_) {}

      if (typeof value !== "function") {
        if (null == value || false === value) {
          element.removeAttribute(name)
        } else {
          element.setAttribute(name, value)
        }
      }
    }
  }

  function updateElement(element, oldProps, props) {
    for (var i in merge(oldProps, props)) {
      var value = props[i]
      var oldValue = i === "value" || i === "checked" ? element[i] : oldProps[i]

      if (value !== oldValue) {
        setElementProp(element, i, value, oldValue)
      }
    }

    if (props.onupdate) {
      lifecycle.push(function() {
        props.onupdate(element, oldProps)
      })
    }
  }

  function removeElement(parent, element, props) {
    if (props && props.onremove) {
      props.onremove(element, done)
    } else {
      done()
    }

    function done() {
      parent.removeChild(element)
    }
  }

  function getKey(node) {
    if (node && node.props) {
      return node.props.key
    }
  }

  function patch(parent, element, oldNode, node, isSVG, nextSibling) {
    if (oldNode === node) {
    } else if (oldNode == null) {
      element = parent.insertBefore(createElement(node, isSVG), element)
    } else if (node.type != null && node.type === oldNode.type) {
      updateElement(element, oldNode.props, node.props)

      isSVG = isSVG || node.type === "svg"

      var len = node.children.length
      var oldLen = oldNode.children.length
      var oldKeyed = {}
      var oldElements = []
      var keyed = {}

      for (var i = 0; i < oldLen; i++) {
        var oldElement = (oldElements[i] = element.childNodes[i])
        var oldChild = oldNode.children[i]
        var oldKey = getKey(oldChild)

        if (null != oldKey) {
          oldKeyed[oldKey] = [oldElement, oldChild]
        }
      }

      var i = 0
      var j = 0
{'fraction_non_alphanumeric': 0.1496434855079174, 'fraction_numerical': 0.0034262431706639502, 'mean_word_length': 2.10077519379845, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2039543', 'n_tokens_mistral': 3506, 'n_tokens_neox': 3423, 'n_words': 800}