Skip to content

Commit

Permalink
[FIX] ManagedObject: Static binding for altType "string"
Browse files Browse the repository at this point in the history
When a binding info with value property only was used (static binding),
it was not working as expected for aggregations with altType "string".

Change-Id: If8782087f858f3b6eed8b914e7742b3bb92b20d8
  • Loading branch information
Malte Wedel committed Feb 26, 2019
1 parent 5982546 commit f872ee2
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 5 deletions.
15 changes: 10 additions & 5 deletions src/sap.ui.core/src/sap/ui/base/ManagedObject.js
Original file line number Diff line number Diff line change
Expand Up @@ -1073,6 +1073,13 @@ sap.ui.define([
}
}

// checks whether given type name has an object/any primitive type
function isObjectType(sType) {
var oType = DataType.getType(sType),
oPrimitiveTypeName = oType && oType.getPrimitiveType().getName();
return oPrimitiveTypeName === "object" || oPrimitiveTypeName === "any";
}

// call the preprocessor if it has been defined
preprocessor && preprocessor.call(this, mSettings); // TODO: decide whether to call for empty settings as well?

Expand Down Expand Up @@ -1129,20 +1136,18 @@ sap.ui.define([
oValue = mSettings[sKey];
// get info object for the key
if ( (oKeyInfo = mValidKeys[sKey]) !== undefined ) {
var oBindingInfo, oType, oPrimitiveTypeName;
var oBindingInfo;
switch (oKeyInfo._iKind) {
case 0: // PROPERTY
oType = DataType.getType(oKeyInfo.type);
oPrimitiveTypeName = oType && oType.getPrimitiveType().getName();
oBindingInfo = this.extractBindingInfo(oValue, oScope, oPrimitiveTypeName !== "object" && oPrimitiveTypeName !== "any");
oBindingInfo = this.extractBindingInfo(oValue, oScope, !isObjectType(oKeyInfo.type));
if (oBindingInfo && typeof oBindingInfo === "object") {
this.bindProperty(sKey, oBindingInfo);
} else {
this[oKeyInfo._sMutator](oBindingInfo || oValue);
}
break;
case 1: // SINGLE_AGGREGATION
oBindingInfo = oKeyInfo.altTypes && this.extractBindingInfo(oValue, oScope);
oBindingInfo = oKeyInfo.altTypes && this.extractBindingInfo(oValue, oScope, !oKeyInfo.altTypes.some(isObjectType));
if ( oBindingInfo && typeof oBindingInfo === "object" ) {
this.bindProperty(sKey, oBindingInfo);
} else {
Expand Down
35 changes: 35 additions & 0 deletions src/sap.ui.core/test/sap/ui/core/qunit/StaticBinding.qunit.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ sap.ui.define([
value: {type: "string"},
objectValue: {type: "object"},
anyValue: {type: "any"}
},
aggregations: {
altString: {type: "sap.ui.core.Control", altTypes: ["string"], multiple: false},
altObject: {type: "sap.ui.core.Control", altTypes: ["object"], multiple: false},
altMulti: {type: "sap.ui.core.Control", altTypes: ["string", "object"], multiple: false}
}
}
});
Expand Down Expand Up @@ -129,6 +134,36 @@ sap.ui.define([
assert.deepEqual(object.getAnyValue(), { value: "test" }, "object getter returns object for object properties");
});

QUnit.test("Binding info as JS object, aggregation with altType string", function(assert) {
var object = new MyObject({
altString: {
value: "test"
}
});
assert.ok(object.getBindingInfo("altString"), "binding info is created");
assert.equal(object.getAltString(), "test", "object getter returns static value");
});

QUnit.test("Binding info as JS object, aggregation with altType object", function(assert) {
var object = new MyObject({
altObject: {
value: "test"
}
});
assert.notOk(object.getBindingInfo("altObject"), "binding info is not created");
assert.equal(typeof object.getAltObject(), "object", "object getter returns object for aggregation with altType object");
});

QUnit.test("Binding info as JS object, aggregation with altType string,object", function(assert) {
var object = new MyObject({
altMulti: {
value: "test"
}
});
assert.notOk(object.getBindingInfo("altMulti"), "binding info is not created");
assert.equal(typeof object.getAltMulti(), "object", "object getter returns object for aggregation with altType string,object");
});

QUnit.test("Binding info as string", function(assert) {
var object = new MyObject({
value: "{value:123}"
Expand Down

0 comments on commit f872ee2

Please sign in to comment.