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); 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 * Load data from the current storage
* @param {Function} clb Callback function * @param {Function} clb Callback function

18
src/editor/model/Editor.js

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

Loading…
Cancel
Save