Browse Source

Check for parent prop

up-style-manager
Artur Arseniev 5 years ago
parent
commit
e3d616f748
  1. 24
      src/domain_abstract/model/TypeableCollection.js
  2. 8
      src/style_manager/model/Property.js
  3. 2
      src/style_manager/model/PropertyComposite.js

24
src/domain_abstract/model/TypeableCollection.js

@ -10,6 +10,7 @@ export default {
initialize(models, opts = {}) {
const { em } = opts;
this.em = em;
this.opts = opts;
this.model = (attrs = {}, options = {}) => {
let Model, View, type;
@ -45,15 +46,12 @@ export default {
for (let i = 0; i < types.length; i++) {
const type = types[i];
let typeFound = type.isType(value);
typeFound =
typeof typeFound == 'boolean' && typeFound
? { type: type.id }
: typeFound;
typeFound = typeof typeFound == 'boolean' && typeFound ? { type: type.id } : typeFound;
if (typeFound) {
return {
type,
attributes: typeFound
attributes: typeFound,
};
}
}
@ -61,7 +59,7 @@ export default {
// If, for any reason, the type is not found it'll return the base one
return {
type: this.getBaseType(),
attributes: value
attributes: value,
};
},
@ -117,14 +115,8 @@ export default {
const ModelInst = type ? type.model : baseType.model;
const ViewInst = type ? type.view : baseType.view;
let { model, view, isType } = definition;
model =
model instanceof Model || isFunction(model)
? model
: ModelInst.extend(model || {});
view =
view instanceof View || isFunction(view)
? view
: ViewInst.extend(view || {});
model = model instanceof Model || isFunction(model) ? model : ModelInst.extend(model || {});
view = view instanceof View || isFunction(view) ? view : ViewInst.extend(view || {});
// New API
if (this.extendViewApi && !definition.model && !definition.view) {
@ -141,12 +133,12 @@ export default {
definition.view = view;
definition.isType =
isType ||
function(value) {
function (value) {
if (value && value.type == id) {
return true;
}
};
this.getTypes().unshift(definition);
}
}
},
};

8
src/style_manager/model/Property.js

@ -19,12 +19,18 @@ export default class Property extends Model {
return !!this.em?.getConfig('customUI');
}
__getParentProp() {
return this.collection?.opts?.parentProp;
}
__upTargets(p, opts = {}) {
if (!this.__hasCustom()) return;
const { em } = this;
const sm = em.get('StyleManager');
const name = this.getName();
const value = this.__getFullValue();
const parentProp = this.__getParentProp();
const applyStyle = !opts.__up && !parentProp;
const to = this.changedAttributes();
const from = keys(to).reduce((a, i) => {
@ -33,7 +39,7 @@ export default class Property extends Model {
}, {});
sm.__trgEv(sm.events.propertyUpdate, { property: this, from, to });
!opts.__up && sm.addStyleTargets({ [name]: value, __p: !!opts.avoidStore }, opts);
applyStyle && sm.addStyleTargets({ [name]: value, __p: !!opts.avoidStore }, opts);
}
_up(props, opts = {}) {

2
src/style_manager/model/PropertyComposite.js

@ -26,7 +26,7 @@ export default Property.extend({
const { em } = this;
const properties = this.get('properties') || [];
const Properties = require('./Properties').default;
this.set('properties', new Properties(properties, { em }), { silent: 1 });
this.set('properties', new Properties(properties, { em, parentProp: this }), { silent: 1 });
this.listenTo(this, 'change:value', this.updateValues);
Property.callInit(this, props, opts);
},

Loading…
Cancel
Save