<commit_before>import eventExtend from './events-extend';
import {EventStream} from 'vega-dataflow';

/**
 * Create a new event stream from an event source.
 * @param {object} source - The event source to monitor.
 * @param {string} type - The event type.
 * @param {function(object): boolean} [filter] - Event filter function.
 * @return {EventStream}
 */
export default function(source, type, filter) {
  var view = this,
      s = new EventStream(filter),
      send = function(e, item) {
        s.receive(eventExtend(view, e, item));
        view.run();
      },
      sources;

  if (source === 'view') {
    view._handler.on(type, send);
    return s;
  }

  if (source === 'window') {
    if (typeof window !== 'undefined') sources = [window];
  } else if (typeof document !== 'undefined') {
    sources = document.querySelectorAll(source);
  }

  if (!sources) {
    view.error('Can not resolve event source: ' + source);
  }

  for (var i=0, n=sources.length; i<n; ++i) {
    sources[i].addEventListener(type, send);
  }

  view._eventListeners.push({
    type:    type,
    sources: sources,
    handler: send
  });

  return s;
}
<commit_msg>Warn, not error, upon missing event source.<commit_after>import eventExtend from './events-extend';
import {EventStream} from 'vega-dataflow';

/**
 * Create a new event stream from an event source.
 * @param {object} source - The event source to monitor.
 * @param {string} type - The event type.
 * @param {function(object): boolean} [filter] - Event filter function.
 * @return {EventStream}
 */
export default function(source, type, filter) {
  var view = this,
      s = new EventStream(filter),
      send = function(e, item) {
        s.receive(eventExtend(view, e, item));
        view.run();
      },
      sources;

  if (source === 'view') {
    view._handler.on(type, send);
    return s;
  }

  if (source === 'window') {
    if (typeof window !== 'undefined') sources = [window];
  } else if (typeof document !== 'undefined') {
    sources = document.querySelectorAll(source);
  }

  if (!sources) {
    view.warn('Can not resolve event source: ' + source);
    return s;
  }

  for (var i=0, n=sources.length; i<n; ++i) {
    sources[i].addEventListener(type, send);
  }

  view._eventListeners.push({
    type:    type,
    sources: sources,
    handler: send
  });

  return s;
}

{'fraction_non_alphanumeric': 0.1522756273925989, 'fraction_numerical': 0.0008507018290089324, 'mean_word_length': 3.0412371134020617, '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': '2349305', 'n_tokens_mistral': 742, 'n_tokens_neox': 732, 'n_words': 222}