UNPKG

one

Version:

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

132 lines (130 loc) • 4.2 kB
"use strict"; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); var handlerState_exports = {}; __export(handlerState_exports, { ForegroundHandler: () => ForegroundHandler, normalizeBehavior: () => normalizeBehavior, showAllBehavior: () => showAllBehavior, suppressBehavior: () => suppressBehavior }); module.exports = __toCommonJS(handlerState_exports); function _class_call_check(instance, Constructor) { if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function"); } function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } function _create_class(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } function _define_property(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value, enumerable: true, configurable: true, writable: true }); } else obj[key] = value; return obj; } var showAllBehavior = { shouldShowBanner: true, shouldShowList: true, shouldPlaySound: true, shouldSetBadge: true }; var 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 = /* @__PURE__ */ (function() { "use strict"; function ForegroundHandler2(present) { _class_call_check(this, ForegroundHandler2); _define_property(this, "present", void 0); _define_property(this, "handler", void 0); _define_property(this, "nulled", void 0); _define_property(this, "pending", void 0); this.present = present; this.handler = null; this.nulled = false; this.pending = /* @__PURE__ */ new Set(); } _create_class(ForegroundHandler2, [ { key: "setHandler", value: function setHandler(handler) { this.handler = handler; this.nulled = handler === null; } }, { key: "receive", value: function receive(requestId, notification) { var _this = this; if (this.pending.has(requestId)) return false; if (!this.handler) { this.present(requestId, { ...this.nulled ? suppressBehavior : showAllBehavior }); return true; } var handler = this.handler; this.pending.add(requestId); Promise.resolve().then(function() { return handler.handleNotification(notification); }).then(function(behavior) { return _this.settle(requestId, normalizeBehavior(behavior)); }, function() { return _this.settle(requestId, showAllBehavior); }); return true; } }, { key: "settle", value: function settle(requestId, behavior) { if (!this.pending.delete(requestId)) return; this.present(requestId, { ...behavior }); } } ]); return ForegroundHandler2; })();