@moudrey/fluxa-history
v0.0.1
Published
Fluxa plugin for event history and replay.
Maintainers
Readme
@moudrey/fluxa-history
Fluxa plugin for event history, snapshots, and replay.
The plugin records events after they are delivered to the local Fluxa bus. That means it works the same way for local events and events received through transport plugins such as @moudrey/fluxa-frames, @moudrey/fluxa-chrome, and @moudrey/fluxa-tabs.
Install
npm install @moudrey/fluxa-core @moudrey/fluxa-historyRequires @moudrey/fluxa-core >=0.0.4.
Usage
import { Fluxa } from "@moudrey/fluxa-core";
import { createHistoryPlugin } from "@moudrey/fluxa-history";
type Events = {
"call:start": { prospectId: string };
"guidance:update": { text: string };
};
const history = createHistoryPlugin<Events>({ limit: 500 });
const bus = new Fluxa<Events>({
context: { id: "side-panel" },
plugins: [history.plugin],
});
bus.emit("call:start", { prospectId: "prospect_123" });
const entries = history.entries();Replay
Replay is local by default. Local replay calls Fluxa's internal delivery function and does not invoke transport plugin broadcasting.
history.replay();Broadcast replay intentionally goes through bus.emit, so transport plugins can forward the replayed events to other contexts.
history.replay({ mode: "broadcast" });Replay metadata includes:
replayed: truereplayIdreplaySequenceoriginalEventIdoriginalTimestamp
Replay events are not recorded again by default.
Snapshots
const snapshot = history.snapshot();
history.clear();
history.restore(snapshot);Options
limit: Maximum number of events to keep. Defaults to500.filter: Record only matching events.dedupe: Deduplicate bymeta.id. Defaults totrue.recordReplays: Record replayed events. Defaults tofalse.clone: Custom clone function for stored data and metadata.
Repository
https://github.com/janMoudry/fluxa-history
