Skip to content

Commit

Permalink
Improve TypeableCollection
Browse files Browse the repository at this point in the history
  • Loading branch information
artf committed Aug 29, 2017
1 parent dc14d18 commit 5f9ba62
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 27 deletions.
4 changes: 2 additions & 2 deletions dist/grapes.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
@@ -1,7 +1,7 @@
{
"name": "grapesjs",
"description": "Free and Open Source Web Builder Framework",
"version": "0.9.33",
"version": "0.9.34",
"author": "Artur Arseniev",
"license": "BSD-3-Clause",
"homepage": "http://grapesjs.com",
Expand Down
9 changes: 8 additions & 1 deletion src/asset_manager/index.js
Expand Up @@ -63,6 +63,10 @@ module.exports = () => {
*/
storageKey: 'assets',

getConfig() {
return c;
},

/**
* Initialize module
* @param {Object} config Configurations
Expand All @@ -84,7 +88,7 @@ module.exports = () => {
}

// Global assets collection
assets = new Assets(c.assets);
assets = new Assets([]);
const obj = {
// Collection visible in asset manager
collection: new Assets([]),
Expand Down Expand Up @@ -257,6 +261,9 @@ module.exports = () => {

postRender(editorView) {
c.dropzone && fu.initDropzone(editorView);

// Leave it here for custom types
assets.add(c.assets, {silent: 1});
},

/**
Expand Down
26 changes: 12 additions & 14 deletions src/asset_manager/model/Assets.js
@@ -1,20 +1,18 @@
import TypeableCollection from 'domain_abstract/model/TypeableCollection';

module.exports = require('backbone').Collection.extend(TypeableCollection).extend({
getTypes() {
return [{
id: 'image',
model: require('./AssetImage'),
view: require('./../view/AssetImageView'),
isType(value) {
if (typeof value == 'string') {
return {
type: 'image',
src: value,
}
types: [{
id: 'image',
model: require('./AssetImage'),
view: require('./../view/AssetImageView'),
isType(value) {
if (typeof value == 'string') {
return {
type: 'image',
src: value,
}
return value;
}
}];
}
return value;
}
}]
});
5 changes: 0 additions & 5 deletions src/asset_manager/view/AssetsView.js
Expand Up @@ -40,11 +40,6 @@ module.exports = Backbone.View.extend({
this.listenTo(this.collection, 'add', this.addToAsset );
this.listenTo(this.collection, 'deselectAll', this.deselectAll);
this.listenTo(this.collection, 'reset', this.render);
/*
this.events = {};
this.events.submit = 'addFromStr';
this.delegateEvents();
*/
},

/**
Expand Down
9 changes: 5 additions & 4 deletions src/domain_abstract/model/TypeableCollection.js
Expand Up @@ -2,6 +2,7 @@ const Model = Backbone.Model;
const View = Backbone.View;

export default {
types: [],

initialize(models, opts) {
this.model = (attrs = {}, options = {}) => {
Expand Down Expand Up @@ -68,7 +69,7 @@ export default {
* @return {Array}
*/
getTypes() {
return [];
return this.types;
},

/**
Expand Down Expand Up @@ -104,9 +105,9 @@ export default {
const type = this.getType(id);
const ModelInst = type ? type.model : Model;
const ViewInst = type ? type.view : View;
let {model, view, isType} = definition;
model = model instanceof Model ? model : ModelInst.extend(model);
view = view instanceof View ? view : ViewInst.extend(view);
let {model, view, isType} = definition;;
model = model instanceof Model ? model : ModelInst.extend(model || {});
view = view instanceof View ? view : ViewInst.extend(view || {});

if (type) {
type.model = model;
Expand Down

0 comments on commit 5f9ba62

Please sign in to comment.