Last active
August 29, 2015 14:04
-
-
Save corpix/f720704802e504607a8d to your computer and use it in GitHub Desktop.
Delegate as monkey!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{EventEmitter} = require('events') | |
_emit = EventEmitter::emit | |
EventEmitter::emit = (type) -> | |
args = Array::slice.call(arguments) | |
res = _emit.apply(@, args) | |
if @_delegates and @_delegates[type] | |
for delegate in @_delegates[type] | |
if delegate.emit.apply(delegate, args) | |
res = true | |
res | |
EventEmitter::delegate = (type, eventemitter) -> | |
if not @_delegates | |
@_delegates = {} | |
if not @_delegates[type] | |
@_delegates[type] = [] | |
@_delegates[type].push(eventemitter) | |
module.exports = {EventEmitter} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment