Issue #525πŸ’¬ AnsweredOpened November 15, 2017by enricribas0 reactions

Local2 example for storage not working

Quick answerby enricribas

Seems I have to manually call 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?

Read full answer below ↓

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)

enricribasβ€’ November 16, 2017

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?

artfβ€’ November 16, 2017

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

enricribasβ€’ November 16, 2017

Thanks, will give that a shot later!

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.