Skip to content

Commit

Permalink
Deprecate ExpressionDataMapping.objectDescriptorReference
Browse files Browse the repository at this point in the history
  • Loading branch information
tejaede committed Nov 15, 2017
1 parent dfd7fb9 commit 521605a
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 71 deletions.
9 changes: 7 additions & 2 deletions core/deprecate.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,15 @@ exports.deprecationWarningOnce = function deprecationWarningOnce(name, alternati
*
* @returns {Function} deprecationWrapper
*/
exports.deprecateMethod = function deprecate(scope, deprecatedFunction, name, alternative) {
exports.deprecateMethod = function deprecate(scope, deprecatedFunction, name, alternative, once) {
var deprecationWrapper = function () {
// stackTraceLimit = 3 // deprecationWarning + deprecate + caller of the deprecated method
deprecationWarning(name, alternative, 3);
if (once) {
exports.deprecationWarningOnce(name, alternative, 3);
} else {
deprecationWarning(name, alternative, 3);
}

return deprecatedFunction.apply(scope ? scope : this, arguments);
};
deprecationWrapper.deprecatedFunction = deprecatedFunction;
Expand Down
113 changes: 52 additions & 61 deletions data/service/expression-data-mapping.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ var DataMapping = require("./data-mapping").DataMapping,
MappingRule = require("data/service/mapping-rule").MappingRule,
Promise = require("core/promise").Promise,
Scope = require("frb/scope"),
Set = require("collections/set");
Set = require("collections/set"),
deprecate = require("core/deprecate");

var Montage = require("montage").Montage;



Expand Down Expand Up @@ -43,7 +46,8 @@ exports.ExpressionDataMapping = DataMapping.specialize(/** @lends ExpressionData

deserializeSelf: {
value: function (deserializer) {
var value = deserializer.getProperty("objectDescriptor");
var value = deserializer.getProperty("objectDescriptor"),
self = this;
if (value instanceof ObjectDescriptorReference) {
this.objectDescriptorReference = value;
} else {
Expand Down Expand Up @@ -199,13 +203,13 @@ exports.ExpressionDataMapping = DataMapping.specialize(/** @lends ExpressionData
* @type {ObjectDescriptorReference}
*/
objectDescriptorReference: {
get: function () {
return this._objectDescriptorReference ? this._objectDescriptorReference.promise(require) :
Promise.resolve(null);
},
set: function (value) {
get: deprecate.deprecateMethod(void 0, function () {
return this._objectDescriptorReference ? this._objectDescriptorReference.promise(require) :
Promise.resolve(null);
}, "objectDescriptorReference", "objectDescriptor", true),
set: deprecate.deprecateMethod(void 0, function (value) {
this._objectDescriptorReference = value;
}
}, "objectDescriptorReference", "objectDescriptor", true)
},


Expand Down Expand Up @@ -738,77 +742,65 @@ exports.ExpressionDataMapping = DataMapping.specialize(/** @lends ExpressionData
* names and whose values are raw rules
* @param {Boolean} addOneWayBindings - Whether or not to add one way bindings.
*/
_mapObjectMappingRulesLegacy: {
value: function (rawRules, addOneWayBindings) {
var propertyNames = rawRules ? Object.keys(rawRules) : [],
propertyName, rawRule, rule, i;

for (i = 0; (propertyName = propertyNames[i]); ++i) {
rawRule = rawRules[propertyName];
if (this._shouldMapRule(rawRule, addOneWayBindings)) {
rule = this._makeRuleFromRawRule(rawRule, propertyName, addOneWayBindings, true);
this._ownObjectMappingRules.set(rule.targetPath, rule);
}
}
}
},

_mapObjectMappingRules: {
value: function (rawRules) {
var propertyNames = rawRules ? Object.keys(rawRules) : [],
propertyName, rawRule, rule, i;

for (i = 0; (propertyName = propertyNames[i]); ++i) {
rawRule = rawRules[propertyName];
if (this._shouldMapRule(rawRule, true)) {
rule = this._makeRuleFromRawRule(rawRule, propertyName, true, true);
if (!rule.targetPath) {
debugger;
//TODO Add path change listener for objectDescriptor to
//account for chance that objectDescriptor is added after the rules
if (this.objectDescriptor) {
for (i = 0; (propertyName = propertyNames[i]); ++i) {
rawRule = rawRules[propertyName];
if (this._shouldMapRule(rawRule, true)) {
rule = this._makeRuleFromRawRule(rawRule, propertyName, true, true);
if (!rule.targetPath) {
debugger;
}
this._ownObjectMappingRules.set(rule.targetPath, rule);
}

if (this._shouldMapRule(rawRule, false)) {
rule = this._makeRuleFromRawRule(rawRule, propertyName, false, true);
this._ownRawDataMappingRules.set(rule.targetPath, rule);
}
this._ownObjectMappingRules.set(rule.targetPath, rule);
}

if (this._shouldMapRule(rawRule, false)) {
rule = this._makeRuleFromRawRule(rawRule, propertyName, false, true);
this._ownRawDataMappingRules.set(rule.targetPath, rule);
}
}
}
},


/**
* Maps raw object to rawData rules to MappingRule objects
* @param {Object<string:Object>} rawRules - Object whose keys are raw property
* names and whose values are object rules
* @param {Boolean} addOneWayBindings - Whether or not to add one way bindings.
*/
_mapRawDataMappingRules: {
value: function (rawRules) {
var propertyNames = rawRules ? Object.keys(rawRules) : [],
propertyName, rawRule, rule, i;

for (i = 0; (propertyName = propertyNames[i]); ++i) {
rawRule = rawRules[propertyName];
if (this._shouldMapRule(rawRule, false)) {
rule = this._makeRuleFromRawRule(rawRule, propertyName, false, false);
if (!rule.targetPath) {
debugger;
}
this._ownObjectMappingRules.set(rule.targetPath, rule);
}
if (this._shouldMapRule(rawRule, true)) {
rule = this._makeRuleFromRawRule(rawRule, propertyName, true, false);
this._ownRawDataMappingRules.set(rule.targetPath, rule);
}
}
}
},

_mapRawDataMappingRulesLegacy: {
value: function (rawRules, addOneWayBindings) {
var propertyNames = rawRules ? Object.keys(rawRules) : [],
propertyName, rawRule, rule, i;
for (i = 0; (propertyName = propertyNames[i]); ++i) {
rawRule = rawRules[propertyName];
if (this._shouldMapRule(rawRule, addOneWayBindings)) {
rule = this._makeRuleFromRawRule(rawRule, propertyName, addOneWayBindings, false);
this._ownRawDataMappingRules.set(rule.targetPath, rule);
//TODO Add path change listener for objectDescriptor to
//account for chance that objectDescriptor is added after the rules
if (this.objectDescriptor) {
for (i = 0; (propertyName = propertyNames[i]); ++i) {
rawRule = rawRules[propertyName];
if (this._shouldMapRule(rawRule, false)) {
rule = this._makeRuleFromRawRule(rawRule, propertyName, false, false);
if (!rule.targetPath) {
debugger;
}
this._ownObjectMappingRules.set(rule.targetPath, rule);
}
if (this._shouldMapRule(rawRule, true)) {
rule = this._makeRuleFromRawRule(rawRule, propertyName, true, false);
this._ownRawDataMappingRules.set(rule.targetPath, rule);
}
}
}

}
},

Expand Down Expand Up @@ -859,7 +851,6 @@ exports.ExpressionDataMapping = DataMapping.specialize(/** @lends ExpressionData
},



/***************************************************************************
* Deprecated
*/
Expand Down
16 changes: 8 additions & 8 deletions data/service/mapping-rule.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,14 @@ exports.MappingRule = Montage.specialize(/** @lends MappingRule.prototype */ {
},


/**
* Path of the property to which the value of the expression should be retrieved
* @type {string}
*/
sourcePath: {
value: undefined
},

/**
* Object created by parsing .sourcePath using frb/grammar.js that will
* be used to evaluate the data
Expand All @@ -145,14 +153,6 @@ exports.MappingRule = Montage.specialize(/** @lends MappingRule.prototype */ {
}
},

/**
* Path of the property to which the value of the expression should be retrieved
* @type {string}
*/
sourcePath: {
value: undefined
},

/**
* Path of the property to which the value of the expression should be assigned.
* @type {string}
Expand Down

0 comments on commit 521605a

Please sign in to comment.