Skip to content

Commit

Permalink
Update how changesCount is handled
Browse files Browse the repository at this point in the history
  • Loading branch information
artf committed Oct 23, 2017
1 parent f6a2806 commit bb97caa
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
3 changes: 3 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -1326,6 +1326,9 @@ <h1 class="heading">Insert title here</h1>
editor.on('storage:store', function(e) {
console.log('STORE ', e);
})
editor.on('change:changesCount', function(e) {
console.log('update changesCount ', editor.getModel().get('changesCount'));
})

editor.on('styleManager:change:text-shadow', function(view) {
var model = view.model;
Expand Down
20 changes: 16 additions & 4 deletions src/editor/model/Editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ module.exports = Backbone.Model.extend({
this.initUndoManager();

this.on('change:selectedComponent', this.componentSelected, this);
this.on('change:changesCount', this.updateBeforeUnload, this);
this.on('change:changesCount', this.updateChanges, this);
},

/**
Expand Down Expand Up @@ -100,21 +100,28 @@ module.exports = Backbone.Model.extend({
}
},


/**
* Set the alert before unload in case it's requested
* and there are unsaved changes
* @private
*/
updateBeforeUnload() {
var changes = this.get('changesCount');
updateChanges() {
const stm = this.get('StorageManager');
const changes = this.get('changesCount');

if (this.config.noticeOnUnload && changes) {
window.onbeforeunload = e => 1;
} else {
window.onbeforeunload = null;
}

if (stm.isAutosave() && changes >= stm.getStepsBeforeSave()) {
this.store();
}
},


/**
* Load generic module
* @param {String} moduleName Module name
Expand Down Expand Up @@ -199,17 +206,22 @@ module.exports = Backbone.Model.extend({

timedInterval && clearInterval(timedInterval);
timedInterval = setTimeout(() => {
if (!opt.avoidStore) {
this.set('changesCount', this.get('changesCount') + 1, opt)
}
/*
var count = this.get('changesCount') + 1;
var stm = this.get('StorageManager');
this.set('changesCount', count);
if (!stm.isAutosave() || count < stm.getStepsBeforeSave()) {
return;
}
if (!opt.avoidStore) {
this.set('changesCount', count)
this.store();
}
*/
}, 0);
},

Expand Down

0 comments on commit bb97caa

Please sign in to comment.