How to use the belter/src.once function in belter

To help you get started, we’ve selected a few belter examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github paypal / paypal-smart-payment-buttons / src / payment-flows / native.js View on Github external
const connectNative = () : NativeConnection => {
        const socket = nativeSocket;

        if (!socket) {
            throw new Error(`Native socket connection not established`);
        }

        const setNativeProps = once(() => {
            return getSDKProps().then(sdkProps => {
                getLogger().info(`native_message_setprops`).flush();
                return socket.send(SOCKET_MESSAGE.SET_PROPS, sdkProps);
            }).then(() => {
                getLogger().info(`native_response_setprops`).track({
                    [FPTI_KEY.TRANSITION]: FPTI_TRANSITION.NATIVE_APP_SWITCH_ACK
                }).flush();
            });
        });

        const closeNative = once(() => {
            getLogger().info(`native_message_close`).flush();
            return socket.send(SOCKET_MESSAGE.CLOSE).then(() => {
                getLogger().info(`native_response_close`).flush();
                return close();
            });
github paypal / paypal-checkout-components / src / integrations / popupBridge.js View on Github external
function normalizeCheckoutProps(props : Object) : { env : string, payment : Function, onAuthorize : Function, onCancel : Function } {
    let payment = props.payment;
    let onAuthorize = once(props.onAuthorize);
    let onCancel = once(props.onCancel || noop);

    return { env: config.env, payment, onAuthorize, onCancel };
}
github krakenjs / zoid / src / parent / index.js View on Github external
watchForUnload() {
        const unloadWindowListener = addEventListener(window, 'unload', once(() => {
            this.component.log(`navigate_away`);
            this.destroy(new Error(`Window navigated away`));
        }));

        this.clean.register(unloadWindowListener.cancel);
    }
github paypal / paypal-smart-payment-buttons / src / payment-flows / native.js View on Github external
if (useDirectAppSwitch()) {
            popupWin = attemptPopupAppSwitch(nativeUrl);
        } else {
            popupWin = openBlankPopup();
        }

        clean.register(() => {
            if (popupWin && !isWindowClosed(popupWin)) {
                popupWin.close();
            }
        });

        return popupWin;
    };

    const detectAppSwitch = once(() => {
        getLogger().info(`native_detect_app_switch`).track({
            [FPTI_KEY.TRANSITION]: FPTI_TRANSITION.NATIVE_DETECT_APP_SWITCH
        }).flush();

        return connectNative().setProps();
    });

    const detectWebSwitch = once((fallbackWin : ?CrossDomainWindowType) => {
        getLogger().info(`native_detect_web_switch`).track({
            [FPTI_KEY.TRANSITION]: FPTI_TRANSITION.NATIVE_DETECT_WEB_SWITCH
        }).flush();

        return fallbackToWebCheckout(fallbackWin);
    });

    const initDirectAppSwitch = (popupWin : ?CrossDomainWindowType) => {
github krakenjs / post-robot / dist / module / public / server.js View on Github external
var listenerOptions = {
        handler: options.handler,
        handleError: options.errorHandler || function (err) {
            throw err;
        },
        window: win,
        domain: domain || WILDCARD,
        name: name
    };

    var requestListener = addRequestListener({ name: name, win: win, domain: domain }, listenerOptions);

    if (options.once) {
        var _handler = listenerOptions.handler;
        listenerOptions.handler = onceFunction(function listenOnce() {
            requestListener.cancel();
            return _handler.apply(this, arguments);
        });
    }

    if (listenerOptions.window && options.errorOnClose) {
        var interval = safeInterval(function () {
            if (win && (typeof win === 'undefined' ? 'undefined' : _typeof(win)) === 'object' && isWindowClosed(win)) {
                interval.cancel();
                listenerOptions.handleError(new Error('Post message target window is closed'));
            }
        }, 50);
    }

    return {
        cancel: function cancel() {
github krakenjs / zoid / dist / module / component / parent / index.js View on Github external
ParentComponent.prototype.watchForUnload = function watchForUnload() {
        var _this13 = this;

        var unloadWindowListener = addEventListener(window, 'unload', once(function () {
            _this13.component.log('navigate_away');
            _this13.destroy();
        }));

        this.clean.register('destroyUnloadWindowListener', unloadWindowListener.cancel);
    };
github krakenjs / zoid / src / component / parent / index.js View on Github external
watchForUnload() {
        let unloadWindowListener = addEventListener(window, 'unload', once(() => {
            this.component.log(`navigate_away`);
            this.destroy();
        }));

        this.clean.register('destroyUnloadWindowListener', unloadWindowListener.cancel);
    }
github paypal / paypal-checkout-components / src / lib / eligibility.js View on Github external
}

    const userAgent = window.navigator.userAgent;

    if (userAgent && eligibilityResults.hasOwnProperty(userAgent)) {
        return eligibilityResults[userAgent];
    }

    const result = isBrowserEligible();

    eligibilityResults[userAgent] = result;

    return result;
}

export const checkRecognizedBrowser = once((state : string) => {

    const { browser } = getBrowser();

    if (!browser) {
        const { name, version, mobile, android, ios } = getBowser();
        
        const logger = getLogger();
        logger.info(`unrecognized_browser_${ state }`, { name, version, mobile, android, ios });
        logger.flush();
    }
});
github paypal / paypal-smart-payment-buttons / src / flows / checkout.js View on Github external
let approved = false;
    const onApprove = ({ orderID, payerID, paymentID, billingToken }) => {
        approved = true;

        const actions = {
            restart,
            ...buildApproveActions(orderID, fundingSource, restart)
        };

        return window.xprops.onApprove({ orderID, payerID, paymentID, billingToken }, actions).catch(err => {
            return window.xprops.onError(err);
        });
    };

    const onCancel = once(() => {
        return ZalgoPromise.try(() => {
            if (approved) {
                return false;
            }

            return validationPromise;

        }).then(valid => {

            if (!valid) {
                return;
            }
            
            return createOrder().then(orderID => {
                return window.xprops.onCancel({ orderID });
            }).catch(err => {