UNPKG

penpal

Version:

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

16 lines (15 loc) 361 B
export default () => { const callbacks = []; let destroyed = false; return { destroy(error) { destroyed = true; callbacks.forEach(callback => { callback(error); }); }, onDestroy(callback) { destroyed ? callback() : callbacks.push(callback); } }; };