From e9d9f5cba152f6011389f3404a23a5ad72f7384c Mon Sep 17 00:00:00 2001 From: Artur Arseniev Date: Tue, 30 Nov 2021 16:52:24 +0100 Subject: [PATCH] Add getValues to composite --- src/style_manager/model/PropertyComposite.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/style_manager/model/PropertyComposite.js b/src/style_manager/model/PropertyComposite.js index 0d78ba3f7..d90d6ef52 100644 --- a/src/style_manager/model/PropertyComposite.js +++ b/src/style_manager/model/PropertyComposite.js @@ -44,12 +44,28 @@ export default Property.extend({ __getFullValue() { if (this.get('detached')) return ''; + // TODO custom build of the value (eg. toValue({ values }), toStyle({ values, name }) ) return this.getProperties() .map(p => p.__getFullValue()) .join(this.get('separator')); }, + /** + * Get current values of properties + * @param {Object} [opts={}] Options + * @param {Boolean} [opts.byName=false] Use property name as key instead of ID + * @returns {Object} + */ + getValues({ byName } = {}) { + return this.getProperties().reduce((res, prop) => { + const key = byName ? prop.getName() : prop.getId(); + const value = prop.hasValue() ? prop.__getFullValue() : prop.getDefaultValue(); + res[key] = `${value}`; + return res; + }, {}); + }, + /** * Clear the value * @return {this}