<commit_before>import createElement from 'virtual-dom/create-element'
import diff from 'virtual-dom/diff'
import patch from 'virtual-dom/patch'
import VText from 'virtual-dom/vnode/vtext'
import { getScheduler } from './scheduler-assignment'

export default class FullObservationWidget {
  constructor (observation) {
    this.type = 'Widget'
    this.observation = observation
    this.domNode = null
    this.vnode = null
    this.observationSubscription = null
  }

  init () {
    this.trackObservation()
    this.vnode = this.getObservationValue()
    this.domNode = createElement(this.vnode)
    return this.domNode
  }

  update (previous, domNode) {
    this.domNode = domNode
    this.trackObservation()
    this.vnode = this.getObservationValue()
    patch(domNode, diff(previous.vnode, this.vnode))
    previous.destroy()
  }

  destroy () {
    this.observationSubscription.dispose()
    this.observationSubscription = null
    this.domNode = null
    this.vnode = null
  }

  getObservationValue () {
    let value = this.observation.getValue()
    if (typeof value === 'string') {
      return new VText(value)
    } else {
      return value
    }
  }

  trackObservation () {
    this.observationSubscription = this.observation.onDidChangeValue((newVnode) => {
      getScheduler().updateDocument(() => {
        if (this.domNode) {
          patch(this.domNode, diff(this.vnode, newVnode))
          this.vnode = newVnode
        }
      })
    })
  }
}<commit_msg>Convert strings to VText nodes<commit_after>import createElement from 'virtual-dom/create-element'
import diff from 'virtual-dom/diff'
import patch from 'virtual-dom/patch'
import VText from 'virtual-dom/vnode/vtext'
import { getScheduler } from './scheduler-assignment'

export default class FullObservationWidget {
  constructor (observation) {
    this.type = 'Widget'
    this.observation = observation
    this.domNode = null
    this.vnode = null
    this.observationSubscription = null
  }

  init () {
    this.trackObservation()
    this.vnode = this.getObservationValue()
    this.domNode = createElement(this.vnode)
    return this.domNode
  }

  update (previous, domNode) {
    this.domNode = domNode
    this.trackObservation()
    this.vnode = this.getObservationValue()
    patch(domNode, diff(previous.vnode, this.vnode))
    previous.destroy()
  }

  destroy () {
    this.observationSubscription.dispose()
    this.observationSubscription = null
    this.domNode = null
    this.vnode = null
  }

  getObservationValue () {
    let value = this.observation.getValue()
    if (typeof value === 'string') {
      return new VText(value)
    } else {
      return value
    }
  }

  trackObservation () {
    this.observationSubscription = this.observation.onDidChangeValue(() => {
      getScheduler().updateDocument(() => {
        if (this.domNode) {
          let newVnode = this.getObservationValue()
          patch(this.domNode, diff(this.vnode, newVnode))
          this.vnode = newVnode
        }
      })
    })
  }
}
{'fraction_non_alphanumeric': 0.11239669421487604, 'fraction_numerical': 0.0, 'mean_word_length': 3.002645502645503, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '7533371', 'n_tokens_mistral': 932, 'n_tokens_neox': 928, 'n_words': 185}