https://github.com/ioncakephper/dispatcher
Dispatch hooks of a hookable method to methods named automatically
https://github.com/ioncakephper/dispatcher
Last synced: 3 months ago
JSON representation
Dispatch hooks of a hookable method to methods named automatically
- Host: GitHub
- URL: https://github.com/ioncakephper/dispatcher
- Owner: ioncakephper
- License: mit
- Created: 2022-12-26T13:08:42.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-12-07T23:54:02.000Z (7 months ago)
- Last Synced: 2025-01-21T23:33:45.527Z (5 months ago)
- Language: JavaScript
- Homepage:
- Size: 219 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# dispatcher
Dispatch hooks of a hook-able method to methods named automatically.
## Badges
[](https://choosealicense.com/licenses/mit/)
## Usage
```js
const { Dispatcher } = require("dispatcher");class Example {
find(hook) {
let d = new Dispatcher();
return d.dispatch(this, 'find', arguments)
}// method for hook 'all'
findAll(options = {}) {
// pass options to a db query
// return DB.query(options)
return [{}]
}// default method for hook-able find
defaultFind(hook, ...args) {
// return a default answer based on hook and available arguments
}
}// in your code:
let options = {}let m = new Example();
let records = m.find('all', options) // will invoke findAll(options)// when no hook method exists for a hook, the defaultFind is executed.
let r = m.find("first", options)
```