podium-lib / issues

All podium issues, bugs, questions etc goes here. Documentation is to be found at https://podium-lib.io
1 stars 0 forks source link

Enhance MessageBus' `subscribe` with an option to replay most recent event #64

Open pearofducks opened 1 year ago

pearofducks commented 1 year ago

I've had several cases where the item being mounted could have raced with any publish events, so one needs to do a subscribe and a peek to ensure nothing was missed.

The immediate (or whatever name you prefer) flag would automatically do this peek action and replay it onto the callback.

Example:

Suggested:

messageBus.subscribe('channel', 'topic', () => {}, { immediate: true })

Current:

const cb = ({ payload }) => {}
mb.subscribe('channel', 'topic', cb)
const maybeEvent = mb.peek('channel', 'topic')
if (maybeEvent) cb(maybeEvent)