diff options
Diffstat (limited to 'node_modules/auto-bind')
-rw-r--r-- | node_modules/auto-bind/index.js | 52 | ||||
-rw-r--r-- | node_modules/auto-bind/license | 9 | ||||
-rw-r--r-- | node_modules/auto-bind/package.json | 40 | ||||
-rw-r--r-- | node_modules/auto-bind/readme.md | 95 |
4 files changed, 0 insertions, 196 deletions
diff --git a/node_modules/auto-bind/index.js b/node_modules/auto-bind/index.js deleted file mode 100644 index 1ebf8e0cd..000000000 --- a/node_modules/auto-bind/index.js +++ /dev/null @@ -1,52 +0,0 @@ -'use strict'; -module.exports = (self, options) => { - options = Object.assign({}, options); - - const filter = key => { - const match = pattern => typeof pattern === 'string' ? key === pattern : pattern.test(key); - - if (options.include) { - return options.include.some(match); - } - - if (options.exclude) { - return !options.exclude.some(match); - } - - return true; - }; - - for (const key of Object.getOwnPropertyNames(self.constructor.prototype)) { - const val = self[key]; - - if (key !== 'constructor' && typeof val === 'function' && filter(key)) { - self[key] = val.bind(self); - } - } - - return self; -}; - -const excludedReactMethods = [ - 'componentWillMount', - 'UNSAFE_componentWillMount', - 'render', - 'getSnapshotBeforeUpdate', - 'componentDidMount', - 'componentWillReceiveProps', - 'UNSAFE_componentWillReceiveProps', - 'shouldComponentUpdate', - 'componentWillUpdate', - 'UNSAFE_componentWillUpdate', - 'componentDidUpdate', - 'componentWillUnmount', - 'componentDidCatch', - 'setState', - 'forceUpdate' -]; - -module.exports.react = (self, options) => { - options = Object.assign({}, options); - options.exclude = (options.exclude || []).concat(excludedReactMethods); - return module.exports(self, options); -}; diff --git a/node_modules/auto-bind/license b/node_modules/auto-bind/license deleted file mode 100644 index e7af2f771..000000000 --- a/node_modules/auto-bind/license +++ /dev/null @@ -1,9 +0,0 @@ -MIT License - -Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com) - -Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/node_modules/auto-bind/package.json b/node_modules/auto-bind/package.json deleted file mode 100644 index 373e9454e..000000000 --- a/node_modules/auto-bind/package.json +++ /dev/null @@ -1,40 +0,0 @@ -{ - "name": "auto-bind", - "version": "1.2.1", - "description": "Automatically bind methods to their class instance", - "license": "MIT", - "repository": "sindresorhus/auto-bind", - "author": { - "name": "Sindre Sorhus", - "email": "sindresorhus@gmail.com", - "url": "sindresorhus.com" - }, - "engines": { - "node": ">=4" - }, - "scripts": { - "test": "xo && ava" - }, - "files": [ - "index.js" - ], - "keywords": [ - "auto", - "bind", - "class", - "methods", - "method", - "automatically", - "prototype", - "instance", - "function", - "this", - "self", - "react", - "component" - ], - "devDependencies": { - "ava": "*", - "xo": "*" - } -} diff --git a/node_modules/auto-bind/readme.md b/node_modules/auto-bind/readme.md deleted file mode 100644 index a40bcc43a..000000000 --- a/node_modules/auto-bind/readme.md +++ /dev/null @@ -1,95 +0,0 @@ -# auto-bind [](https://travis-ci.org/sindresorhus/auto-bind) - -> Automatically bind methods to their class instance - - -## Install - -``` -$ npm install auto-bind -``` - - -## Usage - -```js -const autoBind = require('auto-bind'); - -class Unicorn { - constructor(name) { - this.name = name; - autoBind(this); - } - - message() { - return `${this.name} is awesome!`; - } -} - -const unicorn = new Unicorn('Rainbow'); - -// Grab the method off the class instance -const message = unicorn.message; - -// Still bound to the class instance -message(); -//=> 'Rainbow is awesome!' - -// Without `autoBind(this)`, the above would have resulted in -message(); -//=> Error: Cannot read property 'name' of undefined -``` - - -## API - -### autoBind(self, [options]) - -Bind methods in `self` to their class instance. Returns the `self` object. - -#### self - -Type: `Object` - -Object with methods to bind. - -#### options - -Type: `Object` - -##### include - -Type: `Array<string|RegExp>` - -Bind only the given methods. - -##### exclude - -Type: `Array<string|RegExp>` - -Bind methods except for the given methods. - -### autoBind.react(self, [options]) - -Same as `autoBind`, but excludes the default [React component methods](https://reactjs.org/docs/react-component.html). - -```js -class Foo extends React.Component { - constructor(props) { - super(props); - autoBind.react(this); - } - - // … -} -``` - - -## Related - -- [bind-methods](https://github.com/sindresorhus/bind-methods) - Bind all methods in an object to itself or a specified context - - -## License - -MIT © [Sindre Sorhus](https://sindresorhus.com) |