<commit_before>var _ = require('lodash')
var bean = require('bean')

module.exports = Wagon

var delegateEventSplitter = /^(\S+)\s*(.*)$/

var noop = function(){}

function Wagon(options){
  this.options = (options || {})
  this.cid = _.uniqueId('c')
  this.initialize.apply(this, arguments)
  this.delegateEvents()
}

Wagon.prototype.initialize = noop

Wagon.prototype.delegateEvents = function(masterSelector, events){
  if (!(masterSelector || (masterSelector = _.result(this, 'selector'))))
    return this
  if (!(events || (events = _.result(this, 'events'))))
    return this

  this.undelegateEvents()

  for (var key in events) {
    var method = events[key]
    if (!_.isFunction(method)) method = this[events[key]]
    if (!method) continue

    var match = key.match(delegateEventSplitter)
    var eventName = match[1], selector = (match[2] || mainSelector)
    method = _.bind(method, this)
    eventName += '.' + this.cid

    // Delegate on document
    bean.on(document, eventName, selector, method)
  }
  return this
}

Wagon.prototype.undelegateEvents = function(){
  bean.off(document, 'click.' + this.cid)
}

Wagon.prototype.remove = function(){
  this.undelegateEvents()
}

Wagon.extend = function(){
  return extend.apply(this, arguments)
}

function extend(protoProps, staticProps){
  var parent = this;
  var child;

  // The constructor function for the new subclass is either defined by you
  // (the "constructor" property in your `extend` definition), or defaulted
  // by us to simply call the parent's constructor.
  if (protoProps && _.has(protoProps, 'constructor')) {
    child = protoProps.constructor;
  } else {
    child = function(){ return parent.apply(this, arguments); };
  }

  // Add static properties to the constructor function, if supplied.
  _.extend(child, parent, staticProps);

  // Set the prototype chain to inherit from `parent`, without calling
  // `parent`'s constructor function.
  var Surrogate = function(){ this.constructor = child; };
  Surrogate.prototype = parent.prototype;
  child.prototype = new Surrogate;

  // Add prototype properties (instance properties) to the subclass,
  // if supplied.
  if (protoProps) _.extend(child.prototype, protoProps);

  // Set a convenience property in case the parent's prototype is needed
  // later.
  child.__super__ = parent.prototype;

  return child;
}<commit_msg>do not silently fail<commit_after>var _ = require('lodash')
var bean = require('bean')

module.exports = Wagon

var delegateEventSplitter = /^(\S+)\s*(.*)$/

var noop = function(){}

function Wagon(options){
  this.options = (options || {})
  this.cid = _.uniqueId('c')
  this.initialize.apply(this, arguments)
  this.delegateEvents()
}

Wagon.prototype.initialize = noop

Wagon.prototype.delegateEvents = function(masterSelector, events){
  if (!(masterSelector || (masterSelector = _.result(this, 'selector'))))
    return this
  if (!(events || (events = _.result(this, 'events'))))
    return this

  this.undelegateEvents()

  for (var key in events) {
    var method = events[key]
    if (!_.isFunction(method)) method = this[events[key]]
    if (!method) throw new Error('Event handler '+ key + ' not found.')

    var match = key.match(delegateEventSplitter)
    var eventName = match[1], selector = (match[2] || mainSelector)
    method = _.bind(method, this)
    eventName += '.' + this.cid

    // Delegate on document
    bean.on(document, eventName, selector, method)
  }
  return this
}

Wagon.prototype.undelegateEvents = function(){
  bean.off(document, 'click.' + this.cid)
}

Wagon.prototype.remove = function(){
  this.undelegateEvents()
}

Wagon.extend = function(){
  return extend.apply(this, arguments)
}

function extend(protoProps, staticProps){
  var parent = this;
  var child;

  // The constructor function for the new subclass is either defined by you
  // (the "constructor" property in your `extend` definition), or defaulted
  // by us to simply call the parent's constructor.
  if (protoProps && _.has(protoProps, 'constructor')) {
    child = protoProps.constructor;
  } else {
    child = function(){ return parent.apply(this, arguments); };
  }

  // Add static properties to the constructor function, if supplied.
  _.extend(child, parent, staticProps);

  // Set the prototype chain to inherit from `parent`, without calling
  // `parent`'s constructor function.
  var Surrogate = function(){ this.constructor = child; };
  Surrogate.prototype = parent.prototype;
  child.prototype = new Surrogate;

  // Add prototype properties (instance properties) to the subclass,
  // if supplied.
  if (protoProps) _.extend(child.prototype, protoProps);

  // Set a convenience property in case the parent's prototype is needed
  // later.
  child.__super__ = parent.prototype;

  return child;
}
{'fraction_non_alphanumeric': 0.13320825515947468, 'fraction_numerical': 0.0008338544923910778, 'mean_word_length': 3.866125760649087, 'pattern_counts': {'":': 0, '<': 3, '<?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': '6007454', 'n_tokens_mistral': 1426, 'n_tokens_neox': 1387, 'n_words': 423}