UNPKG

@noaignite/react-centra-checkout

Version:

React components and helpers for Centra checkout api

76 lines (75 loc) 2.39 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); // src/internal/CentraEvents.ts var CentraEvents_exports = {}; __export(CentraEvents_exports, { CentraEvents: () => CentraEvents }); module.exports = __toCommonJS(CentraEvents_exports); var CENTRA_EVENTS = ["centra_checkout_callback", "centra_checkout_payment_callback"]; function isValidEvent(eventName) { if (CENTRA_EVENTS.includes(eventName)) { return true; } console.error(`@noaignite/react-centra-checkout: There's no event with the name ${eventName}`); return false; } var CentraEvents = class _CentraEvents { eventHandlers; static _default; constructor() { this.eventHandlers = { centra_checkout_callback: /* @__PURE__ */ new Set(), centra_checkout_payment_callback: /* @__PURE__ */ new Set() }; } on(eventName, callback) { if (isValidEvent(eventName)) { this.eventHandlers[eventName]?.add(callback); return true; } return false; } off(eventName, callback) { if (isValidEvent(eventName)) { this.eventHandlers[eventName]?.delete(callback); return true; } return false; } dispatch(eventName, payload) { if (isValidEvent(eventName)) { this.eventHandlers[eventName]?.forEach((handler) => handler(payload)); } } static get default() { if (!_CentraEvents._default) { _CentraEvents._default = new _CentraEvents(); } return _CentraEvents._default; } get default() { return _CentraEvents.default; } }; // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { CentraEvents }); //# sourceMappingURL=CentraEvents.cjs.map