How to use cross-domain-safe-weakmap - 9 common examples

To help you get started, we’ve selected a few cross-domain-safe-weakmap 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 / src / lib / dom.js View on Github external
if (!container || !element.contentWindow) {
                throw new Error(`Iframe html can not be written unless container provided and iframe in DOM`);
            }

            // $FlowFixMe
            writeToWindow(element.contentWindow, options.html);

        } else {
            element.innerHTML = options.html;
        }
    }

    return element;
}

let awaitFrameLoadPromises : WeakMap> = new WeakMap();

export function awaitFrameLoad(frame : HTMLIFrameElement) : ZalgoPromise {

    if (awaitFrameLoadPromises.has(frame)) {
        let promise = awaitFrameLoadPromises.get(frame);
        if (promise) {
            return promise;
        }
    }

    let promise = new ZalgoPromise((resolve, reject) => {
        frame.addEventListener('load', () => {
            linkFrameWindow(frame);
            resolve(frame);
        });
github krakenjs / post-robot / dist / module / global.js View on Github external
return globalStore('windowStore').getOrSet(key, () => {
    const winStore = new _src.WeakMap();

    const getStore = win => {
      return winStore.getOrSet(win, defStore);
    };

    return {
      has: win => {
        const store = getStore(win);
        return store.hasOwnProperty(key);
      },
      get: (win, defVal) => {
        const store = getStore(win); // $FlowFixMe

        return store.hasOwnProperty(key) ? store[key] : defVal;
      },
      set: (win, val) => {
github krakenjs / post-robot / src / global.js View on Github external
return globalStore('windowStore').getOrSet(key, () => {
        const winStore = new WeakMap();

        const getStore = (win : CrossDomainWindowType | WildCard) : ObjectGetter => {
            return winStore.getOrSet(win, defStore);
        };
    
        return {
            has: (win) => {
                const store = getStore(win);
                return store.hasOwnProperty(key);
            },
            get: (win, defVal) => {
                const store = getStore(win);
                // $FlowFixMe
                return store.hasOwnProperty(key) ? store[key] : defVal;
            },
            set: (win, val) => {
github krakenjs / zoid / dist / module / lib / dom.js View on Github external
// $FlowFixMe
            if (!container || !element.contentWindow) {
                throw new Error('Iframe html can not be written unless container provided and iframe in DOM');
            }

            // $FlowFixMe
            writeToWindow(element.contentWindow, options.html);
        } else {
            element.innerHTML = options.html;
        }
    }

    return element;
}

var awaitFrameLoadPromises = new WeakMap();

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);
        });
github krakenjs / post-robot / dist / module / lib / ready.js View on Github external
import { WeakMap } from 'cross-domain-safe-weakmap/src';
import { getAncestor } from 'cross-domain-utils/src';
import { ZalgoPromise } from 'zalgo-promise/src';
import { noop } from 'belter/src';

import { MESSAGE_NAME, WILDCARD } from '../conf';
import { global } from '../global';

global.readyPromises = global.readyPromises || new WeakMap();
global.knownWindows = global.knownWindows || new WeakMap();

export function onHello(handler) {
    global.on(MESSAGE_NAME.HELLO, { domain: WILDCARD }, function (_ref) {
        var source = _ref.source,
            origin = _ref.origin;

        return handler({ source: source, origin: origin });
    });
}

export function sayHello(win) {
    return global.send(win, MESSAGE_NAME.HELLO, {}, { domain: WILDCARD, timeout: -1 }).then(function (_ref2) {
        var origin = _ref2.origin;

        return { origin: origin };
    });
github krakenjs / zoid / dist / module / lib / util.js View on Github external
if (obj[key] === undefined || obj[key] === null || typeof obj[key] === 'function') {
            continue;
        } else if (obj[key] && Array.isArray(obj[key]) && obj[key].length && obj[key].every(function (val) {
            return (typeof val === 'undefined' ? 'undefined' : _typeof(val)) !== 'object';
        })) {
            newobj['' + prefix + key] = obj[key].join(',');
        } else if (obj[key] && _typeof(obj[key]) === 'object') {
            newobj = dotify(obj[key], '' + prefix + key, newobj);
        } else {
            newobj['' + prefix + key] = obj[key].toString();
        }
    }
    return newobj;
}

var objectIDs = new WeakMap();

export function getObjectID(obj) {

    if (obj === null || obj === undefined || (typeof obj === 'undefined' ? 'undefined' : _typeof(obj)) !== 'object' && typeof obj !== 'function') {
        throw new Error('Invalid object');
    }

    var uid = objectIDs.get(obj);

    if (!uid) {
        uid = (typeof obj === 'undefined' ? 'undefined' : _typeof(obj)) + ':' + uniqueID();
        objectIDs.set(obj, uid);
    }

    return uid;
}
github krakenjs / zoid / src / lib / util.js View on Github external
prefix = prefix ? `${ prefix }.` : prefix;
    for (let key in obj) {
        if (obj[key] === undefined || obj[key] === null || typeof obj[key] === 'function') {
            continue;
        } else if (obj[key] && Array.isArray(obj[key]) && obj[key].length && obj[key].every(val => typeof val !== 'object')) {
            newobj[`${ prefix }${ key }`] = obj[key].join(',');
        } else if (obj[key] && typeof obj[key] === 'object') {
            newobj = dotify(obj[key], `${ prefix }${ key }`, newobj);
        } else {
            newobj[`${ prefix }${ key }`] = obj[key].toString();
        }
    }
    return newobj;
}

let objectIDs = new WeakMap();

export function getObjectID(obj : Object) : string {

    if (obj === null || obj === undefined || (typeof obj !== 'object' && typeof obj !== 'function')) {
        throw new Error(`Invalid object`);
    }

    let uid = objectIDs.get(obj);

    if (!uid) {
        uid = `${ typeof obj }:${ uniqueID() }`;
        objectIDs.set(obj, uid);
    }

    return uid;
}
github krakenjs / post-robot / dist / module / lib / ready.js View on Github external
import { WeakMap } from 'cross-domain-safe-weakmap/src';
import { getAncestor } from 'cross-domain-utils/src';
import { ZalgoPromise } from 'zalgo-promise/src';
import { noop } from 'belter/src';

import { MESSAGE_NAME, WILDCARD } from '../conf';
import { global } from '../global';

global.readyPromises = global.readyPromises || new WeakMap();
global.knownWindows = global.knownWindows || new WeakMap();

export function onHello(handler) {
    global.on(MESSAGE_NAME.HELLO, { domain: WILDCARD }, function (_ref) {
        var source = _ref.source,
            origin = _ref.origin;

        return handler({ source: source, origin: origin });
    });
}

export function sayHello(win) {
    return global.send(win, MESSAGE_NAME.HELLO, {}, { domain: WILDCARD, timeout: -1 }).then(function (_ref2) {
        var origin = _ref2.origin;

        return { origin: origin };
github krakenjs / post-robot / dist / module / lib / serialize.js View on Github external
import { WeakMap } from 'cross-domain-safe-weakmap/src';
import { matchDomain } from 'cross-domain-utils/src';
import { ZalgoPromise } from 'zalgo-promise/src';
import { once, uniqueID } from 'belter/src';
import { TYPE, serialize, serializeType, deserialize } from 'universal-serialize/src';

import { MESSAGE_NAME, WILDCARD } from '../conf';
import { global } from '../global';

global.methods = global.methods || new WeakMap();

var listenForFunctionCalls = once(function () {
    global.on(MESSAGE_NAME.METHOD, { origin: WILDCARD }, function (_ref) {
        var source = _ref.source,
            origin = _ref.origin,
            data = _ref.data;

        var methods = global.methods.get(source);

        if (!methods) {
            throw new Error('Could not find any methods this window has privileges to call');
        }

        var meth = methods[data.id];

        if (!meth) {

cross-domain-safe-weakmap

Cross domain safe WeakMap.

Apache-2.0
Latest version published 3 years ago

Package Health Score

53 / 100
Full package analysis

Popular cross-domain-safe-weakmap functions