Skip to content

Richer API

Compare
Choose a tag to compare
@oskarhane oskarhane released this 13 Feb 15:21
· 19 commits to master since this release

Two new bus methods are introduces in this release:

bus.reset()

Remove all subscribers on all channels on the bus.

bus.self(channel, message, fn)

a way to tell subscribers that you expect something back on a certain channel. Read more in the docs: https://github.com/oskarhane/suber#self
Example: say you want to fetch a github user and log the name but you want to keep the fetching somewhere else in the app (preferably in some middleware somewhere).
We assume some middleware (maybe redux-observable) subscribing on channel 'FETCH_USER'. How do we get the response back without storing it in redux and subscribing to the state?

Like this.

const b = getBus()
const cb = (data) => console.log(data.name) // Let's just log the name.

b.self('FETCH_USER', {id: 100}, cb)

The middleware receiving this request to fetch the user should now look for a _responseChannel property on the message to know on what channel to respond on. When it does, cb will pick that up and log the name.

One utility method

resetMiddlewares() - Remove all middlewares.