{"size": 3048, "ext": "js", "max_stars_repo_path": "core/serialization/proxy-reviver.js", "max_stars_repo_name": "marchant/palette", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "core/serialization/proxy-reviver.js", "max_issues_repo_name": "marchant/palette", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "core/serialization/proxy-reviver.js", "max_forks_repo_name": "marchant/palette", "max_forks_repo_forks_event_min_datetime": "2019-09-02T23:41:05.000Z", "max_forks_repo_forks_event_max_datetime": "2019-09-02T23:41:05.000Z"}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": 1, "avg_line_length": 26.9734513274, "max_line_length": 103, "alphanum_fraction": 0.5272309711}
var Set = require("montage/collections/set"),
    Map = require("montage/collections/map"),
    MontageReviver = require("montage/core/serialization/deserializer/montage-reviver").MontageReviver,
    Promise = require("montage/core/promise").Promise,
    EditingProxy = require("../editing-proxy").EditingProxy;

exports.ProxyReviver = MontageReviver.specialize({

    constructor: {
        value: function ProxyReviver() {
            this.super();
        }
    },

    getTypeOf: {
        value: function(value) {
            if (
                typeof value === "object" &&
                value !== null
            ) {
                if (value.type === "map") {
                    return "Map";
                } else if (value.type === "set") {
                    return "Set";
                }
            }

            return this.super(value);
        }
    },

    reviveMap: {
        value: function(value, context, label) {
            var map = Map.from(value.entries);

            if (label) {
                context.setObjectLabel(map, label);
            }

            return map;
        }
    },

    reviveSet: {
        value: function(value, context, label) {
            var map = new Set(value.values);

            if (label) {
                context.setObjectLabel(map, label);
            }

            return map;
        }
    },

    /*
     * Revive a montage proxied object.<br/>
     * <b>Note:</b> This need to be overwritten to make something useful
     */
    reviveMontageObject: {
        value: function (value, context, label) {

            if (context.hasUserObject(label)) {
                return context.getUserObject(label);
            }

            var proxyObject = new this.proxyConstructor(),
                self = this,
                revivedSerialization;

            context.setObjectLabel(proxyObject, label);
            revivedSerialization = this.reviveObjectLiteral(value, context);

            if (Promise.is(revivedSerialization)) {
                return revivedSerialization.then(function (revivedSerialization) {
                    return self._initProxy(proxyObject, label, context, revivedSerialization);
                });
            } else {
                return self._initProxy(proxyObject, label, context, revivedSerialization);
            }
        }
    },

    _initProxy: {
        value: function (proxyObject, label, context, serialization) {

            var exportId;

            if (this.rootObjectLabel === label) {
                exportId = context.ownerExportId;
            } else {
                exportId = serialization.prototype || serialization.object;
            }

            return proxyObject.init(label, serialization, exportId, context.editingDocument);
        }
    },

    rootObjectLabel: {
        value: "root"
    },

    proxyConstructor: {
        value: EditingProxy
    },

    // Stop MontageReviver from didReviveObjects
    didReviveObjects: {
        value: function (objects, context) {
        }
    }
});
