add "event" for any event. fixes #171.

This commit is contained in:
Christopher Jeffrey 2015-08-31 03:35:47 -07:00
parent 793646955f
commit e4900bb037
3 changed files with 17 additions and 3 deletions

View File

@ -79,6 +79,10 @@ EventEmitter.prototype._emit = function(type, args) {
var handler = this._events[type]
, ret;
// if (type !== 'event') {
// this._emit('event', [type.replace(/^element /, '')].concat(args));
// }
if (!handler) {
if (type === 'error') {
throw new args[0];
@ -101,8 +105,11 @@ EventEmitter.prototype._emit = function(type, args) {
EventEmitter.prototype.emit = function(type) {
var args = slice.call(arguments, 1)
, params = slice.call(arguments)
, el = this;
this._emit('event', params);
if (this.type === 'screen') {
return this._emit(type, args);
}
@ -113,8 +120,13 @@ EventEmitter.prototype.emit = function(type) {
type = 'element ' + type;
args.unshift(this);
// `element` prefix
// params = [type].concat(args);
// no `element` prefix
// params.splice(1, 0, this);
do {
// el._emit('event', params);
if (!el._events[type]) continue;
if (el._emit(type, args) === false) {
return false;

View File

@ -443,9 +443,6 @@ Screen.prototype.destroy = function() {
};
Screen.prototype.log = function() {
if (this.debugLog) {
this.debugLog.log.apply(this.debugLog, arguments);
}
return this.program.log.apply(this.program, arguments);
};

View File

@ -30,6 +30,11 @@ screen.debugLog.on('show', function() {
screen.render();
});
screen.on('event', function(event, el) {
var type = (el && el.type) || Object.prototype.toString.call(el).slice(8, -1);
screen.program.log('emit("%s", {%s})', event, type);
});
screen.append(blessed.text({
top: 0,
left: 2,