From b76760d4ccb4905de7fe7f6658a832e88bf9c2fd Mon Sep 17 00:00:00 2001 From: Artur Arseniev Date: Mon, 29 Oct 2018 14:03:17 +0100 Subject: [PATCH] Prevent error on getAttributes when classes collection doesn't exist --- src/css_composer/index.js | 2 +- src/dom_components/model/Component.js | 10 ++++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/css_composer/index.js b/src/css_composer/index.js index 44eba860f..be8e9808a 100644 --- a/src/css_composer/index.js +++ b/src/css_composer/index.js @@ -201,7 +201,7 @@ module.exports = () => { var rule = this.get(selectors, s, w, opt); // do not create rules that were found before - // unless this is an at-rule, for which multiple declarations + // unless this is a single at-rule, for which multiple declarations // make sense (e.g. multiple `@font-type`s) if (rule && rule.config && !rule.config.singleAtRule) { return rule; diff --git a/src/dom_components/model/Component.js b/src/dom_components/model/Component.js index ab68f23c2..8b1dd67c3 100644 --- a/src/dom_components/model/Component.js +++ b/src/dom_components/model/Component.js @@ -153,13 +153,13 @@ const Component = Backbone.Model.extend(Styleable).extend( this.config = opt.config || {}; this.ccid = Component.createId(this); this.set('attributes', this.get('attributes') || {}); - this.listenTo(this, 'change:script', this.scriptUpdated); - this.listenTo(this, 'change:tagName', this.tagUpdated); - this.listenTo(this, 'change:attributes', this.attrUpdated); this.initClasses(); this.initTraits(); this.initComponents(); this.initToolbar(); + this.listenTo(this, 'change:script', this.scriptUpdated); + this.listenTo(this, 'change:tagName', this.tagUpdated); + this.listenTo(this, 'change:attributes', this.attrUpdated); this.set('status', ''); // Register global updates for collection properties @@ -356,7 +356,9 @@ const Component = Backbone.Model.extend(Styleable).extend( const id = this.getId(); // Add classes - this.get('classes').each(cls => classes.push(cls.get('name'))); + this.get('classes').forEach(cls => + classes.push(isString(cls) ? cls : cls.get('name')) + ); classes.length && (attributes.class = classes.join(' ')); // Check if we need an ID on the component