all files / montage/core/serialization/deserializer/ properties-deserializer.js

17.65% Statements 3/17
0% Branches 0/6
0% Functions 0/4
17.65% Lines 3/17
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53                                                                                                    
var Montage = require("../../core").Montage;
 
var PropertiesDeserializer = Montage.specialize( {
    _object: {value: null},
    _objectDescriptor: {value: null},
    _context: {value: null},
 
    initWithObjectAndObjectDescriptorAndContext: {
        value: function (object, objectDescriptor, context) {
            this._object = object;
            this._objectDescriptor = objectDescriptor;
            this._context = context;
 
            return this;
        }
    },
 
    get: {
        value: function (name) {
            if (this._objectDescriptor.properties) {
                return this._objectDescriptor.properties[name];
            }
        }
    },
 
    deserializeProperties: {
        value: function (propertyNames) {
            var object = this._object,
                properties = this._objectDescriptor.properties,
                propertyName;
 
            if (properties) {
                if (!propertyNames) {
                    propertyNames = Montage.getSerializablePropertyNames(object);
                }
 
                for (var i = 0, ii = propertyNames.length; i < ii; i++) {
                    propertyName = propertyNames[i];
                    object[propertyName] = properties[propertyName];
                }
            }
        }
    },
 
    getObjectByLabel: {
        value: function (label) {
            this._context.getObject(label);
        }
    }
});
 
exports.PropertiesDeserializer = PropertiesDeserializer;