Reduce duplication in Basestar event proxying code
This commit is contained in:
parent
2c1c691cbc
commit
a4498d0281
|
@ -75,14 +75,7 @@ Basestar.prototype.defineEvent = function(opts) {
|
|||
//
|
||||
// Returns this.connector
|
||||
Basestar.prototype.defineAdaptorEvent = function(opts) {
|
||||
if (typeof opts === 'string') {
|
||||
opts = { eventName: opts };
|
||||
}
|
||||
|
||||
opts['source'] = this.connector;
|
||||
opts['target'] = this.connection;
|
||||
|
||||
return this.defineEvent(opts);
|
||||
return this._proxyEvents(opts, this.connector, this.connection);
|
||||
};
|
||||
|
||||
// Public: Creates an event handler that proxies events from an device's
|
||||
|
@ -93,12 +86,14 @@ Basestar.prototype.defineAdaptorEvent = function(opts) {
|
|||
//
|
||||
// Returns this.connection
|
||||
Basestar.prototype.defineDriverEvent = function(opts) {
|
||||
if (typeof opts === 'string') {
|
||||
opts = { eventName: opts };
|
||||
}
|
||||
return this._proxyEvents(opts, this.connection, this.device);
|
||||
};
|
||||
|
||||
opts['source'] = this.connection;
|
||||
opts['target'] = this.device;
|
||||
Basestar.prototype._proxyEvents = function(opts, source, target) {
|
||||
opts = (typeof opts === 'string') ? { eventName: opts } : opts;
|
||||
|
||||
opts.source = source;
|
||||
opts.target = target
|
||||
|
||||
return this.defineEvent(opts);
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue