<commit_before>var isObservable = require('../is-observable')
var Set = require('../set')
var watch = require('../watch')

module.exports = applyProperties

function applyProperties (target, properties, data) {
  var classList = Set()
  if (target.className) {
    classList.add(target.className)
  }

  for (var key in properties) {
    var valueOrObs = properties[key]
    var value = resolve(valueOrObs)

    if (key === 'style') {
      // TODO: handle observable at root for style objects
      for (var k in value) {
        var styleObs = isObservable(value[k]) ? value[k] : null
        if (styleObs) {
          data.bindings.push(new Binding(bindStyle, target, styleObs, k))
        } else {
          target.style.setProperty(k, value[k])
        }
      }
    } else if (key === 'hooks') {
      if (Array.isArray(value)) {
        value.forEach(function (v) {
          data.bindings.push(new HookBinding(v, target))
        })
      }
    } else if (key === 'attributes') {
      for (var k in value) {
        var attrObs = isObservable(value[k]) ? value[k] : null
        if (attrObs) {
          data.bindings.push(new Binding(bindAttr, target, attrObs, k))
        } else {
          target.setAttribute(k, value[k])
        }
      }
    } else if (key === 'events') {
      for (var name in value) {
        target.addEventListener(name, value[name], false)
      }
    } else if (key.slice(0, 3) === 'ev-') {
      target.addEventListener(key.slice(3), value, false)
    } else if (key === 'className' || key === 'classList') {
      if (Array.isArray(valueOrObs)) {
        valueOrObs.forEach(function (v) {
          classList.add(v)
        })
      } else {
        classList.add(valueOrObs)
      }
    } else {
      target[key] = value
      var obs = isObservable(valueOrObs) ? valueOrObs : null
      if (obs) {
        data.bindings.push(new Binding(bind, target, obs, key))
      }
    }
  }

  if (containsObservables(classList)) {
    data.bindings.push(new Binding(bindClassList, target, classList, 'className'))
  } else {
    // OPTIMISATION: no need to create a binding if the list is never going to change
    target.className = classList().join(' ')
  }
}

function containsObservables (obs) {
  for (var i = 0, len = obs.getLength(); i < len; i++) {
    if (isObservable(obs.get(i))) {<commit_msg>html-element: fix applying of functions as event handlers<commit_after>var isObservable = require('../is-observable')
var Set = require('../set')
var watch = require('../watch')

module.exports = applyProperties

function applyProperties (target, properties, data) {
  var classList = Set()
  if (target.className) {
    classList.add(target.className)
  }

  for (var key in properties) {
    var valueOrObs = properties[key]

    if (key === 'style') {
      // TODO: handle observable at root for style objects
      var value = resolve(valueOrObs)
      for (var k in value) {
        var styleObs = isObservable(value[k]) ? value[k] : null
        if (styleObs) {
          data.bindings.push(new Binding(bindStyle, target, styleObs, k))
        } else {
          target.style.setProperty(k, value[k])
        }
      }
    } else if (key === 'hooks') {
      var value = resolve(valueOrObs)
      if (Array.isArray(value)) {
        value.forEach(function (v) {
          data.bindings.push(new HookBinding(v, target))
        })
      }
    } else if (key === 'attributes') {
      var value = resolve(valueOrObs)
      for (var k in value) {
        var attrObs = isObservable(value[k]) ? value[k] : null
        if (attrObs) {
          data.bindings.push(new Binding(bindAttr, target, attrObs, k))
        } else {
          target.setAttribute(k, value[k])
        }
      }
    } else if (key === 'events') {
      for (var name in valueOrObs) {
        target.addEventListener(name, valueOrObs[name], false)
      }
    } else if (key.slice(0, 3) === 'ev-') {
      target.addEventListener(key.slice(3), valueOrObs, false)
    } else if (key === 'className' || key === 'classList') {
      if (Array.isArray(valueOrObs)) {
        valueOrObs.forEach(function (v) {
          classList.add(v)
        })
      } else {
        classList.add(valueOrObs)
      }
    } else {
      target[key] = resolve(valueOrObs)
      var obs = isObservable(valueOrObs) ? valueOrObs : null
      if (obs) {
        data.bindings.push(new Binding(bind, target, obs, key))
      }
    }
  }

  if (containsObservables(classList)) {
    data.bindings.push(new Binding(bindClassList, target, classList, 'className'))
  } else {
    // OPTIMISATION: no need to create a binding if the list is never going to change
    target.className = classList().join(' ')
  }
}

function containsObservables (obs) {
  for (var i = 0, len = obs.getLength(); i < len; i++) {
    if (isObservable(obs.get(i))) {
{'fraction_non_alphanumeric': 0.14170292106898694, 'fraction_numerical': 0.0016573441060700228, 'mean_word_length': 2.460931899641577, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, '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': '4002609', 'n_tokens_mistral': 1557, 'n_tokens_neox': 1515, 'n_words': 385}