@virtualstate/app-history
Version:
Native JavaScript [app-history](https://github.com/WICG/app-history) implementation
28 lines • 1.04 kB
JavaScript
import { AsyncEventTarget } from "./async-event-target.js";
const defaultModule = { EventTarget: AsyncEventTarget, AsyncEventTarget, SyncEventTarget: AsyncEventTarget };
let module;
try {
module = await import("@virtualstate/app-history/event-target");
console.log("Using @virtualstate/app-history/event-target", module);
}
catch {
console.log("Using default");
module = defaultModule;
}
const EventTargetImplementation = module.EventTarget || module.SyncEventTarget || module.AsyncEventTarget;
function assertEventTarget(target) {
if (typeof target !== "function") {
throw new Error("Could not load EventTarget implementation");
}
}
export class EventTarget extends AsyncEventTarget {
constructor(...args) {
super();
if (EventTargetImplementation) {
assertEventTarget(EventTargetImplementation);
const { dispatchEvent } = new EventTargetImplementation(...args);
this.dispatchEvent = dispatchEvent;
}
}
}
//# sourceMappingURL=event-target.js.map