rails-delegate
Advanced tools
| # Delegate Developer Documentation | ||
| #### Setup the development environment | ||
| * install Node.JS | ||
| * `rm -rf node_modules ; npm install` | ||
| #### Run tests | ||
| * run all specs: | ||
| ``` | ||
| spec [<file>] | ||
| ``` | ||
| #### Update dependencies | ||
| * check whether updates are available: | ||
| ``` | ||
| check-update | ||
| ``` | ||
| * automatically update all dependencies to the latest version: | ||
| ``` | ||
| update | ||
| ``` | ||
| #### Release a new version | ||
| * [update the dependencies](#update-dependencies) to the latest version | ||
| * publish a new version via CI: | ||
| ``` | ||
| $ bin/publish | ||
| ``` |
| # array of strings or regular expressions to match against a module name | ||
| # to determine if it is allowed to be unused | ||
| # | ||
| # Please create an issue at | ||
| # https://github.com/charlierudolph/dependency-lint/issues | ||
| # anytime you need to use this | ||
| allowUnused: | ||
| - cucumber | ||
| - dependency-lint | ||
| - livescript | ||
| - npm-check-updates | ||
| - publish-via-ci | ||
| # array of path patterns to match againt a filename | ||
| # to determine if it is used only for development | ||
| # (see https://github.com/isaacs/minimatch) | ||
| devFilePatterns: | ||
| - '{features,spec,test}/**/*' | ||
| - '**/*_{spec,test}.js' | ||
| # array of strings or regular expressions to match against a script name | ||
| # in your `package.json` to determine if it is used only for development | ||
| devScripts: | ||
| - lint | ||
| - publish | ||
| - test | ||
| - update | ||
| # path pattern to match against a filename to determine if it should be parsed. | ||
| # (see https://github.com/isaacs/minimatch) | ||
| # | ||
| # This is the starting point, devFilePatterns and ignoreFilePatterns should be | ||
| # subsets of this pattern | ||
| filePattern: '**/*.ls' | ||
| # array of path patterns to match against a filename | ||
| # to determine if it should be ignored | ||
| # (see https://github.com/isaacs/minimatch) | ||
| ignoreFilePatterns: | ||
| - 'node_modules/**/*' | ||
| # boolean whether to ignore anything before a `!` in require statements | ||
| # | ||
| # Useful for: | ||
| # webpack loaders - https://webpack.github.io/docs/loaders.html | ||
| # RequireJS loader plugins - http://requirejs.org/docs/plugins.html | ||
| stripLoaders: false | ||
| # array of transpilers with properties 'extension' and 'module'. | ||
| # | ||
| # The module will be required and then the 'compile' property will be called | ||
| # with the file contents and the file path for each file with that extension | ||
| # | ||
| # require(<module>).compile(fileContents, {filename: filePath}); | ||
| # | ||
| transpilers: | ||
| - extension: ls | ||
| module: livescript |
| // Generated by LiveScript 1.4.0 | ||
| (function(){ | ||
| var flatten, debug, delegate, delegateEvent, delegateMethod, delegateProperty, _delegateEvent, slice$ = [].slice; | ||
| flatten = require('lodash.flatten'); | ||
| debug = require('debug')('rails-delegate'); | ||
| delegate = 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; | ||
| switch (false) { | ||
| case !!to: | ||
| throw new Error("Error in rails-delegate: No delegator (to) provided"); | ||
| case !!from: | ||
| throw new Error("Error in rails-delegate: No delegate (from) provided"); | ||
| } | ||
| 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$; | ||
| }; | ||
| 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){ | ||
| 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]; | ||
| } | ||
| }); | ||
| }; | ||
| _delegateEvent = function(eventName, from, to){ | ||
| var i$, ref$, len$, source, results$ = []; | ||
| debug("delegating event '" + eventName + "'"); | ||
| for (i$ = 0, len$ = (ref$ = flatten([from])).length; i$ < len$; ++i$) { | ||
| source = ref$[i$]; | ||
| results$.push(source.on(eventName, fn$)); | ||
| } | ||
| return results$; | ||
| function fn$(){ | ||
| var params; | ||
| params = slice$.call(arguments); | ||
| return to.emit.apply(to, [eventName].concat(slice$.call(params))); | ||
| } | ||
| }; | ||
| module.exports = { | ||
| delegate: delegate, | ||
| delegateEvent: delegateEvent | ||
| }; | ||
| }).call(this); |
+20
-22
| { | ||
| "name": "rails-delegate", | ||
| "version": "0.5.0", | ||
| "description": "A simple helper to implement the delegation pattern in JavaScript code bases", | ||
| "main": "lib/rails-delegate.js", | ||
| "scripts": { | ||
| "postpublish": "git push && git push --tags", | ||
| "prepublish": "bin/build", | ||
| "preversion": "npm test && npm run update", | ||
| "test": "cucumber-js", | ||
| "update": "david update" | ||
| }, | ||
| "repository": { | ||
| "type": "git", | ||
| "url": "git+https://github.com/Originate/delegation-pattern-js.git" | ||
| }, | ||
| "version": "0.5.2", | ||
| "author": "Kevin Goslar", | ||
| "license": "ISC", | ||
| "bugs": { | ||
| "url": "https://github.com/Originate/delegation-pattern-js/issues" | ||
| "dependencies": { | ||
| "debug": "^2.2.0", | ||
| "lodash.flatten": "^4.0.0" | ||
| }, | ||
| "homepage": "https://github.com/Originate/delegation-pattern-js#readme", | ||
| "description": "A simple helper to implement the delegation pattern in JavaScript code bases", | ||
| "devDependencies": { | ||
| "chai": "^3.4.1", | ||
| "cucumber": "^0.9.2", | ||
| "david": "^7.0.0", | ||
| "dependency-lint": "^3.1.1", | ||
| "jsdiff-console": "^1.1.3", | ||
| "livescript": "^1.4.0", | ||
| "npm-check-updates": "^2.5.8", | ||
| "publish-via-ci": "^0.2.2", | ||
| "wait": "^0.1.0" | ||
| }, | ||
| "dependencies": { | ||
| "debug": "^2.2.0", | ||
| "lodash.flatten": "^4.0.0" | ||
| "homepage": "https://github.com/Originate/delegation-pattern-js#readme", | ||
| "license": "ISC", | ||
| "main": "dist/rails-delegate.js", | ||
| "repository": { | ||
| "type": "git", | ||
| "url": "git+https://github.com/Originate/delegation-pattern-js.git" | ||
| }, | ||
| "scripts": { | ||
| "postpublish": "git push && git push --tags", | ||
| "prepublish": "bin/build", | ||
| "preversion": "check-update && bin/spec", | ||
| "test": "bin/spec" | ||
| } | ||
| } |
+9
-2
@@ -18,3 +18,3 @@ # Delegation Pattern for JavaScript | ||
| ```javascript | ||
| delegate = require('rails-delegate'); | ||
| delegate = require('rails-delegate').delegate; | ||
@@ -45,6 +45,8 @@ function Car() { | ||
| ```javascript | ||
| delegateEvent = require('rails-delegate').delegateEvent; | ||
| function Car() { | ||
| this.engine = new Engine(); | ||
| delegateEvents('starting', 'stopping', { from: this.engine, to: this }); | ||
| delegateEvent('starting', 'stopping', { from: this.engine, to: this }); | ||
| }; | ||
@@ -65,1 +67,6 @@ ``` | ||
| [node-delegates](https://github.com/tj/node-delegates). | ||
| ## Development | ||
| See our [developer guidelines](CONTRIBUTING.md) |
| // Generated by LiveScript 1.4.0 | ||
| (function(){ | ||
| var flatten, debug, delegate, delegateEvent, delegateMethod, delegateProperty, _delegateEvent, slice$ = [].slice; | ||
| flatten = require('lodash.flatten'); | ||
| debug = require('debug')('rails-delegate'); | ||
| delegate = 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; | ||
| switch (false) { | ||
| case !!to: | ||
| throw new Error("Error in rails-delegate: No delegator (to) provided"); | ||
| case !!from: | ||
| throw new Error("Error in rails-delegate: No delegate (from) provided"); | ||
| } | ||
| 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$; | ||
| }; | ||
| 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){ | ||
| 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]; | ||
| } | ||
| }); | ||
| }; | ||
| _delegateEvent = function(eventName, from, to){ | ||
| var i$, ref$, len$, source, results$ = []; | ||
| debug("delegating event '" + eventName + "'"); | ||
| for (i$ = 0, len$ = (ref$ = flatten([from])).length; i$ < len$; ++i$) { | ||
| source = ref$[i$]; | ||
| results$.push(source.on(eventName, fn$)); | ||
| } | ||
| return results$; | ||
| function fn$(){ | ||
| var params; | ||
| params = slice$.call(arguments); | ||
| return to.emit.apply(to, [eventName].concat(slice$.call(params))); | ||
| } | ||
| }; | ||
| module.exports = { | ||
| delegate: delegate, | ||
| delegateEvent: delegateEvent | ||
| }; | ||
| }).call(this); |
Sorry, the diff of this file is not supported yet
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
8869
37.59%7
16.67%70
11.11%8
33.33%1
Infinity%