Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removing saved data from storage on submit with low save delay #544

Open
Furgas opened this issue Mar 10, 2017 · 3 comments
Open

Removing saved data from storage on submit with low save delay #544

Furgas opened this issue Mar 10, 2017 · 3 comments

Comments

@Furgas
Copy link

Furgas commented Mar 10, 2017

When autosave delay is low (few seconds - but it depends on server speed), autosave can kick in after submit event listener was processed and value was removed from local storage. So, the item will be inserted to local storage again. Clearing the timeout in listener fixes this issue for me:

SimpleMDE.prototype.autosave = function() {
//...
	if(this.options.autosave.binded !== true) {
		if(simplemde.element.form != null && simplemde.element.form != undefined) {
			simplemde.element.form.addEventListener("submit", function() {
				clearTimeout(simplemde.autosaveTimeoutId);
				simplemde.autosaveTimeoutId = undefined;

				localStorage.removeItem("smde_" + simplemde.options.autosave.uniqueId);

				//restart autosaving in case the submit will be cancelled down the line
				setTimeout(function() {
					simplemde.autosave();
				}, 30000);
			});
		}

		this.options.autosave.binded = true;
	}
//...
};

Should I create a pull request?

@Furgas
Copy link
Author

Furgas commented Mar 10, 2017

By the way, this submit event listener is added for every call to autosave, so with short delay and long document it won't be nice... There should be some this.options.autosave.binded options to guard against it like with this.options.autosave.loaded. I've updated the original post.

@WesCossick
Copy link
Member

It sounds like this would be a good PR. If you'd like, you can submit one and we can review it for inclusion.

@Furgas
Copy link
Author

Furgas commented Apr 27, 2017

I've created pull request #577.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants