UNPKG

woltage

Version:

A CQRS and Event-Sourcing Framework

12 lines (11 loc) 487 B
import { projectionStorage } from "../localStorages.js"; export default function sideEffect(fn) { return async (arg) => { const store = projectionStorage.getStore(); if (store?.isReplaying === false) await fn(arg); else if (store === undefined) console.trace(`Invalid side effect execution "${fn.toString()}".`, 'Executing side effects is only possible from event handlers in projections.'); return Promise.resolve(); }; }