<commit_before>jsio('from shared.javascript import Class');

exports = Class(function() {
	
	this.init = function() {
		this._subscribers = {};
	}
	
	this.subscribe = function(signal, callback) {
		if (!this._subscribers[signal]) { this._subscribers[signal] = []; }
		this._subscribers[signal].push(callback);
		return callback
	}

	this.unsubscribe = function(signal, targetCallback) {
		var subscribers = this._subscribers[signal] || []
		for (var i=0, callback; callback = subscribers[i]; i++) {
			if (callback != targetCallback) { continue }
			subscribers.splice(i, 1)
			return
		}
	}
	
	this._publish = function(signal) {
		var args = Array.prototype.slice.call(arguments, 1)
		var subscribers = this._subscribers[signal] || []
		for (var i=0, callback; callback = subscribers[i]; i++) {
			callback.apply(this, args)
		}
	}
})<commit_msg>Make subscribe/unsubscrube chainable<commit_after>jsio('from shared.javascript import Class');

exports = Class(function() {
	
	this.init = function() {
		this._subscribers = {};
	}
	
	this.subscribe = function(signal, callback) {
		if (!this._subscribers[signal]) { this._subscribers[signal] = []; }
		this._subscribers[signal].push(callback);
		return this
	}

	this.unsubscribe = function(signal, targetCallback) {
		var subscribers = this._subscribers[signal] || []
		for (var i=0, callback; callback = subscribers[i]; i++) {
			if (callback != targetCallback) { continue }
			subscribers.splice(i, 1)
			return
		}
		return this
	}
	
	this._publish = function(signal) {
		var args = Array.prototype.slice.call(arguments, 1)
		var subscribers = this._subscribers[signal] || []
		for (var i=0, callback; callback = subscribers[i]; i++) {
			callback.apply(this, args)
		}
	}
})
{'fraction_non_alphanumeric': 0.15344528083381587, 'fraction_numerical': 0.004632310364794441, 'mean_word_length': 4.300613496932515, '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': '4402709', 'n_tokens_mistral': 629, 'n_tokens_neox': 554, 'n_words': 116}