How to use universal-serialize - 10 common examples

To help you get started, we’ve selected a few universal-serialize 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 / src / serialize / function.js View on Github external
if (typeof name === 'string' && typeof name.indexOf === 'function' && name.indexOf('anonymous::') === 0) {
        name = name.replace('anonymous::', `${ key }::`);
    }

    if (ProxyWindow.isProxyWindow(destination)) {
        addMethod(id, val, name, destination, domain);

        // $FlowFixMe
        destination.awaitWindow().then(win => {
            addMethod(id, val, name, win, domain);
        });
    } else {
        addMethod(id, val, name, destination, domain);
    }

    return serializeType(SERIALIZATION_TYPE.CROSS_DOMAIN_FUNCTION, { id, name });
}
github krakenjs / post-robot / dist / module / lib / serialize.js View on Github external
function serializePromise(destination, domain, val, key) {
    return serializeType(CUSTOM_TYPE.CROSS_DOMAIN_ZALGO_PROMISE, {
        then: serializeFunction(destination, domain, function (resolve, reject) {
            return val.then(resolve, reject);
        }, key)
    });
}
github krakenjs / post-robot / dist / module / lib / serialize.js View on Github external
function serializeFunction(destination, domain, val, key) {
    var id = uniqueID();

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

    if (!methods) {
        methods = {};
        global.methods.set(destination, methods);
    }

    methods[id] = { domain: domain, val: val };

    listenForFunctionCalls();

    return serializeType(CUSTOM_TYPE.CROSS_DOMAIN_FUNCTION, { id: id, name: val.name || key });
}
github krakenjs / post-robot / src / serialize / promise.js View on Github external
export function serializePromise(destination : CrossDomainWindowType | ProxyWindow, domain : DomainMatcher, val : Thenable, key : string, { on, send } : { on : OnType, send : SendType }) : SerializedPromise {
    return serializeType(SERIALIZATION_TYPE.CROSS_DOMAIN_ZALGO_PROMISE, {
        then: serializeFunction(destination, domain, (resolve, reject) => val.then(resolve, reject), key, { on, send })
    });
}
github krakenjs / post-robot / src / serialize / window.js View on Github external
export function serializeWindow(destination : CrossDomainWindowType | ProxyWindow, domain : DomainMatcher, win : CrossDomainWindowType, { send } : { send : SendType }) : SerializedWindow {
    return serializeType(SERIALIZATION_TYPE.CROSS_DOMAIN_WINDOW, ProxyWindow.serialize(win, { send }));
}
github krakenjs / post-robot / dist / module / serialize / serialize.js View on Github external
function serializeMessage(destination, domain, obj, {
  on,
  send
}) {
  return (0, _src2.serialize)(obj, {
    [_src2.TYPE.PROMISE]: (val, key) => (0, _promise.serializePromise)(destination, domain, val, key, {
      on,
      send
    }),
    [_src2.TYPE.FUNCTION]: (val, key) => (0, _function.serializeFunction)(destination, domain, val, key, {
      on,
      send
    }),
    [_src2.TYPE.OBJECT]: val => {
      return (0, _src.isWindow)(val) || _window.ProxyWindow.isProxyWindow(val) ? (0, _window.serializeWindow)(destination, domain, val, {
        on,
        send
      }) : val;
    }
  });
}
github krakenjs / post-robot / dist / module / serialize / serialize.js View on Github external
function serializeMessage(destination, domain, obj, {
  on,
  send
}) {
  return (0, _src2.serialize)(obj, {
    [_src2.TYPE.PROMISE]: (val, key) => (0, _promise.serializePromise)(destination, domain, val, key, {
      on,
      send
    }),
    [_src2.TYPE.FUNCTION]: (val, key) => (0, _function.serializeFunction)(destination, domain, val, key, {
      on,
      send
    }),
    [_src2.TYPE.OBJECT]: val => {
      return (0, _src.isWindow)(val) || _window.ProxyWindow.isProxyWindow(val) ? (0, _window.serializeWindow)(destination, domain, val, {
        on,
        send
      }) : val;
    }
  });
}
github krakenjs / post-robot / dist / module / lib / serialize.js View on Github external
export function serializeMessage(destination, domain, obj) {
    var _serialize;

    return serialize(obj, (_serialize = {}, _serialize[TYPE.PROMISE] = function (val, key) {
        return serializePromise(destination, domain, val, key);
    }, _serialize[TYPE.FUNCTION] = function (val, key) {
        return serializeFunction(destination, domain, val, key);
    }, _serialize));
}
github krakenjs / post-robot / src / serialize / serialize.js View on Github external
export function serializeMessage(destination : CrossDomainWindowType | ProxyWindow, domain : DomainMatcher, obj : T, { on, send } : { on : OnType, send : SendType }) : string {
    return serialize(obj, {
        [ TYPE.PROMISE ]:  (val : Thenable, key : string) : SerializedPromise => serializePromise(destination, domain, val, key, { on, send }),
        [ TYPE.FUNCTION ]: (val : Function, key : string) : SerializedFunction => serializeFunction(destination, domain, val, key, { on, send }),
        [ TYPE.OBJECT ]:   (val : CrossDomainWindowType) : Object | SerializedWindow => {
            return (isWindow(val) || ProxyWindow.isProxyWindow(val)) ? serializeWindow(destination, domain, val, { on, send }) : val;
        }
    });
}
github krakenjs / post-robot / dist / module / lib / serialize.js View on Github external
export function serializeMessage(destination, domain, obj) {
    var _serialize;

    return serialize(obj, (_serialize = {}, _serialize[TYPE.PROMISE] = function (val, key) {
        return serializePromise(destination, domain, val, key);
    }, _serialize[TYPE.FUNCTION] = function (val, key) {
        return serializeFunction(destination, domain, val, key);
    }, _serialize));
}