<commit_before>_ = require 'lodash'
Rx = require 'rx-lite'
isThunk = require 'virtual-dom/vnode/is-thunk'

z = require './z'
render = require './render'
isComponent = require './is_component'
ZThunk = require './z_thunk'

isZThunk = (node) ->
  isThunk(node) and node.component?

module.exports = ($$root, tree) ->
  if isComponent tree
    tree = z tree

  # FIXME
  unless isZThunk tree
    throw new Error 'Not passed a component'

  # FIXME: if re-binding does not stop listening for old tree changes
  # though maybe it's fine because the component unmounts
  onchange = _.debounce ->
    render $$root, new ZThunk {
      component: tree.component
      props: tree.props
    }

  tree.component.__onDirty = onchange

  # for full-page rendering, root node is never mounted
  $$root.__disposable?.dispose()
  $$root.__disposable = tree.component.state?.subscribe onchange

  render $$root, new ZThunk {<commit_msg>remove fixmes<commit_after>_ = require 'lodash'
Rx = require 'rx-lite'
isThunk = require 'virtual-dom/vnode/is-thunk'

z = require './z'
render = require './render'
isComponent = require './is_component'
ZThunk = require './z_thunk'

isZThunk = (node) ->
  isThunk(node) and node.component?

module.exports = ($$root, tree) ->
  if isComponent tree
    tree = z tree

  # TODO: support trees, not just components
  unless isZThunk tree
    throw new Error 'Passed a tree, not a component'

  onchange = _.debounce ->
    render $$root, new ZThunk {
      component: tree.component
      props: tree.props
    }

  tree.component.__onDirty = onchange

  # for full-page rendering, root node is never mounted
  $$root.__disposable?.dispose()
  $$root.__disposable = tree.component.state?.subscribe onchange

  render $$root, new ZThunk {
{'fraction_non_alphanumeric': 0.1150997150997151, 'fraction_numerical': 0.0, 'mean_word_length': 3.4455696202531647, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '5347029', 'n_tokens_mistral': 574, 'n_tokens_neox': 554, 'n_words': 175}