0.1.0 • Published 5 years ago
emyt v0.1.0
Install
npm:
npm install mitterYarn:
yarn add mitterGitHub:
git clone https://github.com/mazecodes/mitter.gitUsage
Make an instance:
const Mitter = require('mitter');
const mitter = new Mitter();You can also make Mitter case-insensitive if you want:
const mitter = new Mitter({
caseSensitive: false,
});Listen to an event:
mitter.on('event', message => {
console.log(`Event: ${message}`);
});You can also attach multiple handlers to an event at the same time:
mitter.on(
'event',
() => console.log('Handler 1'),
() => console.log('Handler 2'),
() => console.log('Handler 3')
);Trigger an event:
mitter.emit('event');You can pass multiple values to handlers:
mitter.emit('event', 'Message 1', 'Message 2');Remove a specific event handler:
mitter.off('event', handler);Remove all handlers for an event:
mitter.clear('event');All events
Listen to all events:
mitter.onAll((type, message) => {
console.log(`Event type: ${type}`);
});Trigger all events:
mitter.emitAll();Remove all events:
mitter.clearAll();RegExps
You can listen to RegExps to catch specific events:
mitter.on(/^event/, type => {
console.log(`Event type: ${type}`);
});You can also trigger events with RegExp:
mitter.emit(/foo$/, 'bar');Handler Category
Handlers have two categories: normal and regex.
You can clear a specific category like this:
mitter.clearAll('normal');Contributing
All contributions, issues and feature requests are welcome! Please feel free to check issues page.
- Fork the project
- Create your feature branch (
git checkout -b awesome-feature) - Commit your changes (
git commit -m "Add Awesome Feature") - Push to the branch (
git push origin awesome-feature) - Open a Pull Request
Author
Maze Peterson:
Show your support
Give a ⭐ if you liked this project!
License
MIT © Maze Peterson
0.1.0
5 years ago