Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move object mapping to mainService DataService #1968

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
Open
2 changes: 1 addition & 1 deletion core/deprecate.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* global console */
var Montage = require("./core").Montage;
var Montage = require("./core").Montage,
Map = require("collections/map");

var deprecatedFeaturesOnceMap = new Map();
Expand Down
11 changes: 8 additions & 3 deletions core/meta/property-descriptor.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,12 +125,17 @@ exports.PropertyDescriptor = Montage.specialize( /** @lends PropertyDescriptor#
if (value !== void 0) {
this._owner = value;
}

this._overridePropertyWithDefaults(deserializer, "cardinality");

if (this.cardinality === -1) {
this.cardinality = Infinity;
}

value = deserializer.getProperty("isDerived");
if (value !== void 0) {
this._isDerived = value;
}

this._overridePropertyWithDefaults(deserializer, "mandatory");
this._overridePropertyWithDefaults(deserializer, "readOnly");
Expand Down Expand Up @@ -303,7 +308,7 @@ exports.PropertyDescriptor = Montage.specialize( /** @lends PropertyDescriptor#
*/
isDerived: {
get: function () {
return false;
return this._isDerived || false;
}
},

Expand Down
10 changes: 8 additions & 2 deletions data/converter/raw-property-value-to-object-converter.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,10 @@ exports.RawPropertyValueToObjectConverter = Converter.specialize( /** @lends Raw
* */
revertSyntax: {
get: function() {
return this._revertSyntax || (this._revertSyntax = parse(this.revertExpression));
if (!this._revertSyntax && this.revertExpression) {
this._revertSyntax = parse(this.revertExpression);
}
return this._revertSyntax;
}
},

Expand All @@ -172,7 +175,10 @@ exports.RawPropertyValueToObjectConverter = Converter.specialize( /** @lends Raw

compiledRevertSyntax: {
get: function () {
return this._compiledRevertSyntax || (this._compiledRevertSyntax = compile(this.revertSyntax));
if (!this._compiledRevertSyntax && this.revertSyntax) {
this._compiledRevertSyntax = compile(this.revertSyntax);
}
return this._compiledRevertSyntax;
}
},

Expand Down
5 changes: 3 additions & 2 deletions data/model/data-object-descriptor.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
var ObjectDescriptor = require("./object-descriptor").ObjectDescriptor,
DataPropertyDescriptor = require("./data-property-descriptor").DataPropertyDescriptor;
DataPropertyDescriptor = require("./data-property-descriptor").DataPropertyDescriptor,
deprecate = require("core/deprecate");

/**
* Extends an object descriptor with the additional object information needed by
Expand All @@ -10,7 +11,7 @@ var ObjectDescriptor = require("./object-descriptor").ObjectDescriptor,
* @extends ObjectDescriptor
*/
exports.DataObjectDescriptor = ObjectDescriptor.specialize(/** @lends DataObjectDescriptor.prototype */ {

/**
* The names of the properties containing the identifier for this type of
* data object.
Expand Down
24 changes: 22 additions & 2 deletions data/service/data-mapping.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,36 @@ exports.DataMapping = Montage.specialize(/** @lends DataMapping.prototype */ {
*/
mapRawDataToObject: {
value: function (data, object, context) {
var i, key,
keys = Object.keys(data);
var i, key, keys;

if (data) {
keys = Object.keys(data);
for (i = 0; (key = keys[i]); ++i) {
object[key] = data[key];
}
}
}
},

/**
* Maps the value of a single raw data property onto the model object
*
* @method
* @argument {Object} data - An object whose properties' values
* hold the raw data.
* @argument {Object} object - The object on which to assign the property
* @argument {string} propertyName - The name of the model property to which
* to assign the value(s).
* @returns {DataStream|Promise|?} - Either the value or a "promise" for it
*
*/
mapRawDataToObjectProperty: {
value: function (data, object, propertyName) {
// TO DO: Provide a default mapping based on object descriptor and prpoerty name
// For now, subclasses must override this.
}
},

/**
* @todo Document.
*/
Expand Down
Loading