From 3f774762bfd64af232a79e8c667484fee1bac51a Mon Sep 17 00:00:00 2001 From: Artur Arseniev Date: Wed, 4 Aug 2021 11:41:30 +0200 Subject: [PATCH] Add `editor.storeData` --- src/editor/index.js | 11 +++++++++++ src/editor/model/Editor.js | 18 ++++++++++-------- 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/src/editor/index.js b/src/editor/index.js index 428794440..409f2797c 100644 --- a/src/editor/index.js +++ b/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 diff --git a/src/editor/model/Editor.js b/src/editor/model/Editor.js index 6385faf73..3e36d2cb3 100644 --- a/src/editor/model/Editor.js +++ b/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