Issue #849💬 AnsweredOpened February 8, 2018by ajwootto1 reactions

Ability to unload and destroy the editor instance or reload the config options?

快速解答by maxtacco1

You can access RemoteStorage and update urls at any time:

Read full answer below ↓

Question

In my use case, I'm trying to change the store and load URLs used by the remote storage manager dynamically. As far as I can tell, the editor does not pick up and use any changes to the config if I change them directly, ie. editor.Config.storageManager.storeUrl = 'blah' after the editor has already been initialized.

To try and get around it, I was attempting to unload the editor from the page programmatically by removing the target DOM element and recalling init. However, the init function seems to create multiple instances of the editor. I noticed the GrapesJS.editors array keeping track of them, so I tried setting this to empty to hopefully have the instances be garbage collected. Even in this case however, the editor has event handlers that still seem to trigger afterwards, saving erroneous data.

Ideally, I would like a way to either destroy the editor with some destructor method (if one does not already exist) or force a reloading of the config options without reloading the editor.

Answers (3)

maxtaccoFebruary 8, 2018

You can access RemoteStorage and update urls at any time:

    const RemoteStorage = editor.StorageManager.get('remote');
    RemoteStorage.set('urlLoad', [urlLoad]);
    RemoteStorage.set('urlStore', [urlStore]);
ajwoottoFebruary 8, 2018

Both of those options would probably work, however something I forgot to mention is that in some cases, I want to re-initialize the editor with components and styles pre-specified (ie. passing them in the init) rather than loading them from remote storage, but in other cases I want the initial contents to come from remote storage only. This is happening on the same page, with the contents of the editor having to be swapped around. Is there some API I'm missing that can do this?

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...

Free option

Check the open-source GrapesJS plugins on GitHub or run a quick search in our free catalog.

Browse free plugins →
Premium option

Premium plugins ship with support, regular updates, and production-ready features — save days of integration work.

Browse premium plugins →

Related tutorials

In-depth guides on the same topic.

All tutorials →

Browse Plugin Categories

Jump directly to plugin category pages on the marketplace.