From b27515edb65cb5e02f17e0361cda78ea5dddf484 Mon Sep 17 00:00:00 2001 From: Gregory Schier Date: Fri, 13 Oct 2017 21:15:31 +0200 Subject: [PATCH] Fix env editor debounce so no longer lose changes --- app/ui/components/editors/environment-editor.js | 6 +++--- .../modals/workspace-environments-edit-modal.js | 12 ++++++++---- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/app/ui/components/editors/environment-editor.js b/app/ui/components/editors/environment-editor.js index 27a9827ab..715586b45 100644 --- a/app/ui/components/editors/environment-editor.js +++ b/app/ui/components/editors/environment-editor.js @@ -36,11 +36,12 @@ class EnvironmentEditor extends PureComponent { } } + this.props.didChange(); + + // Call this last in case component unmounted if (this.state.error !== error || this.state.warning !== warning) { this.setState({error, warning}); } - - this.props.didChange(); } _setEditorRef (n) { @@ -80,7 +81,6 @@ class EnvironmentEditor extends PureComponent { lineWrapping={lineWrapping} keyMap={editorKeyMap} onChange={this._handleChange} - debounceMillis={DEBOUNCE_MILLIS * 6} defaultValue={JSON.stringify(environment)} nunjucksPowerUserMode={nunjucksPowerUserMode} render={render} diff --git a/app/ui/components/modals/workspace-environments-edit-modal.js b/app/ui/components/modals/workspace-environments-edit-modal.js index 6426dd11f..fda4bc578 100644 --- a/app/ui/components/modals/workspace-environments-edit-modal.js +++ b/app/ui/components/modals/workspace-environments-edit-modal.js @@ -41,6 +41,7 @@ type State = { class WorkspaceEnvironmentsEditModal extends React.PureComponent { environmentEditorRef: EnvironmentEditor | null; colorChangeTimeout: any; + saveTimeout: any; modal: Modal; constructor (props: Props) { @@ -189,13 +190,13 @@ class WorkspaceEnvironmentsEditModal extends React.PureComponent { } _didChange () { - const isValid = this.environmentEditorRef ? this.environmentEditorRef.isValid() : false; + this._saveChanges(); + // Call this last in case component unmounted + const isValid = this.environmentEditorRef ? this.environmentEditorRef.isValid() : false; if (this.state.isValid !== isValid) { this.setState({isValid}); } - - this._saveChanges(); } _getActiveEnvironment (): Environment | null { @@ -247,7 +248,10 @@ class WorkspaceEnvironmentsEditModal extends React.PureComponent { const activeEnvironment = this._getActiveEnvironment(); if (activeEnvironment) { - models.environment.update(activeEnvironment, {data}); + clearTimeout(this.saveTimeout); + this.saveTimeout = setTimeout(() => { + models.environment.update(activeEnvironment, {data}); + }, DEBOUNCE_MILLIS * 4); } }