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
|
// Returns this.connector
|
||||||
Basestar.prototype.defineAdaptorEvent = function(opts) {
|
Basestar.prototype.defineAdaptorEvent = function(opts) {
|
||||||
if (typeof opts === 'string') {
|
return this._proxyEvents(opts, this.connector, this.connection);
|
||||||
opts = { eventName: opts };
|
|
||||||
}
|
|
||||||
|
|
||||||
opts['source'] = this.connector;
|
|
||||||
opts['target'] = this.connection;
|
|
||||||
|
|
||||||
return this.defineEvent(opts);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Public: Creates an event handler that proxies events from an device's
|
// Public: Creates an event handler that proxies events from an device's
|
||||||
|
@ -93,12 +86,14 @@ Basestar.prototype.defineAdaptorEvent = function(opts) {
|
||||||
//
|
//
|
||||||
// Returns this.connection
|
// Returns this.connection
|
||||||
Basestar.prototype.defineDriverEvent = function(opts) {
|
Basestar.prototype.defineDriverEvent = function(opts) {
|
||||||
if (typeof opts === 'string') {
|
return this._proxyEvents(opts, this.connection, this.device);
|
||||||
opts = { eventName: opts };
|
};
|
||||||
}
|
|
||||||
|
|
||||||
opts['source'] = this.connection;
|
Basestar.prototype._proxyEvents = function(opts, source, target) {
|
||||||
opts['target'] = this.device;
|
opts = (typeof opts === 'string') ? { eventName: opts } : opts;
|
||||||
|
|
||||||
|
opts.source = source;
|
||||||
|
opts.target = target
|
||||||
|
|
||||||
return this.defineEvent(opts);
|
return this.defineEvent(opts);
|
||||||
};
|
}
|
||||||
|
|
Loading…
Reference in New Issue