<commit_before>import { $each, $setRef, $sel } from 'core/dom';
import { $extend, $isObject, $isString, $toArray } from 'core/types';
import { $exec } from 'core/core';
import { _doc } from 'core/variables';

let custom = {};
let bound = [];

function _bind(els, obj, options) {
	// Redefine variables when delegating
	if (options && options.delegate) {
		options.targ = els;
		els = options.delegate;
	}

	// For each element attach events
	$each(els, el => {
		// Loop through object events
		for (let key in obj) {
			let evts = key.split(' ');
			let	i = 0;

			for (; i < evts.length; i++) {
				let conf = $extend({
						args: [],
						once: false,
						scope: el
					}, options);
				let	fn = obj[key];
				let	evt = evts[i];
				let	ev = evt;
				let	parts = ev.split('.');
				let	f = fn;
				evt = parts[0];

				if (parts.length == 1 && conf.namespace) {
					ev += '.' + conf.namespace;
				}

				// Prepend element to callback arguments if necessary
				if (conf.args[1] !== el) {
					conf.args.unshift(0, el);
				}

				(function(el, evt, fn, f, conf) {
					let cb = e => {
						let cont = true;
						conf.args[0] = e;

						// If watch within ancestor make sure the target
						// matches the selector
						if (conf.targ) {
							let targ = conf.targ;
							let	sel = targ._$ ? targ.sel : targ;

							// Update refs when targeting ref
							if ($isString(sel) &&
								sel.indexOf('ref:') > -1) {
								$setRef(el);
							}

							cont = $toArray($sel(sel)).some(el => el.contains(e.target) && (targ = el));

							// Ensure element argument is the target
							conf.args[1] = conf.scope = targ;
						}

						if (cont) {
							$exec(fn, conf);

							// Unbind after first execution
							if (conf.once) {
								_off(el, evt, f);
							}
						}
					};

					// Ensure the specified element, event, and function
					// combination hasn't already been bound
					if (evt != 'init' && ! _bound(el, ev, f, conf.targ).length) {
						// Determine if the event is native or custom
						if ('on' + evt in el) {
							el.addEventListener(evt, cb, false);
						} else if (custom[evt]) {
							custom[evt][0](el, fn, conf);
						}

						bound.push({
							el: el,
							ev: ev,
							evt: evt,
							cb: cb,
							fn: f,
							targ: conf.targ
						});
					}

					if (evt == 'init' || conf.init === true) {
						cb();
					}
				})(el, evt, fn, f, conf);
			}
		}
	}, options);
}

/**
 * Detach event(s) from element
 *
 * @private
 * @param {(HTMLElement|string)} [sel]
 * @param {string} [evt]
 * @param {function} [fn]
 */
function _off(sel, evt, fn) {
	$each(_bound(sel, evt, fn), e => {
		if ('on' + e.evt in _doc) {
			e.el.removeEventListener(e.evt, e.cb);
		} else if (custom[e.evt]) {
			custom[e.evt][1](e.el, e.cb);
		}

		bound.splice(bound.indexOf(e), 1);
	});
}

function _bound(target, event, fn, delegateTarg) {
	let segs = (event || '').split('.');
	let	matches = [];
	target = target || [0];

	$each(target, el => {
		Object.keys(bound).forEach(e => {
			let binding = bound[e];
			let	parts = binding.ev.split('.');
			let	match = true;

			if (el && el !== binding.el) {
				match = false;
			}

			if (event &&
				(
					segs[0] !== '' &&
					segs[0] != parts[0]
				) ||
				(
					segs[1] &&
					segs[1] != parts[1]
				)) {<commit_msg>Put broken down conditional on single line<commit_after>import { $each, $setRef, $sel } from 'core/dom';
import { $extend, $isObject, $isString, $toArray } from 'core/types';
import { $exec } from 'core/core';
import { _doc } from 'core/variables';

let custom = {};
let bound = [];

function _bind(els, obj, options) {
	// Redefine variables when delegating
	if (options && options.delegate) {
		options.targ = els;
		els = options.delegate;
	}

	// For each element attach events
	$each(els, el => {
		// Loop through object events
		for (let key in obj) {
			let evts = key.split(' ');
			let	i = 0;

			for (; i < evts.length; i++) {
				let conf = $extend({
						args: [],
						once: false,
						scope: el
					}, options);
				let	fn = obj[key];
				let	evt = evts[i];
				let	ev = evt;
				let	parts = ev.split('.');
				let	f = fn;
				evt = parts[0];

				if (parts.length == 1 && conf.namespace) {
					ev += '.' + conf.namespace;
				}

				// Prepend element to callback arguments if necessary
				if (conf.args[1] !== el) {
					conf.args.unshift(0, el);
				}

				(function(el, evt, fn, f, conf) {
					let cb = e => {
						let cont = true;
						conf.args[0] = e;

						// If watch within ancestor make sure the target
						// matches the selector
						if (conf.targ) {
							let targ = conf.targ;
							let	sel = targ._$ ? targ.sel : targ;

							// Update refs when targeting ref
							if ($isString(sel) &&
								sel.indexOf('ref:') > -1) {
								$setRef(el);
							}

							cont = $toArray($sel(sel)).some(el => el.contains(e.target) && (targ = el));

							// Ensure element argument is the target
							conf.args[1] = conf.scope = targ;
						}

						if (cont) {
							$exec(fn, conf);

							// Unbind after first execution
							if (conf.once) {
								_off(el, evt, f);
							}
						}
					};

					// Ensure the specified element, event, and function
					// combination hasn't already been bound
					if (evt != 'init' && ! _bound(el, ev, f, conf.targ).length) {
						// Determine if the event is native or custom
						if ('on' + evt in el) {
							el.addEventListener(evt, cb, false);
						} else if (custom[evt]) {
							custom[evt][0](el, fn, conf);
						}

						bound.push({
							el: el,
							ev: ev,
							evt: evt,
							cb: cb,
							fn: f,
							targ: conf.targ
						});
					}

					if (evt == 'init' || conf.init === true) {
						cb();
					}
				})(el, evt, fn, f, conf);
			}
		}
	}, options);
}

/**
 * Detach event(s) from element
 *
 * @private
 * @param {(HTMLElement|string)} [sel]
 * @param {string} [evt]
 * @param {function} [fn]
 */
function _off(sel, evt, fn) {
	$each(_bound(sel, evt, fn), e => {
		if ('on' + e.evt in _doc) {
			e.el.removeEventListener(e.evt, e.cb);
		} else if (custom[e.evt]) {
			custom[e.evt][1](e.el, e.cb);
		}

		bound.splice(bound.indexOf(e), 1);
	});
}

function _bound(target, event, fn, delegateTarg) {
	let segs = (event || '').split('.');
	let	matches = [];
	target = target || [0];

	$each(target, el => {
		Object.keys(bound).forEach(e => {
			let binding = bound[e];
			let	parts = binding.ev.split('.');
			let	match = true;

			if (el && el !== binding.el) {
				match = false;
			}

			if (event && (segs[0] !== '' && segs[0] != parts[0]) || (segs[1] && segs[1] != parts[1])) {
{'fraction_non_alphanumeric': 0.17956843217141996, 'fraction_numerical': 0.005432322317790856, 'mean_word_length': 2.1190588235294117, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 17, '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': '4587221', 'n_tokens_mistral': 3152, 'n_tokens_neox': 2426, 'n_words': 652}