respond-framework
Version:
create as fast you think
32 lines (31 loc) • 1.38 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = reduce;
var _replayEvents = require("../../modules/replayTools/replayEvents.js");
var _utils = require("../../utils.js");
async function reduce(...events) {
const {
status
} = this.replayState;
switch (status) {
case 'reload':
if (events.length === 1) await events[0].trigger();else await (0, _replayEvents.runEvents)(events, 0, this.state, true); // pass true to block render, as it's expected to happen in userland when status === 'reload'
break;
case 'session':
const e = _utils.isNative ? nativeEvent(this.state.replayTools) : this.eventFrom(window.location);
const last = e ?? events[0];
if (!last) throw new Error(`respond: no event matches ${_utils.isNative ? 'event passed to reduce' : window.location.href}`);
await last.trigger(); // only need to trigger one event since session status doesn't actually re-run any events; instead on first dispatch triggerPlugin bails out if the URL of last event matches prevUrl; however, if the user changed the URL, it will be triggered, and here we capture that case
break;
case 'replay':
default:
await (0, _replayEvents.runEvents)(events, 0, this.state);
}
return this.state;
}
const nativeEvent = ({
evs,
evsIndex
}) => evs[evsIndex] ?? evs.at(-1);