UNPKG

@virtualstate/app-history

Version:

Native JavaScript [app-history](https://github.com/WICG/app-history) implementation

34 lines 1.84 kB
import { AppHistoryTransitionNavigationType, AppHistoryTransitionWait, AppHistoryTransitionWhile, } from "./app-history-transition.js"; import { InvalidStateError } from "./app-history-errors.js"; export const AppHistoryTransitionPlanAppHistorySymbol = Symbol.for("@virtualstate/app-history/transition/plan/appHistory"); export const AppHistoryTransitionPlanWhile = Symbol.for("@virtualstate/app-history/transition/plan/while"); export const AppHistoryTransitionPlanWait = Symbol.for("@virtualstate/app-history/transition/plan/wait"); export function plan(options) { const { transition, currentPlan, constructAppHistory, finishedTransitions, } = options; const nextPlan = { [AppHistoryTransitionPlanAppHistorySymbol]: currentPlan?.[AppHistoryTransitionPlanAppHistorySymbol] ?? constructAppHistory(), transitions: [], ...currentPlan, knownTransitions: new Set(currentPlan?.knownTransitions ?? []), [AppHistoryTransitionPlanWhile]: transition[AppHistoryTransitionWhile], [AppHistoryTransitionPlanWait]: transition[AppHistoryTransitionWait] }; if (nextPlan.knownTransitions.has(transition)) { throw new InvalidStateError("Transition already found in plan, this may lead to unexpected behaviour, please raise an issue at "); } nextPlan.knownTransitions.add(transition); if (transition[AppHistoryTransitionNavigationType] === "traverse") { nextPlan.transitions.push(transition); } else { // Reset on non traversal nextPlan.transitions = [] .concat([transition]); } nextPlan.transitions = nextPlan.transitions // Remove finished transitions .filter(transition => finishedTransitions?.has(transition)); return nextPlan; } //# sourceMappingURL=app-history-transition-planner.js.map