Browse Source

Update getCacheLoad function

pull/2436/head
Artur Arseniev 7 years ago
parent
commit
f944b168b9
  1. 28
      src/editor/model/Editor.js

28
src/editor/model/Editor.js

@ -1,4 +1,11 @@
import { isUndefined, isArray, contains, toArray, keys } from 'underscore';
import {
isUndefined,
isFunction,
isArray,
contains,
toArray,
keys
} from 'underscore';
import Backbone from 'backbone';
import Extender from 'utils/extender';
import { getModel } from 'utils/mixins';
@ -514,26 +521,23 @@ export default Backbone.Model.extend({
* @private
*/
getCacheLoad(force, clb) {
var f = force ? 1 : 0;
if (this.cacheLoad && !f) return this.cacheLoad;
var sm = this.get('StorageManager');
var load = [];
if (this.cacheLoad && !force) return this.cacheLoad;
const sm = this.get('StorageManager');
const load = [];
if (!sm) return {};
this.get('storables').forEach(m => {
var key = m.storageKey;
key = typeof key === 'function' ? key() : key;
var keys = key instanceof Array ? key : [key];
keys.forEach(k => {
load.push(k);
});
let key = m.storageKey;
key = isFunction(key) ? key() : key;
const keys = isArray(key) ? key : [key];
keys.forEach(k => load.push(k));
});
sm.load(load, res => {
this.cacheLoad = res;
clb && clb(res);
setTimeout(() => this.trigger('storage:load', res), 0);
setTimeout(() => this.trigger('storage:load', res));
});
},

Loading…
Cancel
Save