v1.1.0
Event Replay API 🕙
This release adds the planned event replay API to TinyBus! You can now replay events that have been send through the event bus by sending them to all subscribers again.
const tinyBus = new TinyBus({
// enables event persistence and replay abilities, defaults to true
persistEvents: true,
});
await tinyBus.on("example-replay", {
onCallback: () => console.log("Hello World"),
});
// if persistEvents is false, emit will return undefined
const eventId = tinyBus.emit("example-replay", "arg1", "arg2");
await tinyBus.replay(eventId);
Custom persistence and restoration handlers
Of course you can control how the an event is persisted and restored, this can be useful if you want to save your events into a database. For that you can use the TinyBus
constructor, but remember: If you provide a onRestore
function you also need to provide a onPersist
function and vise verca or an error will be thrown.
const tinyBus = new TinyBus({
// expects you to return an id of type `EventID`
onPersist: async (event) => {},
// expects you to return an event of type `TinyBusEvent`
onRestore: async (eventId) => {},
});
What's Changed
- feat: add event replay capabilities by @fabio-nettis in #3
Full Changelog: v1.0.0...v1.1.0