![PyPI Now Supports iOS and Android Wheels for Mobile Python Development](https://cdn.sanity.io/images/cgdhsj6q/production/96416c872705517a6a65ad9646ce3e7caef623a0-1024x1024.webp?w=400&fit=max&auto=format)
Security News
PyPI Now Supports iOS and Android Wheels for Mobile Python Development
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
simple-event-bus
Advanced tools
This project implements a basic but configurable event bus.
// In Node.js
const EventBus = require('simple-event-bus');
// For the browser, using a bundler
import EventBus from 'simple-event-bus';
const eventBus = new EventBus();
// subscribe to events
const removeHandler = eventBus.on('my-event', (...args) => {
console.log(...args);
});
// trigger events
eventBus.emit('my-event', 'Hello', 'world', '!');
// => Hello world !
// unsubscribe when you are done
removeHandler();
Live Demo and its source code.
new EventBus([options: Object])
Returns the event bus instance, that holds the handlers and is able to dispatch events
eventBus.on(action: string, handler: Function, [handlerId: number]): Function
Registers the handler for the given action. Optionally, a handlerId can be passed, that will be used when logging errors. It returns a function that removes the handler when called.
eventBus.emit(action: string, ...parameters: any): number
Emits an event, dispatching it to all registered handlers. It does not do anything if no handlers have been registered on that event.
eventBus.handlersCount(action: string)
Returns the number of handlers currently subscribed to the action.
[options = {}]
options.logger
Type: Object
Default: console
The only mandatory method for now is error
, but some additional loggings will most likely be added (log
, info
, debug
, warn
);
options.broker
Type: Function
Default: (action, ...payload) => payload
A function to customize the interface between events and handlers, giving the ability for example to standardize all the messages transmitted to the handlers into a normalized format. By default, the broker just propagates the arguments that have been emitted.
The node entry point ("main": "index.js"
in the package.json
) requires Node >= 6.5 (see ES6 compatibility table for class). The browser entry point ("browser": "browser.js" in the package.json
) exposes some code bundled and transpiled into ES5 for compatibility with older browsers, bundlers, minifiers, ...
More logging: Currently, we only log errors. We could log more information, to help with troubleshooting.
Log level: We could add a logLevel option, to allow filtering the log messages while still keeping the default logger.
Test framework: A better test framework (for example Jest) should be used in order to for example have a test coverage report.
Examples: A showcase application could be built as a demo, showing the interest of using a custom logger and broker in a real-case example.
FAQs
A simple event bus library, without dependencies
The npm package simple-event-bus receives a total of 21 weekly downloads. As such, simple-event-bus popularity was classified as not popular.
We found that simple-event-bus demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
Security News
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.