<commit_before>import { Interface, ModuleAPI } from '../../core'
import { init } from 'snabbdom'
import classModule from 'snabbdom/modules/class'
import attributesModule from 'snabbdom/modules/attributes'
import propsModule from 'snabbdom/modules/props'
import eventlistenersModule from './eventListeners'
import styleModule from 'snabbdom/modules/style'
import { default as _h } from './h'
import { VNode } from './vnode'

export const h = _h

export type View<S> = Interface<VNode, S>

export const viewHandler = selectorElm => (mod: ModuleAPI) => {
  let selector = (typeof selectorElm === 'string') ? selectorElm : ''
  let lastContainer
  let state

  // Common snabbdom patch function (convention over configuration)
  let patchFn = init([
    classModule,
    attributesModule,
    propsModule,
    eventlistenersModule(mod),
    styleModule,
  ])

  function handler (vnode: VNode) {
    let vnode_mapped = h('div' + selector, { key: selector }, [vnode])
    state = patchFn(state, <any> vnode_mapped)
    lastContainer = state
  }

  return {
    state,
    handle: (value: VNode) => {
      if (!state) {
        let container = selector !== '' ? document.querySelector(selector) : selectorElm
        if (!container) {
          return mod.error('view', `There are no element matching selector '${selector}'`)
        }
        state = container
        handler(state)
        handler(value)
      } else {
        handler(value)
      }
    },
    dispose: () => {},
  }
}
<commit_msg>Add VNode to View interface exports<commit_after>import { Interface, ModuleAPI } from '../../core'
import { init } from 'snabbdom'
import classModule from 'snabbdom/modules/class'
import attributesModule from 'snabbdom/modules/attributes'
import propsModule from 'snabbdom/modules/props'
import eventlistenersModule from './eventListeners'
import styleModule from 'snabbdom/modules/style'
import { default as _h } from './h'
import { VNode as _VNode } from './vnode'

export const h = _h

export type VNode = _VNode

export type View<S> = Interface<VNode, S>

export const viewHandler = selectorElm => (mod: ModuleAPI) => {
  let selector = (typeof selectorElm === 'string') ? selectorElm : ''
  let lastContainer
  let state

  // Common snabbdom patch function (convention over configuration)
  let patchFn = init([
    classModule,
    attributesModule,
    propsModule,
    eventlistenersModule(mod),
    styleModule,
  ])

  function handler (vnode: VNode) {
    let vnode_mapped = h('div' + selector, { key: selector }, [vnode])
    state = patchFn(state, <any> vnode_mapped)
    lastContainer = state
  }

  return {
    state,
    handle: (value: VNode) => {
      if (!state) {
        let container = selector !== '' ? document.querySelector(selector) : selectorElm
        if (!container) {
          return mod.error('view', `There are no element matching selector '${selector}'`)
        }
        state = container
        handler(state)
        handler(value)
      } else {
        handler(value)
      }
    },
    dispose: () => {},
  }
}

{'fraction_non_alphanumeric': 0.12017026850032744, 'fraction_numerical': 0.0, 'mean_word_length': 3.1734972677595628, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 17, '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': '4305411', 'n_tokens_mistral': 903, 'n_tokens_neox': 898, 'n_words': 263}