Skip to content

v1.1.0

Compare
Choose a tag to compare
@fabio-nettis fabio-nettis released this 24 Jan 13:21
· 10 commits to main since this release
0fae7d6

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

Full Changelog: v1.0.0...v1.1.0