1 module.exports = CollectingHandler;
3 function CollectingHandler(cbs) {
8 var EVENTS = require("./").EVENTS;
9 Object.keys(EVENTS).forEach(function(name) {
10 if (EVENTS[name] === 0) {
12 CollectingHandler.prototype[name] = function() {
13 this.events.push([name]);
14 if (this._cbs[name]) this._cbs[name]();
16 } else if (EVENTS[name] === 1) {
18 CollectingHandler.prototype[name] = function(a) {
19 this.events.push([name, a]);
20 if (this._cbs[name]) this._cbs[name](a);
22 } else if (EVENTS[name] === 2) {
24 CollectingHandler.prototype[name] = function(a, b) {
25 this.events.push([name, a, b]);
26 if (this._cbs[name]) this._cbs[name](a, b);
29 throw Error("wrong number of arguments");
33 CollectingHandler.prototype.onreset = function() {
35 if (this._cbs.onreset) this._cbs.onreset();
38 CollectingHandler.prototype.restart = function() {
39 if (this._cbs.onreset) this._cbs.onreset();
41 for (var i = 0, len = this.events.length; i < len; i++) {
42 if (this._cbs[this.events[i][0]]) {
43 var num = this.events[i].length;
46 this._cbs[this.events[i][0]]();
47 } else if (num === 2) {
48 this._cbs[this.events[i][0]](this.events[i][1]);
50 this._cbs[this.events[i][0]](