Browse Source

Replace getComponentValue with getTargetValue

pull/312/head
Artur Arseniev 9 years ago
parent
commit
f792b3c69a
  1. 1
      src/style_manager/view/PropertyStackView.js
  2. 42
      src/style_manager/view/PropertyView.js
  3. 8
      test/specs/style_manager/view/PropertyView.js

1
src/style_manager/view/PropertyStackView.js

@ -276,7 +276,6 @@ module.exports = PropertyCompositeView.extend({
fieldName = 'values';
a = this.getLayersFromTarget();
} else {
//var v = this.getComponentValue();
var v = this.getTargetValue();
var vDef = this.getDefaultValue();
v = v == vDef ? '' : v;

42
src/style_manager/view/PropertyView.js

@ -214,49 +214,11 @@ module.exports = Backbone.View.extend({
* @return {Boolean}
* */
sameValue() {
return this.getComponentValue() == this.getValueForTarget();
},
/**
* Get the value from the selected component of this property
* @return {String}
* @deprecated use getTargetValue
* */
getComponentValue() {
var propModel = this.model;
var target = this.getTargetModel();
if(!target)
return;
var targetProp = target.get('style')[this.property];
if(targetProp)
this.componentValue = targetProp;
else
this.componentValue = this.model.getDefaultValue() + (this.unit || ''); // todo model
// Check if wrap inside function is required
if (propModel.get('functionName')) {
var v = this.fetchFromFunction(this.componentValue);
if(v)
this.componentValue = v;
}
// This allow to ovveride the normal flow of selecting component value,
// useful in composite properties
if(this.customValue && typeof this.customValue === "function"){
var index = propModel.collection.indexOf(propModel);
var t = this.customValue(this, index);
if(t)
this.componentValue = t;
}
return this.componentValue;
return this.getTargetValue() == this.getValueForTarget();
},
/**
* Refactor of getComponentValue
* Get the value of this property from the target (eg, Component, CSSRule)
* @param {Object} [opts] Options
* @param {Boolean} [options.fetchFromFunction]
* @param {Boolean} [options.ignoreDefault]

8
test/specs/style_manager/view/PropertyView.js

@ -124,21 +124,21 @@ module.exports = {
});
it('Target style is empty without values', () => {
expect(view.getComponentValue()).toNotExist();
expect(view.getTargetValue()).toNotExist();
});
it('Target style is correct', () => {
var style = {};
style[propName] = propValue;
component.set('style', style);
expect(view.getComponentValue()).toEqual(propValue);
expect(view.getTargetValue()).toEqual(propValue);
});
it('Target style is empty with an other style', () => {
var style = {};
style[propName + '2'] = propValue;
component.set('style', style);
expect(view.getComponentValue()).toNotExist();
expect(view.getTargetValue()).toNotExist();
});
it('Fetch value from function', () => {
@ -147,7 +147,7 @@ module.exports = {
style[propName] = 'testfun(' + propValue + ')';
component.set('style', style);
view.model.set('functionName', 'testfun');
expect(view.getComponentValue()).toEqual(propValue);
expect(view.getTargetValue()).toEqual(propValue);
});
describe('With target setted', () => {

Loading…
Cancel
Save