mirror of
				https://github.com/zulip/zulip.git
				synced 2025-11-03 21:43:21 +00:00 
			
		
		
		
	dict: Move Dict.from(otherdict) functionality into clone method
(imported from commit 6a3981a726922d7acf55b49ea2d477271da430d3)
This commit is contained in:
		@@ -16,29 +16,20 @@ function Dict(opts) {
 | 
			
		||||
 | 
			
		||||
/* Constructs a new Dict object from another object.
 | 
			
		||||
 *
 | 
			
		||||
 * Dict.from(otherdict) -> create a shallow copy of otherdict
 | 
			
		||||
 * Dict.from(jsobj, opts) -> create a Dict with keys corresponding to the
 | 
			
		||||
 *                           properties of jsobj and values corresponding to
 | 
			
		||||
 *                           the value of the appropriate property.  `opts` is
 | 
			
		||||
 *                           passed to the Dict constructor.
 | 
			
		||||
 */
 | 
			
		||||
Dict.from = function Dict_from(obj, opts) {
 | 
			
		||||
    var ret;
 | 
			
		||||
 | 
			
		||||
    if (typeof obj === "object" && obj !== null) {
 | 
			
		||||
        if (obj instanceof Dict) {
 | 
			
		||||
            ret = new Dict(obj._opts);
 | 
			
		||||
            ret._items = _.clone(obj._items);
 | 
			
		||||
        } else {
 | 
			
		||||
            ret = new Dict(opts);
 | 
			
		||||
            _.each(obj, function (val, key) {
 | 
			
		||||
                ret.set(key, val);
 | 
			
		||||
            });
 | 
			
		||||
        }
 | 
			
		||||
    } else {
 | 
			
		||||
    if (typeof obj !== "object" || obj === null) {
 | 
			
		||||
        throw new TypeError("Cannot convert argument to Dict");
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    var ret = new Dict(opts);
 | 
			
		||||
    _.each(obj, function (val, key) {
 | 
			
		||||
        ret.set(key, val);
 | 
			
		||||
    });
 | 
			
		||||
    return ret;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
@@ -51,6 +42,12 @@ Dict.prototype = _.object(_.map({
 | 
			
		||||
        return ':' + k;
 | 
			
		||||
    },
 | 
			
		||||
 | 
			
		||||
    clone: function Dict_clone() {
 | 
			
		||||
        var ret = new Dict(this._opts);
 | 
			
		||||
        ret._items = _.clone(this._items);
 | 
			
		||||
        return ret;
 | 
			
		||||
    },
 | 
			
		||||
 | 
			
		||||
    get: function Dict_get(key) {
 | 
			
		||||
        var mapping = this._items[this._munge(key)];
 | 
			
		||||
        if (mapping === undefined) {
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user