Browse Source

Move style manager updare for styleable:change

up-style-manager
Artur Arseniev 5 years ago
parent
commit
0183432b57
  1. 2
      package.json
  2. 43
      src/style_manager/index.js

2
package.json

@ -66,7 +66,7 @@
}, },
"lint-staged": { "lint-staged": {
"{src,test}/**/*.js": [ "{src,test}/**/*.js": [
"prettier --single-quote --write", "prettier --single-quote --print-width 100 --write",
"git add" "git add"
] ]
}, },

43
src/style_manager/index.js

@ -37,13 +37,7 @@
* @module StyleManager * @module StyleManager
*/ */
import { import { isElement, isUndefined, isArray, isString, debounce } from 'underscore';
isElement,
isUndefined,
isArray,
isString,
debounce
} from 'underscore';
import Module from 'common/module'; import Module from 'common/module';
import { Model } from 'common'; import { Model } from 'common';
import defaults from './config/config'; import defaults from './config/config';
@ -103,12 +97,20 @@ export default () => {
sectors = new Sectors([], c); sectors = new Sectors([], c);
this.model = new Model({ targets: [] }); this.model = new Model({ targets: [] });
const ev = const ev =
'component:toggled component:update:classes change:state change:device frame:resized selector:type styleable:change'; 'component:toggled component:update:classes change:state change:device frame:resized selector:type';
this.model.listenTo( this.model.listenTo(
em, em,
ev, ev,
debounce(() => this.__upSel()) debounce(() => this.__upSel())
); );
this.model.listenTo(
em,
'styleable:change',
debounce(() => {
this.__upProps();
this.__trgCustom();
})
);
return this; return this;
}, },
@ -201,11 +203,7 @@ export default () => {
* const sectors = styleManager.getSectors(); * const sectors = styleManager.getSectors();
* */ * */
getSectors(opts = {}) { getSectors(opts = {}) {
return sectors && sectors.models return sectors && sectors.models ? (opts.array ? [...sectors.models] : sectors) : [];
? opts.array
? [...sectors.models]
: sectors
: [];
}, },
/** /**
@ -268,9 +266,7 @@ export default () => {
if (sector) { if (sector) {
prop = sector prop = sector
.get('properties') .get('properties')
.filter( .filter(prop => prop.get('property') === name || prop.get('id') === name)[0];
prop => prop.get('property') === name || prop.get('id') === name
)[0];
} }
return prop || null; return prop || null;
@ -379,16 +375,12 @@ export default () => {
rules = otherRules.concat(cmpRules); rules = otherRules.concat(cmpRules);
} else { } else {
cmpRules = cssC.getRules(`#${sel.getId()}`); cmpRules = cssC.getRules(`#${sel.getId()}`);
otherRules = cssC.getRules( otherRules = cssC.getRules(target.getSelectors().getFullName(optsSel));
target.getSelectors().getFullName(optsSel)
);
rules = cmpRules.concat(otherRules); rules = cmpRules.concat(otherRules);
} }
const all = rules const all = rules
.filter(rule => .filter(rule => (!isUndefined(state) ? rule.get('state') === state : 1))
!isUndefined(state) ? rule.get('state') === state : 1
)
.sort(cssGen.sortRules) .sort(cssGen.sortRules)
.reverse(); .reverse();
@ -585,9 +577,7 @@ export default () => {
if (!hasVal) { if (!hasVal) {
newValue = null; newValue = null;
const parentItem = parentStyles.filter(p => const parentItem = parentStyles.filter(p => propDef(p.style[name]))[0];
propDef(p.style[name])
)[0];
if (parentItem) { if (parentItem) {
newValue = parentItem.style[name]; newValue = parentItem.style[name];
@ -596,8 +586,7 @@ export default () => {
} }
prop.__setParentTarget(parentTarget); prop.__setParentTarget(parentTarget);
prop.getFullValue() !== newValue && prop.getFullValue() !== newValue && prop.upValue(newValue, { ...opts, __up: true });
prop.upValue(newValue, { ...opts, __up: true });
}); });
}); });
}, },

Loading…
Cancel
Save