From 548478940a86a9c74d7ab33c6c024486e4d94136 Mon Sep 17 00:00:00 2001 From: Artur Arseniev Date: Thu, 22 Jun 2017 00:36:46 +0200 Subject: [PATCH] Update how the autosave is checked, should fix #119 --- src/editor/model/Editor.js | 41 ++++++++++---------------------------- 1 file changed, 11 insertions(+), 30 deletions(-) diff --git a/src/editor/model/Editor.js b/src/editor/model/Editor.js index 342e530ac..e5f017136 100644 --- a/src/editor/model/Editor.js +++ b/src/editor/model/Editor.js @@ -135,26 +135,28 @@ module.exports = Backbone.Model.extend({ * @private */ listenRule(model) { - this.stopListening(model, 'change:style', this.ruleUpdated); - this.listenTo(model, 'change:style', this.ruleUpdated); + this.stopListening(model, 'change:style', this.componentsUpdated); + this.listenTo(model, 'change:style', this.componentsUpdated); }, /** - * Triggered when rule is updated + * Triggered when something in components is changed * @param {Object} model * @param {Mixed} val Value * @param {Object} opt Options * @private * */ - ruleUpdated(model, val, opt) { - var count = this.get('changesCount') + 1, - avSt = opt ? opt.avoidStore : 0; - this.set('changesCount', count); + componentsUpdated(model, val, opt) { + var count = this.get('changesCount') + 1; + var avoidStore = opt ? opt.avoidStore : 0; var stm = this.get('StorageManager'); - if(stm.isAutosave() && count < stm.getStepsBeforeSave()) + this.set('changesCount', count); + + if (!stm.isAutosave() || count < stm.getStepsBeforeSave()) { return; + } - if(!avSt){ + if (!avoidStore) { this.store(); } }, @@ -218,27 +220,6 @@ module.exports = Backbone.Model.extend({ } }, - /** - * Triggered when components are updated - * @param {Object} model - * @param {Mixed} val Value - * @param {Object} opt Options - * @private - * */ - componentsUpdated(model, val, opt) { - var updatedCount = this.get('changesCount') + 1, - avSt = opt ? opt.avoidStore : 0; - this.set('changesCount', updatedCount); - var stm = this.get('StorageManager'); - if(stm.isAutosave() && updatedCount < stm.getStepsBeforeSave()){ - return; - } - - if(!avSt){ - this.store(); - } - }, - /** * Callback on component selection * @param {Object} Model