Skip to content

Commit

Permalink
Replace getComponentValue with getTargetValue
Browse files Browse the repository at this point in the history
  • Loading branch information
artf committed Sep 14, 2017
1 parent b9ebcfb commit f792b3c
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 45 deletions.
1 change: 0 additions & 1 deletion src/style_manager/view/PropertyStackView.js
Expand Up @@ -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;
Expand Down
42 changes: 2 additions & 40 deletions src/style_manager/view/PropertyView.js
Expand Up @@ -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]
Expand Down
8 changes: 4 additions & 4 deletions test/specs/style_manager/view/PropertyView.js
Expand Up @@ -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', () => {
Expand All @@ -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', () => {
Expand Down

0 comments on commit f792b3c

Please sign in to comment.