How to use the post-robot/src.on 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 krakenjs / zoid / test / child.js View on Github external
/* @flow */

import { on } from 'post-robot/src';

import './component';

on('eval', ({ data: { code } }) => {
    eval(code); // eslint-disable-line no-eval, security/detect-eval-with-expression
});

if (window.xprops.run) {
    // eslint-disable-next-line no-unused-vars
    let zoid = require('../src');
    // eslint-disable-next-line no-unused-vars
    let { onWindowOpen } = require('./common');
    eval(`(function() { ${ window.xprops.run } }).call(this);`); // eslint-disable-line no-eval, security/detect-eval-with-expression
}
github paypal / paypal-checkout-components / src / api / rest.js View on Github external
}).then(({ body }) : string => {

        logOrderResponse(body.id);

        if (body && body.id) {
            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 paypal / paypal-checkout-components / src / compat / fallback.js View on Github external
import { isPayPalDomain, noop, getScriptVersion, extendUrl } from '../lib';
import { config } from '../config';

function match(str : string, pattern : RegExp) : ?string {
    let regmatch : ?Array = str.match(pattern);
    if (regmatch) {
        return regmatch[1];
    }
}

let onAuthorize : ?Function;

// Post-Bridge

if (isPayPalDomain()) {
    on('onLegacyPaymentAuthorize', { window: window.parent }, ({ data } : { data : { method : Function } }) => {
        onAuthorize = data.method;
    });
}

// Button / Merchant

export function onLegacyPaymentAuthorize(method : Function) : ZalgoPromise {
    onAuthorize = method;

    return ZalgoPromise.try(() => {
        if (bridge && !isPayPalDomain()) {
            return bridge.openBridge(extendUrl(config.postBridgeUrl, { version: getScriptVersion() }), config.postBridgeDomain).then((postBridge : CrossDomainWindowType) => {
                return send(postBridge, 'onLegacyPaymentAuthorize', { method }, { domain: config.paypalDomain })
                    .then(noop);
            });
        }
github krakenjs / zoid / test / windows / child / index.js View on Github external
setTimeout(() => {
        window.close();
        if (window.frameElement) {
            destroyElement(window.frameElement);
        }
    }, 1);
    throw new Error(`No xprops found`);
}

const xEval = (code) => {
    return ZalgoPromise.try(() => {
        return eval(`(function() { ${ code } })()`);
    });
};

on('eval', ({ data: { code } }) => {
    return xEval(code);
});

if (window.xprops.run) {
    window.xprops.run().then(code => {
        const wrappedCode = `(function() { ${ code } }).call(this);`;

        if (window.xprops.runOnClick) {
            runOnClick(() => {
                eval(wrappedCode);
            });
        } else {
            eval(wrappedCode);
        }
    }).then(() => {
        if (window.xprops.postRun) {
github krakenjs / zoid / src / component / component / index.js View on Github external
listenDelegate() {
        on(`${ POST_MESSAGE.ALLOW_DELEGATE }_${ this.name }`, () => {
            return true;
        });

        on(`${ POST_MESSAGE.DELEGATE }_${ this.name }`, ({ source, data: { context, props, overrides } }) => {
            return this.delegate(source, { context, props, overrides }).getDelegate();
        });
    }
github krakenjs / zoid / src / component / component / index.js View on Github external
listenDelegate() {
        if (this.remoteRenderDomain) {
            postRobot.on(`${POST_MESSAGE.DELEGATE}_${this.name}`, { domain: this.remoteRenderDomain }, ({ source, data}) => {

                let delegate = this.delegate(source, data.options);

                return {
                    overrides: delegate.getOverrides(data.context),
                    destroy:   () => delegate.destroy()
                };
            });
        }
    }
github krakenjs / zoid / dist / module / component / component / index.js View on Github external
Component.prototype.listenDelegate = function listenDelegate() {
        var _this2 = this;

        on(POST_MESSAGE.ALLOW_DELEGATE + '_' + this.name, function () {
            return true;
        });

        on(POST_MESSAGE.DELEGATE + '_' + this.name, function (_ref2) {
            var source = _ref2.source,
                _ref2$data = _ref2.data,
                context = _ref2$data.context,
                props = _ref2$data.props,
                overrides = _ref2$data.overrides;

            return _this2.delegate(source, { context: context, props: props, overrides: overrides }).getDelegate();
        });
    };
github krakenjs / zoid / src / component / component.js View on Github external
listenDelegate() {
        on(`${ POST_MESSAGE.ALLOW_DELEGATE }_${ this.name }`, () => {
            return true;
        });

        on(`${ POST_MESSAGE.DELEGATE }_${ this.name }`, ({ source, data: { context, props, overrides } }) => {
            const delegate = new DelegateComponent(this, source, { context, props, overrides });
            return delegate.getDelegate();
        });
    }