Ability to unload and destroy the editor instance or reload the config options?
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)
You can access RemoteStorage and update urls at any time:
const RemoteStorage = editor.StorageManager.get('remote');
RemoteStorage.set('urlLoad', [urlLoad]);
RemoteStorage.set('urlStore', [urlStore]);
@ajwootto ,
You can create a custom Remote Storage and inside it apply your custom saving/updating logic.
Take a look on this link: https://github.com/artf/grapesjs/wiki/API-Storage-Manager
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.
Issue #1971
event triggers previous state attributes to remote storage
I'm trying to extract the change in src of an image and store it in the remote storage using Storage Manager, by using the following code T...
Issue #597
storageManager: Loading from remote storage
Hi, I'm trying to read the HTML and CSS from my database. When I try to load it into the editor, nothing displays. I can store the data jus...
Issue #876
[Feature] Pass store manager's response to editor's store callback
Hi @artf, We have a need to get a response of the store manager when calling editor.store() method with a callback (we return generated tem...
Issue #1985
[BUG] Autosave with remote storage doesn't send network requests
OS: Windows 10 Browser: Chrome 73 GrapesJS version: 0.14.57 I have remote storage configured using this call to grapesjs.init(): While I se...
Paid Plugins That Match This Issue
Curated by issue keywords and label relevance to help you ship faster.
Loading paid plugin recommendations...
Browse Plugin Categories
Jump directly to plugin category pages on the marketplace.