Browse Source

Add `editor.storeData`

pull/3671/head
Artur Arseniev 5 years ago
parent
commit
3f774762bf
  1. 11
      src/editor/index.js
  2. 18
      src/editor/model/Editor.js

11
src/editor/index.js

@ -486,6 +486,17 @@ export default (config = {}) => {
return em.store(clb);
},
/**
* Get the JSON data object, which could be stored and loaded back with `editor.loadData(json)`
* @returns {Object}
* @example
* console.log(editor.storeData());
* // { pages: [...], styles: [...], ... }
*/
storeData() {
return em.storeData();
},
/**
* Load data from the current storage
* @param {Function} clb Callback function

18
src/editor/model/Editor.js

@ -597,16 +597,10 @@ export default Backbone.Model.extend({
* @private
*/
store(clb) {
var sm = this.get('StorageManager');
var store = {};
const sm = this.get('StorageManager');
if (!sm) return;
// Fetch what to store
this.get('storables').forEach(m => {
var obj = m.store(1);
for (var el in obj) store[el] = obj[el];
});
const store = this.storeData();
sm.store(store, res => {
clb && clb(res, store);
this.set('changesCount', 0);
@ -616,6 +610,14 @@ export default Backbone.Model.extend({
return store;
},
storeData() {
let result = {};
this.get('storables').forEach(m => {
result = { ...result, ...m.store(1) };
});
return result;
},
/**
* Load data from the current storage
* @param {Function} clb Callback function

Loading…
Cancel
Save