StorageManager

You can customize the initial state of the module from the editor initialization, by passing the following Configuration Object

const editor = grapesjs.init({
 storageManager: {
   // options
 }
})

Once the editor is instantiated you can use its API. Before using these methods you should get the module from the instance

const storageManager = editor.StorageManager;

getConfig

Get configuration object

Returns Object

isAutosave

Checks if autosave is enabled

Returns Boolean

setAutosave

Set autosave value

Parameters

Returns this

getStepsBeforeSave

Returns number of steps required before trigger autosave

Returns number

setStepsBeforeSave

Set steps required before trigger autosave

Parameters

Returns this

add

Add new storage

Parameters

Examples

storageManager.add('local2', {
  load: function(keys, clb, clbErr) {
    var res = {};
    for (var i = 0, len = keys.length; i < len; i++){
      var v = localStorage.getItem(keys[i]);
      if(v) res[keys[i]] = v;
    }
    clb(res); // might be called inside some async method
    // In case of errors...
    // clbErr('Went something wrong');
  },
  store: function(data, clb, clbErr) {
    for(var key in data)
      localStorage.setItem(key, data[key]);
    clb(); // might be called inside some async method
  }
});

Returns this

get

Returns storage by id

Parameters

Returns (Object | null)

getStorages

Returns all storages

Returns Array

getCurrent

Returns current storage type

Returns string

setCurrent

Set current storage type

Parameters

Returns this

store

Store key-value resources in the current storage

Parameters

  • dataObject Data in key-value format, eg. {item1: value1, item2: value2}
  • clbFunction Callback function

Examples

storageManager.store({item1: value1, item2: value2});

Returns (Object | null)

load

Load resource from the current storage by keys

Parameters

Examples

storageManager.load(['item1', 'item2'], res => {
 // res -> {item1: value1, item2: value2}
});
storageManager.load('item1', res => {
// res -> {item1: value1}
});

getCurrentStorage

Get current storage

Returns Storage

Last Updated: 7/8/2018, 11:25:18 PM