How to use the belter/src.uniqueID 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 krakenjs / post-robot / dist / module / public / client.js View on Github external
// $FlowFixMe
                targetWindow = options.window.contentWindow;
            }
        } else {
            targetWindow = options.window;
        }

        if (!targetWindow) {
            throw new Error('Expected options.window to be a window object, iframe, or iframe element id.');
        }

        var win = targetWindow;

        domain = options.domain || WILDCARD;

        var hash = options.name + '_' + uniqueID();

        if (isWindowClosed(win)) {
            throw new Error('Target window is closed');
        }

        var hasResult = false;

        var reqPromises = requestPromises.getOrSet(win, function () {
            return [];
        });

        var requestPromise = ZalgoPromise['try'](function () {

            if (isAncestor(window, win)) {
                return awaitWindowHello(win, options.timeout || CONFIG.CHILD_WINDOW_TIMEOUT);
            }
github paypal / paypal-smart-payment-buttons / test / client / mocks.js View on Github external
const onApprove = () => {
        if (!props) {
            throw new Error(`Can not approve without getting props`);
        }

        onApproveRequestID = uniqueID();

        send(JSON.stringify({
            session_uid:        getSessionUID(),
            source_app:         'paypal_native_checkout_sdk',
            source_app_version: '1.2.3',
            target_app:         'paypal_smart_payment_buttons',
            request_uid:        onApproveRequestID,
            message_uid:        uniqueID(),
            message_type:       'request',
            message_name:       'onApprove',
            message_data:       {
                orderID: props.orderID,
                payerID: 'XXYYZZ123456'
            }
        }));
    };
github krakenjs / zoid / src / component / parent / index.js View on Github external
return this.tryInit(() => {
            this.component.log(`render`);

            let uid = uniqueID();
            let tasks = {};
            
            tasks.onRender = this.props.onRender();

            let domain = this.getDomain();
            let initialDomain = this.getInitialDomain();

            tasks.elementReady = ZalgoPromise.try(() => {
                if (element) {
                    return this.elementReady(element);
                }
            });

            let focus = () => {
                return tasks.open.then(proxyWin => proxyWin.focus());
            };
github krakenjs / post-robot / src / serialize / window.js View on Github external
function getSerializedWindow(winPromise : ZalgoPromise, { send, id = uniqueID() } : { send : SendType, id? : string }) : SerializedWindowType {
    
    let windowNamePromise = winPromise.then(win => {
        if (isSameDomain(win)) {
            return assertSameDomain(win).name;
        }
    });
    
    return {
        id,
        getType: () => winPromise.then(win => {
            return getOpener(win) ? WINDOW_TYPE.POPUP : WINDOW_TYPE.IFRAME;
        }),
        getInstanceID: memoizePromise(() => winPromise.then(win => getWindowInstanceID(win, { send }))),
        close:         () => winPromise.then(closeWindow),
        getName:       () => winPromise.then(win => {
            if (isWindowClosed(win)) {
github paypal / paypal-smart-payment-buttons / src / payment-flows / native.js View on Github external
return ZalgoPromise.try(() => {
        const { version, firebase: firebaseConfig } = config;
        const { getPageUrl } = props;

        sessionUID = uniqueID();
        nativeSocket = getNativeSocket({
            sessionUID, firebaseConfig, version
        });

        nativeSocket.onError(err => {
            nativeSocket = null;
            getLogger().error('native_socket_error', { err: stringifyError(err) });
        });

        return getPageUrl().then(pageUrl => {
            initialPageUrl = pageUrl;
        });
    });
}
github krakenjs / post-robot / src / bridge / bridge.js View on Github external
function addTunnelWindow({ name, source, canary, sendMessage } : TunnelWindowDataType) : string {
    cleanTunnelWindows();
    const id = uniqueID();
    const tunnelWindows = globalStore('tunnelWindows');
    tunnelWindows.set(id, { name, source, canary, sendMessage });
    return id;
}
github krakenjs / post-robot / src / drivers / send / index.js View on Github external
export function sendMessage(win : CrossDomainWindowType, domain : DomainMatcher, message : Message, { on, send } : { on : OnType, send : SendType }) {
    if (isWindowClosed(win)) {
        throw new Error('Window is closed');
    }
    
    const serializedMessage = serializeMessage(win, domain, {
        [ __POST_ROBOT__.__GLOBAL_KEY__ ]: {
            id:     uniqueID(),
            origin: getDomain(window),
            ...message
        }
    }, { on, send });

    const strategies = Object.keys(SEND_MESSAGE_STRATEGIES);
    const errors = [];

    for (const strategyName of strategies) {
        try {
            SEND_MESSAGE_STRATEGIES[strategyName](win, serializedMessage, domain);
        } catch (err) {
            errors.push(err);
        }
    }
github paypal / paypal-smart-payment-buttons / src / api / socket.js View on Github external
const sendMessage = (socket, data) => {
        const messageUID = uniqueID();
        receivedMessages[messageUID] = true;

        const message = {
            session_uid:        sessionUID,
            message_uid:        messageUID,
            source_app:         sourceApp,
            source_app_version: sourceAppVersion,
            target_app:         targetApp,
            ...data
        };

        socket.send(JSON.stringify(message));
    };