Refactor Basestar#defineEvent
This commit is contained in:
parent
84f06afa5b
commit
520c523971
|
@ -52,19 +52,21 @@ namespace("Cylon", function() {
|
|||
//
|
||||
// Returns the source
|
||||
Basestar.prototype.defineEvent = function(opts) {
|
||||
var sendUpdate, targetEventName,
|
||||
_this = this;
|
||||
targetEventName = opts.targetEventName || opts.eventName;
|
||||
sendUpdate = opts.sendUpdate || false;
|
||||
var self = this;
|
||||
|
||||
opts.sendUpdate = opts.sendUpdate || false;
|
||||
opts.targetEventName = opts.targetEventName || opts.eventName;
|
||||
|
||||
opts.source.on(opts.eventName, function() {
|
||||
var args, _ref, _ref1;
|
||||
args = 1 <= arguments.length ? [].slice.call(arguments, 0) : [];
|
||||
(_ref = opts.target).emit.apply(_ref, [targetEventName].concat([].slice.call(args)));
|
||||
if (sendUpdate) {
|
||||
return (_ref1 = opts.target).emit.apply(_ref1, ['update', targetEventName].concat([].slice.call(args)));
|
||||
var args = arguments.length >= 1 ? [].slice.call(arguments, 0) : [];
|
||||
args.unshift(opts.targetEventName);
|
||||
opts.target.emit.apply(opts.target, args);
|
||||
|
||||
if (opts.sendUpdate) {
|
||||
args.unshift('update');
|
||||
opts.target.emit.apply(opts.target, args);
|
||||
}
|
||||
});
|
||||
return opts.source;
|
||||
})
|
||||
};
|
||||
|
||||
// Public: Creates an event handler that proxies events from an adaptor's
|
||||
|
@ -77,9 +79,7 @@ namespace("Cylon", function() {
|
|||
Basestar.prototype.defineAdaptorEvent = function(opts) {
|
||||
opts['source'] = this.connector;
|
||||
opts['target'] = this.connection;
|
||||
if (opts['sendUpdate'] == null) {
|
||||
opts['sendUpdate'] = false;
|
||||
}
|
||||
if (opts['sendUpdate'] == null) { opts['sendUpdate'] = false; }
|
||||
return this.defineEvent(opts);
|
||||
};
|
||||
|
||||
|
@ -93,9 +93,7 @@ namespace("Cylon", function() {
|
|||
Basestar.prototype.defineDriverEvent = function(opts) {
|
||||
opts['source'] = this.connection;
|
||||
opts['target'] = this.device;
|
||||
if (opts['sendUpdate'] == null) {
|
||||
opts['sendUpdate'] = true;
|
||||
}
|
||||
if (opts['sendUpdate'] == null) { opts['sendUpdate'] = true; }
|
||||
return this.defineEvent(opts);
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue