quick-event is a TypeScript event library that provides tools that enable your application components to communicate with each other by dispatching events and listening for them. With quick-event you can easily implement signal/slot mechanism, or observer pattern.
# npm
npm install --save quick-event
# yarn
yarn add --save quick-event
<script src="dist/quick-event.min.js"></script>
Name QuickEvent
is ready to use and no need to import.
<script src="https://unpkg.com/quick-event/dist/quick-event.min.js"></script>
Name QuickEvent
is ready to use and no need to import.
import { CallbackList } from 'quick-event';
const callbackList = new CallbackList();
callbackList.append(() => {
console.log('Got callback 1.');
});
callbackList.append(() => {
console.log('Got callback 2.');
});
callbackList.dispatch();
import { EventDispatcher } from 'quick-event';
const dispatcher = new EventDispatcher();
dispatcher.appendListener(3, () => {
console.log('Got event: 3.');
});
dispatcher.appendListener('my-event', () => {
console.log('Got event: my-event.');
});
dispatcher.appendListener('my-event, () => {
console.log('Got another event: my-event.');
});
dispatcher.dispatch(3);
dispatcher.dispatch('my-event');
import { EventQueue } from 'quick-event';
const queue = new EventQueue();
queue.appendListener(3, (s: any, n: any) => {
console.log(`Got event: 3, s is ${s}, n is ${n}`);
});
queue.appendListener(5, (s: any, n: any) => {
console.log(`Got event: 5, s is ${s}, n is ${n}`);
});
queue.appendListener(5, (s: any, n: any) => {
console.log(`Got another event: 5, s is ${s}, n is ${n}`);
});
// Enqueue the events, the first argument is always the event type.
// The listeners are not triggered during enqueue.
queue.enqueue(3, 'Hello', 38);
queue.enqueue(5, 'World', 58);
// Process the event queue, dispatch all queued events.
queue.process();
yarn test
quick-event is rewritten from wqking/eventjs.
Wang Qi(wqking) is my friend and teacher, we have developed some projects together. He's a wide-ranging, experienced developer and I've learned a lot from him.
The code in this project is licensed under MIT license.
Generated using TypeDoc