Package Exports
- @supercharge/method-missing
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@supercharge/method-missing) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
Method Missing
Handle missing methods on your classes, like PHP’s __call.
Installation · Docs · Usage
Follow @marcuspoehls and @superchargejs for updates!
Introduction
The @supercharge/method-missing
package allows you to handle missing methods in your JavaScript classes. It calls the __call(methodName, args)
method in your class when trying to invoke a missing method.
Installation
npm i @supercharge/method-missing
Docs
Find all the details for @supercharge/method-missing
in the extensive Supercharge docs.
Usage
Using @supercharge/method-missing
is pretty straightforward. The package exports a class that you must extend in your implemented class. Then, add a __call(methodName, args)
method to your class. The __call
method allows you to handle all calls for methods that are not existent in your class.
I guess an example clears things up:
const MethodMissing = require('@supercharge/method-missing')
class QueryInterface extends MethodMissing {
/**
* Creates an instance wrapping the Sequelize `queryInterface` instance.
*
* @param {QueryInterface} queryInterface
*/
constructor (queryInterface) {
super()
this.queryInterface = queryInterface
}
/**
* Determine whether the given `column` already exists in the given `table`.
*
* @param {String} table
* @param {String} column
*
* @returns {Boolean}
*/
async hasColumn(tableName, columnName) {
const description = await this.queryInterface.describeTable(tableName)
return !!description[columnName]
}
/**
* Pass through all calls to the original query interface.
*
* @param {String} methodName
* @param {Array} args
*
* @returns {*}
*/
__call(methodName, args) {
return this.queryInterface[methodName](...args)
}
}
Contributing
Do you miss a function? We very much appreciate your contribution! Please send in a pull request 😊
- Create a fork
- Create your feature branch:
git checkout -b my-feature
- Commit your changes:
git commit -am 'Add some feature'
- Push to the branch:
git push origin my-new-feature
- Submit a pull request 🚀
License
MIT © Supercharge
superchargejs.com · GitHub @superchargejs · Twitter @superchargejs