Sha256: 5c5ee0ffa55e23baea4645bd9a6d5bda77b5533da6aba37066010b6b2e07d53f

Contents?: true

Size: 1.35 KB

Versions: 22

Compression:

Stored size: 1.35 KB

Contents

module.exports = CollectingHandler;

function CollectingHandler(cbs){
	this._cbs = cbs || {};
	this.events = [];
}

var EVENTS = require("./").EVENTS;
Object.keys(EVENTS).forEach(function(name){
	if(EVENTS[name] === 0){
		name = "on" + name;
		CollectingHandler.prototype[name] = function(){
			this.events.push([name]);
			if(this._cbs[name]) this._cbs[name]();
		};
	} else if(EVENTS[name] === 1){
		name = "on" + name;
		CollectingHandler.prototype[name] = function(a){
			this.events.push([name, a]);
			if(this._cbs[name]) this._cbs[name](a);
		};
	} else if(EVENTS[name] === 2){
		name = "on" + name;
		CollectingHandler.prototype[name] = function(a, b){
			this.events.push([name, a, b]);
			if(this._cbs[name]) this._cbs[name](a, b);
		};
	} else {
		throw Error("wrong number of arguments");
	}
});

CollectingHandler.prototype.onreset = function(){
	this.events = [];
	if(this._cbs.onreset) this._cbs.onreset();
};

CollectingHandler.prototype.restart = function(){
	if(this._cbs.onreset) this._cbs.onreset();

	for(var i = 0, len = this.events.length; i < len; i++){
		if(this._cbs[this.events[i][0]]){

			var num = this.events[i].length;

			if(num === 1){
				this._cbs[this.events[i][0]]();
			} else if(num === 2){
				this._cbs[this.events[i][0]](this.events[i][1]);
			} else {
				this._cbs[this.events[i][0]](this.events[i][1], this.events[i][2]);
			}
		}
	}
};

Version data entries

22 entries across 19 versions & 5 rubygems

Version Path
locomotivecms-4.0.0.alpha1 app/javascript/node_modules/htmlparser2/lib/CollectingHandler.js
locomotivecms-3.4.0 app/javascript/node_modules/htmlparser2/lib/CollectingHandler.js
lanes-0.8.0 node_modules/htmlparser2/lib/CollectingHandler.js
xcodebuild-helper-1.2.5 externals/ios-sim-master/node_modules/htmlparser2/lib/CollectingHandler.js
tck-lambdas-0.3.10 lib/tck/lambdas/chistacojs/source/node_modules/cheerio/node_modules/htmlparser2/lib/CollectingHandler.js
tck-lambdas-0.3.9 lib/tck/lambdas/chistacojs/source/node_modules/cheerio/node_modules/htmlparser2/lib/CollectingHandler.js
tck-lambdas-0.3.8 lib/tck/lambdas/chistacojs/source/node_modules/cheerio/node_modules/htmlparser2/lib/CollectingHandler.js
tck-lambdas-0.3.7 lib/tck/lambdas/chistacojs/source/node_modules/cheerio/node_modules/htmlparser2/lib/CollectingHandler.js
tck-lambdas-0.3.6 lib/tck/lambdas/chistacojs/source/node_modules/cheerio/node_modules/htmlparser2/lib/CollectingHandler.js
tck-lambdas-0.3.5 lib/tck/lambdas/chistacojs/source/node_modules/cheerio/node_modules/htmlparser2/lib/CollectingHandler.js
tck-lambdas-0.3.4 lib/tck/lambdas/chistacojs/source/node_modules/cheerio/node_modules/htmlparser2/lib/CollectingHandler.js
tck-lambdas-0.3.3 lib/tck/lambdas/chistacojs/source/node_modules/cheerio/node_modules/htmlparser2/lib/CollectingHandler.js
tck-lambdas-0.3.2 lib/tck/lambdas/chistacojs/source/node_modules/cheerio/node_modules/htmlparser2/lib/CollectingHandler.js
tck-lambdas-0.3.1 lib/tck/lambdas/chistacojs/source/node_modules/cheerio/node_modules/htmlparser2/lib/CollectingHandler.js
tck-lambdas-0.3.0 lib/tck/lambdas/chistacojs/node_modules/cheerio/node_modules/htmlparser2/lib/CollectingHandler.js
tck-lambdas-0.3.0 lib/tck/lambdas/chistacojs/source/node_modules/cheerio/node_modules/htmlparser2/lib/CollectingHandler.js
tck-lambdas-0.2.0 lib/tck/lambdas/chistacojs/source/node_modules/cheerio/node_modules/htmlparser2/lib/CollectingHandler.js
tck-lambdas-0.2.0 lib/tck/lambdas/chistacojs/node_modules/cheerio/node_modules/htmlparser2/lib/CollectingHandler.js
tck-lambdas-0.1.6 lib/tck/lambdas/chistacojs/node_modules/cheerio/node_modules/htmlparser2/lib/CollectingHandler.js
tck-lambdas-0.1.6 lib/tck/lambdas/chistacojs/source/node_modules/cheerio/node_modules/htmlparser2/lib/CollectingHandler.js