0.2.5 • Published 5 years ago
pubsubjs-m4r v0.2.5
PubSubJS
Simple pubsub solution for node and web
Use
- CDN
- Production
<script src="https://unpkg.com/pubsubjs-m4r/dist/umd/pubsubjs.prod.js"></script>
- Development
<script src="https://unpkg.com/pubsubjs-m4r/dist/umd/pubsubjs.dev.js"></script>
- Production
npm
npm i -S pubsubjs-m4r
yarn
yarn add pubsubjs-m4r
How to use
import PubSubJS from 'pubsubjs-m4r'
// Or
// const PubSubJS = require("pubsubjs-m4r").default
// Subscribe to topic "abc"
const sub = PubSubJS.subscribe('abc', data => {
// Your code
console.log(data)
})
// Publish to topic "acb"
PubSubJS.publish('abc', 'Hello')
// unsub!!
sub()
API
PubSubJS
- Subscribe - subscribe to notifications on a given topic
subscribe: (topic: string, cb: Action<any>) => UnsubAction
- Publish - publishes to a given topic
publish: (topic: string, data: any, sync?: boolean) => void;
- ClearAllSubscriptions - removes all subscriptions
clearAllSubscriptions: () => void;
- ClearAllByTopic - removes all subscriptios on a topic
```typescript
clearAllByTopic: (topic: string) => void;
```
- GetTopics - get the registered topics
```typescript
getTopics: () => string[];
```