Browse Source

Fix clear on detached stack properties

up-style-manager
Artur Arseniev 5 years ago
parent
commit
c20744443d
  1. 9
      src/style_manager/model/PropertyStack.js
  2. 14
      test/specs/style_manager/model/Properties.js

9
src/style_manager/model/PropertyStack.js

@ -275,7 +275,7 @@ export default Property.extend({
const value = isUndefined(val) ? prop.getDefaultValue() : val; const value = isUndefined(val) ? prop.getDefaultValue() : val;
return { name, value }; return { name, value };
}); });
style = this.get('detached') style = this.isDetached()
? result.reduce((acc, item) => { ? result.reduce((acc, item) => {
acc[item.name] = item.value; acc[item.name] = item.value;
return acc; return acc;
@ -301,6 +301,7 @@ export default Property.extend({
let result = {}; let result = {};
const name = this.getName(); const name = this.getName();
const layers = this.getLayers(); const layers = this.getLayers();
const props = this.getProperties();
const styles = layers.map(l => this.getStyleFromLayer(l)); const styles = layers.map(l => this.getStyleFromLayer(l));
styles.forEach(style => { styles.forEach(style => {
keys(style).map(key => { keys(style).map(key => {
@ -314,8 +315,12 @@ export default Property.extend({
if (this.isDetached()) { if (this.isDetached()) {
result[name] = ''; result[name] = '';
!layers.length &&
props.map(prop => {
result[prop.getName()] = '';
});
} else { } else {
const style = this.getProperties().reduce((acc, prop) => { const style = props.reduce((acc, prop) => {
acc[prop.getName()] = ''; acc[prop.getName()] = '';
return acc; return acc;
}, {}); }, {});

14
test/specs/style_manager/model/Properties.js

@ -585,6 +585,20 @@ describe('StyleManager properties logic', () => {
}); });
}); });
test('On clear removes all values (detached)', () => {
compTypeProp.set('detached', true);
compTypeProp.clear();
expect(compTypeProp.hasValue()).toBe(false);
expect(compTypeProp.getLayers().length).toBe(0);
expect(rule1.getStyle()).toEqual({
__p: false,
[propTest]: '',
[propATest]: '',
[propBTest]: '',
[propCTest]: '',
});
});
test('Get the values from parent style', () => { test('Get the values from parent style', () => {
const rule2 = cssc.addRules(` const rule2 = cssc.addRules(`
@media (max-width: 992px) { @media (max-width: 992px) {

Loading…
Cancel
Save