UNPKG

one

Version:

One is a React framework for web, iOS, and Android apps.

53 lines (51 loc) • 1.69 kB
const showAllBehavior = { shouldShowBanner: true, shouldShowList: true, shouldPlaySound: true, shouldSetBadge: true }; const suppressBehavior = { shouldShowBanner: false, shouldShowList: false, shouldPlaySound: false, shouldSetBadge: false }; function normalizeBehavior(input) { if (!input || typeof input !== "object") return { ...suppressBehavior }; return { shouldShowBanner: "shouldShowBanner" in input && input.shouldShowBanner === true, shouldShowList: "shouldShowList" in input && input.shouldShowList === true, shouldPlaySound: "shouldPlaySound" in input && input.shouldPlaySound === true, shouldSetBadge: "shouldSetBadge" in input && input.shouldSetBadge === true }; } var ForegroundHandler = class { constructor(present) { this.present = present; } present; handler = null; nulled = false; pending = /* @__PURE__ */ new Set(); setHandler(handler) { this.handler = handler; this.nulled = handler === null; } receive(requestId, notification) { if (this.pending.has(requestId)) return false; if (!this.handler) { this.present(requestId, { ...this.nulled ? suppressBehavior : showAllBehavior }); return true; } const handler = this.handler; this.pending.add(requestId); Promise.resolve().then(() => handler.handleNotification(notification)).then((behavior) => this.settle(requestId, normalizeBehavior(behavior)), () => this.settle(requestId, showAllBehavior)); return true; } settle(requestId, behavior) { if (!this.pending.delete(requestId)) return; this.present(requestId, { ...behavior }); } }; export { ForegroundHandler, normalizeBehavior, showAllBehavior, suppressBehavior }; //# sourceMappingURL=handlerState.mjs.map