Browse Source

Add the possibility to disable StorageManger with `storageManager: false`

pull/1800/head
Artur Arseniev 7 years ago
parent
commit
da4844db17
  1. 17
      src/editor/index.js
  2. 21
      src/editor/model/Editor.js
  3. 10
      src/storage_manager/index.js

17
src/editor/index.js

@ -95,15 +95,14 @@
*/
import $ from 'cash-dom';
export default config => {
var c = config || {},
defaults = require('./config/config'),
EditorModel = require('./model/Editor'),
EditorView = require('./view/EditorView');
for (var name in defaults) {
if (!(name in c)) c[name] = defaults[name];
}
export default (config = {}) => {
const defaults = require('./config/config');
const EditorModel = require('./model/Editor');
const EditorView = require('./view/EditorView');
const c = {
...defaults,
...config
};
c.pStylePrefix = c.stylePrefix;
var em = new EditorModel(c);

21
src/editor/model/Editor.js

@ -173,18 +173,23 @@ module.exports = Backbone.Model.extend({
* @private
*/
loadModule(moduleName) {
var c = this.config;
var Mod = new moduleName();
var name = Mod.name.charAt(0).toLowerCase() + Mod.name.slice(1);
var cfg = c[name] || c[Mod.name] || {};
cfg.pStylePrefix = c.pStylePrefix || '';
const { config } = this;
const Mod = new moduleName();
const name = Mod.name.charAt(0).toLowerCase() + Mod.name.slice(1);
const cfgParent = !isUndefined(config[name])
? config[name]
: config[Mod.name];
const cfg = cfgParent || {};
const sm = this.get('StorageManager');
cfg.pStylePrefix = config.pStylePrefix || '';
// Check if module is storable
var sm = this.get('StorageManager');
if (!isUndefined(cfgParent) && !cfgParent) {
cfg._disable = 1;
}
if (Mod.storageKey && Mod.store && Mod.load && sm) {
cfg.stm = sm;
var storables = this.get('storables');
const storables = this.get('storables');
storables.push(Mod);
this.set('storables', storables);
}

10
src/storage_manager/index.js

@ -71,14 +71,10 @@ module.exports = () => {
* }
* ...
*/
init(config) {
c = config || {};
init(config = {}) {
c = { ...defaults, ...config };
em = c.em;
for (var name in defaults) {
if (!(name in c)) c[name] = defaults[name];
}
if (c._disable) c.type = 0;
defaultStorages.remote = new RemoteStorage(c);
defaultStorages.local = new LocalStorage(c);
c.currentStorage = c.type;

Loading…
Cancel
Save