https://github.com/joepdooper/callbackhooks
A lightweight and flexible callback utility for JavaScript. Easily add, organize, and execute callback functions.
https://github.com/joepdooper/callbackhooks
async-callback callback callbacks custom-callback event event-driven event-handling events function-hooks hook hooks javascript
Last synced: 7 days ago
JSON representation
A lightweight and flexible callback utility for JavaScript. Easily add, organize, and execute callback functions.
- Host: GitHub
- URL: https://github.com/joepdooper/callbackhooks
- Owner: joepdooper
- License: mit
- Created: 2025-01-05T00:24:25.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2025-05-11T09:03:52.000Z (10 months ago)
- Last Synced: 2025-09-19T16:36:57.532Z (6 months ago)
- Topics: async-callback, callback, callbacks, custom-callback, event, event-driven, event-handling, events, function-hooks, hook, hooks, javascript
- Language: JavaScript
- Homepage:
- Size: 4.88 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# CallbackHooks
**CallbackHooks** is a lightweight and flexible callback/event management library for JavaScript.
It lets you easily add, organize, and execute callback functions tied to named events.
## Installation
Install via npm:
```bash
npm install callbackhooks
```
## Usage
```javascript
// Import the CallbackHooks class
import { CallbackHooks } from 'callbackhooks';
// Create a new instance of CallbackHooks
const hooks = new CallbackHooks();
// Add a callback to an event named 'userLogin'
hooks.add('userLogin', function(userData) {
console.log('User logged in:', userData);
});
// Add a callback to an event named 'userLogout'
hooks.add('userLogout', function() {
console.log('User logged out');
});
// Call the 'userLogin' event with parameters (user data)
hooks.call('userLogin', { name: 'Joe', age: 30 });
// Call the 'userLogout' event (no parameters needed)
hooks.call('userLogout');
```
## Example Use Cases
- Plugin systems
- Event-driven modules
- Custom event handling in apps
- Decoupled function execution