Created
July 18, 2014 18:20
-
-
Save jxson/06c0442f72c402465ec4 to your computer and use it in GitHub Desktop.
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
var extend = require('xtend'); | |
module.exports = SinkEventHandler; | |
function SinkEventHandler(sink, data) { | |
if (!(this instanceof SinkEventHandler)) { | |
return new SinkEventHandler(sink, data); | |
} | |
this.sink = sink; | |
this.id = sink.id; | |
this.data = extend({ preventDefault: true }, data); | |
} | |
SinkEventHandler.prototype.handleEvent = handleEvent; | |
function handleEvent(ev) { | |
var data = this.data; | |
if (data.preventDefault) ev.preventDefault(); | |
if (typeof this.sink === 'function') { | |
this.sink(this.data); | |
} else { | |
this.sink.write(this.data); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment