How to use the post-robot/src.send function in post-robot

To help you get started, we’ve selected a few post-robot 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 / api / rest.js View on Github external
return body.id;
        }

        throw new Error(`Order Api response error:\n\n${ JSON.stringify(body, null, 4) }`);
    });
}

const PROXY_REST = `proxy_rest`;
const parentWin = getAncestor();

on(PROXY_REST, { domain: getPayPalDomain() }, ({ data }) => {
    proxyRest = data;
});

if (parentWin && isPayPalDomain() && !isSameDomain(parentWin)) {
    send(parentWin, PROXY_REST, { createAccessToken, createOrder })
        .catch(() => {
            // pass
        });
}
github krakenjs / zoid / src / parent / index.js View on Github external
delegate(context : $Values, target : CrossDomainWindowType) {
        this.component.log(`delegate`);

        const props = {};
        for (const propName of this.component.getPropNames()) {
            if (this.component.getPropDefinition(propName).allowDelegate) {
                props[propName] = this.props[propName];
            }
        }

        const overridesPromise = send(target, `${ POST_MESSAGE.DELEGATE }_${ this.component.name }`, {
            context,
            props,
            overrides: {
                event:   this.event,
                close:   () => this.close(),
                onError: (err) => this.onError(err)
            }

        }).then(({ data }) => {
            this.clean.register(data.destroy);
            return data.overrides;

        }).catch(err => {
            throw new Error(`Unable to delegate rendering. Possibly the component is not loaded in the target window.\n\n${ stringifyError(err) }`);
        });
github krakenjs / zoid / dist / module / component / component / index.js View on Github external
Component.prototype.canRenderTo = function canRenderTo(win) {
        return send(win, POST_MESSAGE.ALLOW_DELEGATE + '_' + this.name).then(function (_ref3) {
            var data = _ref3.data;

            return data;
        })['catch'](function () {
            return false;
        });
    };
github krakenjs / zoid / src / component / parent / index.js View on Github external
delegate(context : $Values, target : CrossDomainWindowType) {
        this.component.log(`delegate`);

        let props = {};
        for (let propName of this.component.getPropNames()) {
            if (this.component.getProp(propName).allowDelegate) {
                props[propName] = this.props[propName];
            }
        }

        let delegate = send(target, `${ POST_MESSAGE.DELEGATE }_${ this.component.name }`, {
            context,
            props,
            overrides: {
                userClose: () => this.userClose(),
                error:     (err) => this.error(err),
                on:        (eventName, handler) => this.on(eventName, handler)
            }

        }).then(({ data }) => {
            this.clean.register(data.destroy);
            return data;

        }).catch(err => {
            throw new Error(`Unable to delegate rendering. Possibly the component is not loaded in the target window.\n\n${ stringifyError(err) }`);
        });
github krakenjs / zoid / src / component / component.js View on Github external
canRenderTo(win : CrossDomainWindowType) : ZalgoPromise {
        return send(win, `${ POST_MESSAGE.ALLOW_DELEGATE }_${ this.name }`).then(({ data }) => {
            return data;
        }).catch(() => {
            return false;
        });
    }
github krakenjs / zoid / src / component / component / index.js View on Github external
canRenderTo(win : CrossDomainWindowType) : ZalgoPromise {
        return send(win, `${ POST_MESSAGE.ALLOW_DELEGATE }_${ this.name }`).then(({ data }) => {
            return data;
        }).catch(() => {
            return false;
        });
    }
github paypal / paypal-checkout-components / src / lib / proxy.js View on Github external
export function proxyMethod(name : string, win : ?CrossDomainWindowType, originalMethod : Function) : Function {

    if (win && getDomain() === getPayPalDomain() && !isSameDomain(win)) {

        if (win) {
            send(win, `proxy_${ name }`, { originalMethod }).catch(noop);
        }

        return originalMethod;
    }

    let methods = [];

    on(`proxy_${ name }`, { domain: getPayPalDomain() }, ({ data }) => {
        methods.push(data.originalMethod);
    });

    return function postMessageProxy() : mixed {

        methods = methods.filter(method => !isWindowClosed(method.source));

        if (methods.length) {