Issue #441Opened October 20, 2017by santiph0 reactions

Ignore/avoid changeCount

Question

Due to https://github.com/artf/grapesjs/issues/436, I cannot rely on StorageManager's Remote Load method to load a template from a REST endpoint, so I'm falling back to alternatives as editor.setComponents() and editor.setStyle() (being used within a command, so grapesjs and editor are available).

Unfortunately, those methods make changesCount to increase and triggers onbeforeunload event when our users try to leave the webpage. Also, including sentences like editor.editor.set('changesCount', 0); in the command are useless, since changesCount gets incremented as soon as the command finishes (even after completing run() and stop() execution).

Is there any workaround this issue? Or any way to override changesCount right after .setComponents()/.setStyles() are used?

Thanks. PS: As for https://github.com/artf/grapesjs/issues/436, I'll be working on a refactor proposal for fetch library to make it REST-compliant. Hope to push it at some point next week

Answers (3)

artfOctober 23, 20170 reactions

Hi @santiph well, if the problem is onbeforeunload you can disable it with noticeOnUnload

grapesjs.init({
     ...
     noticeOnUnload: false
})
santiphOctober 23, 20170 reactions

Hi @artf I need to warn the user know of any unsaved changes consistently. And skip it when there's nothing new to be saved: When a new empty template is created, right after saving or right after loading a template, no confirmation message should be displayed.

Saving scenario through StorageManager works as expected. Loading doesn't, unfortunately. At least not when components, styles, html and so on is being loaded through the editor's API, not the StorageManager .load().

santiphOctober 24, 20170 reactions

I could test it with remote storage fully: onbeforeunload is disabled, as expected, on closing right after saving. Unfortunately, it's still being displayed on closing right after loading a new template.

After a little debugging, loading a new template seems to increase changesCount to 1. (Load changesCount = 1. Load changesCount = 2. Load changesCount = 3.) How could this counter be reseted if the reason of template change was Loading a new one?

Related Questions and Answers

Continue research with similar issue discussions.

Paid Plugins That Match This Issue

Curated by issue keywords and label relevance to help you ship faster.

View all plugins

Loading paid plugin recommendations...

Browse Plugin Categories

Jump directly to plugin category pages on the marketplace.