<commit_before>import { VNode, VNodeData } from './vnode'
import { Module } from 'snabbdom/modules/module'
import { computeEvent, InputData, ModuleAPI } from '../../core'

export interface On {
  [event: string]: InputData | 'ignore'
}

export const eventListenersModule = (mod: ModuleAPI): Module => {

  function invokeHandler(handler: InputData | 'ignore', event?: Event): void {
    if (handler instanceof Array && typeof handler[0] === 'string') {
      let options = handler[4]
      if (!options || options.default === undefined || options.default) {
        event.preventDefault()
      }
      if (!options || options.propagate === undefined || options.propagate) {
        event.stopPropagation()
      }
      // call function handler
      requestAnimationFrame(() => {
        setTimeout(() => {
          mod.dispatch(computeEvent(event, handler))
        }, 0)
      })
    } else if (handler instanceof Array) {
      // call multiple handlers
      for (var i = 0; i < handler.length; i++) {
        invokeHandler(handler[i])
      }
    } else if (handler === 'ignore') {
      // TODO: document ignored and passed view event handlers
      // this handler is ignored
      event.preventDefault()
      event.stopPropagation()
    } else if (handler === '' && handler === undefined) {
      // this handler is passed
      return
    } else {
      mod.error('ViewInterface-eventListenersModule', 'event handler of type ' + typeof handler + 'are not allowed, data: ' + JSON.stringify(handler))
    }
  }

  function handleEvent(event: Event, vnode: VNode) {
    var name = event.type,
        on = (vnode.data as VNodeData).on

    // call event handler(s) if exists
    if (on && on[name]) {
      invokeHandler(on[name], event)
    }
  }

  function createListener() {
    return function handler(event: Event) {<commit_msg>Fix default and propagate eventListeners  and speed-up it<commit_after>import { VNode, VNodeData } from './vnode'
import { Module } from 'snabbdom/modules/module'
import { computeEvent, InputData, ModuleAPI } from '../../core'

export interface On {
  [event: string]: InputData | 'ignore'
}

export const eventListenersModule = (mod: ModuleAPI): Module => {

  function invokeHandler(handler: InputData | 'ignore', event?: Event): void {
    if (handler instanceof Array && typeof handler[0] === 'string') {
      let options = handler[4]
      if (!options || options.default === undefined || !options.default) {
        event.preventDefault()
      }
      if (!options || options.propagate === undefined || !options.propagate) {
        event.stopPropagation()
      }
      mod.dispatch(computeEvent(event, handler))
    } else if (handler instanceof Array) {
      // call multiple handlers
      for (var i = 0; i < handler.length; i++) {
        invokeHandler(handler[i])
      }
    } else if (handler === 'ignore') {
      // TODO: document ignored and passed view event handlers
      // this handler is ignored
      event.preventDefault()
      event.stopPropagation()
    } else if (handler === '' && handler === undefined) {
      // this handler is passed
      return
    } else {
      mod.error('ViewInterface-eventListenersModule', 'event handler of type ' + typeof handler + 'are not allowed, data: ' + JSON.stringify(handler))
    }
  }

  function handleEvent(event: Event, vnode: VNode) {
    var name = event.type,
        on = (vnode.data as VNodeData).on

    // call event handler(s) if exists
    if (on && on[name]) {
      invokeHandler(on[name], event)
    }
  }

  function createListener() {
    return function handler(event: Event) {
{'fraction_non_alphanumeric': 0.13340714088015498, 'fraction_numerical': 0.0019374481040686411, 'mean_word_length': 2.8243386243386244, 'pattern_counts': {'":': 0, '<': 5, '<?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': '1066452', 'n_tokens_mistral': 1004, 'n_tokens_neox': 999, 'n_words': 301}