Issue #525Opened November 15, 2017by enricribas0 reactions

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)

enricribasNovember 16, 20170 reactions

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?

artfNovember 16, 20170 reactions

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

enricribasNovember 16, 20170 reactions

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

Browse Plugin Categories

Jump directly to plugin category pages on the marketplace.