How to use the zalgo-promise/src.ZalgoPromise function in zalgo-promise

To help you get started, we’ve selected a few zalgo-promise 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-checkout-components / src / checkout / template / containerTemplate.jsx View on Github external
e.preventDefault();
        e.stopPropagation();

        if (isIos()) {
            // eslint-disable-next-line no-alert
            window.alert('Please switch tabs to reactivate the PayPal window');
        } else {
            focus();
        }
    }

    const { style = {} } = props;

    const content = containerContent[lang];

    const onDisplay = new ZalgoPromise(resolve => {
        event.on(EVENT.DISPLAY, resolve);
    });

    const onClose = new ZalgoPromise(resolve => {
        event.on(EVENT.CLOSE, resolve);
    });

    const setupAnimations = (name) => {
        return (el) => {
            onDisplay.then(() => animate(el, `show-${ name }`, noop));
            onClose.then(() => animate(el, `hide-${ name }`, noop));
        };
    };

    let outlet;
github paypal / paypal-checkout-components / src / legacy / interface.js View on Github external
function awaitPaymentTokenAndUrl() : { url : ZalgoPromise, paymentToken : ZalgoPromise } {

    let paymentTokenAndUrl = new ZalgoPromise((resolve) => {

        checkout.initXO = () => {
            warn(`gettoken_initxo`);
        };

        // startFlow is our 'success' case - we get a token, and we can pass it back to the caller

        checkout.startFlow = once((item) => {
            debug(`gettoken_startflow`, { item });

            let { url, paymentToken } = matchUrlAndPaymentToken(item);

            checkUrlAgainstEnv(url);

            return resolve({ url, paymentToken });
        });
github krakenjs / zoid / src / lib / dom.js View on Github external
}
}

export function getElement(id : ElementRefType) : HTMLElement {

    let element = getElementSafe(id);

    if (element) {
        return element;
    }

    throw new Error(`Can not find element: ${ stringify(id) }`);
}


export let documentReady = new ZalgoPromise(resolve => {

    if (window.document.readyState === 'complete') {
        return resolve(window.document);
    }

    let interval = setInterval(() => {
        if (window.document.readyState === 'complete') {
            clearInterval(interval);
            return resolve(window.document);
        }
    }, 10);
});

export function isDocumentReady() : boolean {
    return window.document.readyState === 'complete';
}
github krakenjs / zoid / src / lib / promise.js View on Github external
export function delay(time : number = 1) : ZalgoPromise {
    return new ZalgoPromise(resolve => {
        setTimeout(resolve, time);
    });
}
github krakenjs / zoid / src / component / parent / index.js View on Github external
return ZalgoPromise.try(() => {
            this.onInit = this.onInit || new ZalgoPromise();
            this.onInit.reject(err);

            return this.destroy();

        }).then(() => {
            if (props.onError) {
github krakenjs / post-robot / src / bridge / parent.js View on Github external
return documentBodyReady.then(body => {

            body.appendChild(iframe);
            const bridge = iframe.contentWindow;

            return new ZalgoPromise((resolve, reject) => {

                iframe.addEventListener('load', resolve);
                iframe.addEventListener('error', reject);

            }).then(() => {

                return awaitWindowHello(bridge, BRIDGE_TIMEOUT, `Bridge ${ url }`);

            }).then(() => {

                return bridge;
            });
        });
    }));
github krakenjs / post-robot / src / serialize / promise.js View on Github external
export function deserializePromise(source : CrossDomainWindowType | ProxyWindow, origin : string, { then } : { then : Function }) : ZalgoPromise {
    return new ZalgoPromise(then);
}
github krakenjs / zoid / dist / module / lib / dom.js View on Github external
export function getHttpType(contentType, url) {
    return new ZalgoPromise(function (resolve, reject) {

        var req = new window.XMLHttpRequest();

        req.open('GET', url);
        req.setRequestHeader('Accept', contentType);
        req.send(null);

        req.onload = function () {
            resolve(req.responseText);
        };

        req.onerror = function () {
            return reject(new Error('prefetch failed'));
        };
    });
}
github krakenjs / zoid / dist / module / lib / dom.js View on Github external
export function awaitFrameLoad(frame) {

    if (awaitFrameLoadPromises.has(frame)) {
        var _promise = awaitFrameLoadPromises.get(frame);
        if (_promise) {
            return _promise;
        }
    }

    var promise = new ZalgoPromise(function (resolve, reject) {
        frame.addEventListener('load', function () {
            linkFrameWindow(frame);
            resolve(frame);
        });

        frame.addEventListener('error', function (err) {
            if (frame.contentWindow) {
                resolve(frame);
            } else {
                reject(err);
            }
        });
    });

    awaitFrameLoadPromises.set(frame, promise);