rails-delegate
Advanced tools
Comparing version 0.3.0 to 0.4.0
// Generated by LiveScript 1.4.0 | ||
(function(){ | ||
var flatten, debug, delegate, delegateMethod, delegateProperty, slice$ = [].slice; | ||
var flatten, debug, delegate, delegateEvent, delegateMethod, delegateProperty, _delegateEvent, slice$ = [].slice; | ||
flatten = require('lodash.flatten'); | ||
@@ -29,2 +29,11 @@ debug = require('debug')('rails-delegate'); | ||
}; | ||
delegateEvent = function(){ | ||
var i$, names, ref$, from, to, len$, name, results$ = []; | ||
names = 0 < (i$ = arguments.length - 1) ? slice$.call(arguments, 0, i$) : (i$ = 0, []), ref$ = arguments[i$], from = ref$.from, to = ref$.to; | ||
for (i$ = 0, len$ = (ref$ = flatten(names)).length; i$ < len$; ++i$) { | ||
name = ref$[i$]; | ||
results$.push(_delegateEvent(name, from, to)); | ||
} | ||
return results$; | ||
}; | ||
delegateMethod = function(from, to, methodName){ | ||
@@ -45,3 +54,14 @@ var ref$; | ||
}; | ||
module.exports = delegate; | ||
_delegateEvent = function(eventName, from, to){ | ||
debug("delegating event '" + eventName + "'"); | ||
return from.on(eventName, function(){ | ||
var params; | ||
params = slice$.call(arguments); | ||
return to.emit.apply(to, [eventName].concat(slice$.call(params))); | ||
}); | ||
}; | ||
module.exports = { | ||
delegate: delegate, | ||
delegateEvent: delegateEvent | ||
}; | ||
}).call(this); |
{ | ||
"name": "rails-delegate", | ||
"version": "0.3.0", | ||
"version": "0.4.0", | ||
"description": "A simple helper to implement the delegation pattern in JavaScript code bases", | ||
@@ -27,3 +27,5 @@ "main": "lib/rails-delegate.js", | ||
"david": "^7.0.0", | ||
"livescript": "^1.4.0" | ||
"jsdiff-console": "^1.1.3", | ||
"livescript": "^1.4.0", | ||
"wait": "^0.1.0" | ||
}, | ||
@@ -30,0 +32,0 @@ "dependencies": { |
@@ -21,3 +21,3 @@ # Delegation Pattern for JavaScript | ||
delegate('start', 'stop', { from: this, to: this.engine }); | ||
delegate('start', 'stop', 'cylinders', { from: this, to: this.engine }); | ||
}; | ||
@@ -30,4 +30,7 @@ | ||
`myCar.stop()` calls `myCar.engine.stop()`. | ||
You can also access the property `myCar.cylinders`, | ||
which contains the value of `myCar.engine.cylinders`. | ||
More information in the [spec](features/delegate.feature). | ||
More information in the spec for delegating [methods](features/delegating-methods.feature) | ||
and [properties](features/delegating-properties.feature). | ||
This library also provides meaningful [error messages](features/error-messages.feature). | ||
@@ -34,0 +37,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
5967
65
46
6