UNPKG

penpal

Version:

A promise-based library for communicating with iframes via postMessage.

29 lines (24 loc) 558 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var _default = (localName, log) => { const callbacks = []; let destroyed = false; return { destroy(error) { if (!destroyed) { destroyed = true; log("".concat(localName, ": Destroying connection")); callbacks.forEach(callback => { callback(error); }); } }, onDestroy(callback) { destroyed ? callback() : callbacks.push(callback); } }; }; exports.default = _default;