local2 example for storage not working
Question
Using code provided in docs. https://github.com/artf/grapesjs/wiki/API-Storage-Manager in "add" examples. I am trying to create my own storage method.
The "store" method works fine, and it adds the content to the localStorage. I can inspect it and see in Applications of chrome devtools.
With autoload: false, refreshing the page shows an empty html body which is what you'd expect. Clicking on a button I have that calls the "load" method runs but does not update the editor.
load: function(keys){
var result = {};
for (var i = 0, len = keys.length; i < len; i++){
var v = localStorage.getItem(keys[i]);
console.log('key', keys[i], v);
if(v) result[keys[i]] = v;
}
return result;
},
(from the docs directly)
This was added by calling...
editor.StorageManager.add('local2', ...
and I call it by running...
editor.load();
This code runs and I see the keys and the data in the console. Is there something that I need to do to update?
Answers (3)
Seems I have to manually call
editor.setComponents(result['gjs-html']);
editor.setStyle(result['gjs-css']);
before the return result above.
That's not in the example code. Is that correct? Seems strange to me, what about the other elements, gjs-styles and gjs-assets? Are they not needed?
Hi Enric, actually the wiki is not updated with the new signature, you have to call the callback
store(data, clb) {
... async store
clb(resultObject);
...
},
load(keys, clb) {
... async load
clb(resultObject);
...
}
thanks for pointing this out
Thanks, will give that a shot later!
Related Questions and Answers
Continue research with similar issue discussions.
Issue #792
Script property using function don't work with blocks
In Components & JS docs there's this example: This works perfectly. But I couldn't use a function instead of a string in script, as is said...
Issue #1113
[QUESTIONS] New trait type is not working with rendered components?
Hello, thanks for the great framework. I'm trying to apply this to my project. I want to add a new trait for existing LINK '<a>' component....
Issue #361
getproperty style manager not working
https://github.com/artf/grapesjs/wiki/API-Style-Manager#getproperty
Issue #581
Reading component related events
The Editor API wiki lists a set of component-related events that can be listened to (e.g. component:add, component:update). There is howeve...
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.