UNPKG

one

Version:

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

105 lines (103 loc) • 3.25 kB
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; })(); export { ForegroundHandler, normalizeBehavior, showAllBehavior, suppressBehavior }; //# sourceMappingURL=handlerState.native.js.map