   return self
 
 module.exports = Runtime
+
+empty = (node) ->
+  node.removeChild(child) while child = node.firstChild

  node.nodeType is 11

valueBind = (element, value) ->
  element.value = value()

  # Because firing twice with the same value is idempotent just binding both
  # oninput and onchange handles the widest range of inputs and browser
  # inconsistencies.
  element.oninput = ->
    value(element.value)
  element.onchange = ->
    value(element.value)

  value.observe? (newValue) ->
    element.value = newValue

  switch element.nodeName
    when "SELECT"
      # HACK: Need to set the value, but probably don't have the option contents yet
      # so let's just do it after our execution suspends and we probably have them
      setTimeout ->
        element.value = value()
      , 0

  return

Runtime = (context) ->
  stack = []

  observeAttribute = (name, value) ->
    element = top()

    {nodeName} = element

    update = (newValue) ->
      if newValue? and newValue != false
        element.setAttribute name, newValue
      else
        element.removeAttribute name

    # TODO: Consolidate special bindings better than if/else
    if (name is "value") and (typeof value is "function")
      valueBind(element, value)
    else if (name is "checked") and (typeof value is "function")
      element.onchange = ->
        value element.checked
      bindObservable(element, value, update)
    else if binding = specialBindings[nodeName]?[name]
      binding(element, value)
    # Straight up onclicks, etc.
    else if name.match(/^on/) and isEvent(name.substr(2))
      element[name] = value
