UNPKG

@empirica/core

Version:
123 lines (120 loc) 3.78 kB
import { trace } from "./chunk-TIKLWCJI.js"; // src/player/provider.ts import { Subject, groupBy } from "rxjs"; var TajribaProvider = class { constructor(changes, globals, setAttributes) { this.globals = globals; this.setAttributes = setAttributes; this.scopes = new Subject(); this.attributes = new Subject(); this.participants = new Subject(); this.steps = new Subject(); this.dones = new Subject(); let scopeIDs = []; changes.pipe(groupBy((chg) => chg?.change?.__typename)).subscribe({ next: (group) => { switch (group.key) { case "ScopeChange": group.subscribe({ next: (msg) => { if (!msg.change || msg.removed === null || msg.removed === void 0) { trace("AttributeChange empty"); } else { this.scopes.next({ scope: msg.change, removed: msg.removed }); } if (msg.done) { this.dones.next(scopeIDs); } } }); break; case "AttributeChange": group.subscribe({ next: (msg) => { if (!msg.change || msg.removed === null || msg.removed === void 0) { trace("AttributeChange empty"); } else { const atChange = msg.change; scopeIDs.push(atChange.nodeID || atChange.node.id); this.attributes.next({ attribute: atChange, removed: msg.removed }); } if (msg.done) { this.dones.next(scopeIDs); scopeIDs = []; } } }); break; case "ParticipantChange": group.subscribe({ next: (msg) => { if (!msg.change || msg.removed === null || msg.removed === void 0) { trace("ParticipantChange empty"); } else { this.participants.next({ participant: msg.change, removed: msg.removed }); } if (msg.done) { this.dones.next([]); } } }); break; case "StepChange": group.subscribe({ next: (msg) => { if (!msg.change || msg.removed === null || msg.removed === void 0) { trace("StepChange empty"); } else { this.steps.next({ step: msg.change, removed: msg.removed }); } if (msg.done) { this.dones.next([]); } } }); break; default: group.subscribe({ next: (change) => { if (change.done) { this.dones.next([]); } } }); break; } } }); } }; // src/player/utils.ts var isDevelopment = process.env.NODE_ENV === "development"; var isProduction = process.env.NODE_ENV === "production"; var isTest = process.env.NODE_ENV === "test"; var createNewParticipant = (key = "participantKey") => { const url = new URL(document.location.href); url.searchParams.set(key, (/* @__PURE__ */ new Date()).getTime().toString()); window.open(url.href, "_blank")?.focus(); }; export { TajribaProvider, isDevelopment, isProduction, isTest, createNewParticipant }; //# sourceMappingURL=chunk-6SEN3GDC.js.map