rails-delegate
Advanced tools
Comparing version 0.2.0 to 0.3.0
// Generated by LiveScript 1.4.0 | ||
(function(){ | ||
var flatten, delegate, slice$ = [].slice; | ||
var flatten, debug, delegate, delegateMethod, delegateProperty, slice$ = [].slice; | ||
flatten = require('lodash.flatten'); | ||
debug = require('debug')('rails-delegate'); | ||
delegate = function(){ | ||
var i$, methodNames, ref$, from, to, len$, methodName, ref1$, results$ = []; | ||
methodNames = 0 < (i$ = arguments.length - 1) ? slice$.call(arguments, 0, i$) : (i$ = 0, []), ref$ = arguments[i$], from = ref$.from, to = ref$.to; | ||
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; | ||
switch (false) { | ||
@@ -14,12 +15,32 @@ case !!to: | ||
} | ||
for (i$ = 0, len$ = (ref$ = flatten(methodNames)).length; i$ < len$; ++i$) { | ||
methodName = ref$[i$]; | ||
results$.push(from[methodName] = ((ref1$ = to[methodName]) != null ? ref1$.bind(to) : void 8) || (fn$())); | ||
for (i$ = 0, len$ = (ref$ = flatten(names)).length; i$ < len$; ++i$) { | ||
name = ref$[i$]; | ||
switch (typeof to[name]) { | ||
case 'function': | ||
results$.push(delegateMethod(from, to, name)); | ||
break; | ||
case 'undefined': | ||
throw new Error("Error in rails-delegate: method '" + name + "' not found on the delegate"); | ||
default: | ||
results$.push(delegateProperty(from, to, name)); | ||
} | ||
} | ||
return results$; | ||
function fn$(){ | ||
}; | ||
delegateMethod = function(from, to, methodName){ | ||
var ref$; | ||
debug("delegating method '" + methodName + "'"); | ||
return from[methodName] = ((ref$ = to[methodName]) != null ? ref$.bind(to) : void 8) || (function(){ | ||
throw new Error("Error in rails-delegate: method '" + methodName + "' not found on the delegate"); | ||
} | ||
}()); | ||
}; | ||
delegateProperty = function(from, to, propertyName){ | ||
debug("delegating property '" + propertyName + "'"); | ||
return Object.defineProperty(from, propertyName, { | ||
get: function(){ | ||
return to[propertyName]; | ||
} | ||
}); | ||
}; | ||
module.exports = delegate; | ||
}).call(this); |
{ | ||
"name": "rails-delegate", | ||
"version": "0.2.0", | ||
"version": "0.3.0", | ||
"description": "A simple helper to implement the delegation pattern in JavaScript code bases", | ||
@@ -30,4 +30,5 @@ "main": "lib/rails-delegate.js", | ||
"dependencies": { | ||
"debug": "^2.2.0", | ||
"lodash.flatten": "^4.0.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
4912
45
2
+ Addeddebug@^2.2.0
+ Addeddebug@2.6.9(transitive)
+ Addedms@2.0.0(transitive)