From 1f1bd669fed7a200fb729332312af2e8be295116 Mon Sep 17 00:00:00 2001 From: Scott Tolksdorf Date: Mon, 12 Dec 2016 10:28:37 -0500 Subject: [PATCH] Added additional protection against debounce saving --- .../snippetbar/snippets/classtable.gen.js | 8 +++---- client/homebrew/pages/editPage/editPage.jsx | 24 +++++++++++-------- package.json | 2 +- 3 files changed, 19 insertions(+), 15 deletions(-) diff --git a/client/homebrew/editor/snippetbar/snippets/classtable.gen.js b/client/homebrew/editor/snippetbar/snippets/classtable.gen.js index 0ccd51a23..28eca21ab 100644 --- a/client/homebrew/editor/snippetbar/snippets/classtable.gen.js +++ b/client/homebrew/editor/snippetbar/snippets/classtable.gen.js @@ -51,8 +51,8 @@ var getFeature = (level)=>{ } module.exports = { - full : function(classname){ - classname = classname || _.sample(classnames) + full : function(){ + classname = _.sample(classnames) var maxes = [4,3,3,3,3,2,2,1,1] var drawSlots = function(Slots){ @@ -91,8 +91,8 @@ module.exports = { }).join('\n') +'\n\n\n'; }, - half : function(classname){ - classname = classname || _.sample(classnames) + half : function(){ + classname = _.sample(classnames) var featureScore = 1 return "
\n##### The " + classname + "\n" + diff --git a/client/homebrew/pages/editPage/editPage.jsx b/client/homebrew/pages/editPage/editPage.jsx index 64c61f8c2..4ce6669e1 100644 --- a/client/homebrew/pages/editPage/editPage.jsx +++ b/client/homebrew/pages/editPage/editPage.jsx @@ -11,18 +11,15 @@ const PrintLink = require('../../navbar/print.navitem.jsx'); const Account = require('../../navbar/account.navitem.jsx'); //const RecentlyEdited = require('../../navbar/recent.navitem.jsx').edited; - const SplitPane = require('naturalcrit/splitPane/splitPane.jsx'); const Editor = require('../../editor/editor.jsx'); const BrewRenderer = require('../../brewRenderer/brewRenderer.jsx'); const Markdown = require('naturalcrit/markdown.js'); - const SAVE_TIMEOUT = 3000; - const EditPage = React.createClass({ getDefaultProps: function() { return { @@ -47,7 +44,6 @@ const EditPage = React.createClass({ return { brew : this.props.brew, - isSaving : false, isPending : false, errors : null, @@ -58,7 +54,7 @@ const EditPage = React.createClass({ savedBrew : null, componentDidMount: function(){ - this.debounceSave = _.debounce(this.save, SAVE_TIMEOUT); + this.trySave(); window.onbeforeunload = ()=>{ if(this.state.isSaving || this.state.isPending){ return 'You have unsaved changes!'; @@ -98,8 +94,7 @@ const EditPage = React.createClass({ brew : _.merge({}, this.state.brew, metadata), isPending : true, }, ()=>{ - console.log(this.hasChanges()); - (this.hasChanges() ? this.debounceSave() : this.debounceSave.cancel()); + this.trySave(); }); }, @@ -116,7 +111,7 @@ const EditPage = React.createClass({ htmlErrors : htmlErrors }); - (this.hasChanges() ? this.debounceSave() : this.debounceSave.cancel()); + this.trySave(); }, hasChanges : function(){ @@ -128,8 +123,18 @@ const EditPage = React.createClass({ return false; }, + trySave : function(){ + if(!this.debounceSave) this.debounceSave = _.debounce(this.save, SAVE_TIMEOUT); + if(this.hasChanges()){ + this.debounceSave(); + }else{ + this.debounceSave.cancel(); + } + }, + save : function(){ - this.debounceSave.cancel(); + if(this.debounceSave && this.debounceSave.cancel) this.debounceSave.cancel(); + this.setState({ isSaving : true, errors : null, @@ -163,7 +168,6 @@ const EditPage = React.createClass({ errMsg += '```\n' + JSON.stringify(this.state.errors.response.error, null, ' ') + '\n```'; }catch(e){} - return Oops!
diff --git a/package.json b/package.json index e67844dfa..466b4b8d3 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "homebrewery", "description": "Create authentic looking D&D homebrews using only markdown", - "version": "2.6.0", + "version": "2.6.1", "scripts": { "build": "node_modules/.bin/gulp prod", "watch": "node_modules/.bin/gulp",