Wheels PubSub
Simple and lightweight PubSub, fully compatible with CommonJS (Node), AMD and standard browser script tag include.
Install
wheels-pubsub
can be included in a project with CommonJS / npm, AMD or standard browser script tag. Its only dependency is wheels-class
.
npm
npm install wheels-pubsub
AMD / RequireJS
// Remember to provide the dependency `wheels-class`;
Traditional browser script tag
Usage
var ps = ; var { console;}; // Subscribe to an event:ps; // emit event:ps; // Console will log "Event foo was triggered!" // Pass other arguments when emitting event:ps;ps; // Console will log "Received event bar with arguments 123 and abc" // Unsubscribe:ps; // Unsubscribe `cbk` from event "foo"ps; // Unsubscribe any callback from event foops; // Unsubscribe any callback from any event // Subscribe to an event only once:ps;ps; // Console will log "Event foo was triggered!"ps; // Console won't log anything