|
|
|
@ -1,13 +1,13 @@ |
|
|
|
import { includes } from 'underscore'; |
|
|
|
import Backbone from 'backbone'; |
|
|
|
import View from './View'; |
|
|
|
import Collection from './Collection'; |
|
|
|
import Model from './Model'; |
|
|
|
/*interface DomainView<TView, TModel>{ |
|
|
|
constructor(model: TModel): TView |
|
|
|
}*/ |
|
|
|
type TModel<TCollection> = TCollection extends Backbone.Collection<infer TModel>? TModel: Model; |
|
|
|
|
|
|
|
export default abstract class DomainViews<TCollection extends Backbone.Collection<Model>, TItemView extends View> extends View<TModel<TCollection>> { |
|
|
|
export default abstract class DomainViews< |
|
|
|
TCollection extends Collection, |
|
|
|
TItemView extends View |
|
|
|
> extends View<TCollection> { |
|
|
|
// Defines the View per type
|
|
|
|
itemsView = ''; |
|
|
|
|
|
|
|
@ -26,7 +26,7 @@ export default abstract class DomainViews<TCollection extends Backbone.Collectio |
|
|
|
* @param {Model} model |
|
|
|
* @private |
|
|
|
* */ |
|
|
|
private addTo(model: TModel<TCollection>) { |
|
|
|
private addTo(model: Model) { |
|
|
|
this.add(model); |
|
|
|
} |
|
|
|
|
|
|
|
@ -35,7 +35,7 @@ export default abstract class DomainViews<TCollection extends Backbone.Collectio |
|
|
|
const warn = `${ns ? `[${ns}]: ` : ''}'${type}' type not found`; |
|
|
|
em?.logWarning(warn);*/ |
|
|
|
} |
|
|
|
protected abstract renderView(model: TModel<TCollection>, itemType: string): TItemView; |
|
|
|
protected abstract renderView(model: Model, itemType: string): TItemView; |
|
|
|
|
|
|
|
/** |
|
|
|
* Render new model inside the view |
|
|
|
@ -43,7 +43,7 @@ export default abstract class DomainViews<TCollection extends Backbone.Collectio |
|
|
|
* @param {Object} fragment Fragment collection |
|
|
|
* @private |
|
|
|
* */ |
|
|
|
private add(model: TModel<TCollection>, fragment?: DocumentFragment) { |
|
|
|
private add(model: Model, fragment?: DocumentFragment) { |
|
|
|
const { reuseView, viewCollection, itemsView = {} } = this; |
|
|
|
var frag = fragment || null; |
|
|
|
var typeField = model.get(this.itemType); |
|
|
|
@ -69,10 +69,7 @@ export default abstract class DomainViews<TCollection extends Backbone.Collectio |
|
|
|
this.clearItems(); |
|
|
|
this.$el.empty(); |
|
|
|
|
|
|
|
if (this.collection.length) |
|
|
|
this.collection.each((model) => { |
|
|
|
this.add(model, frag); |
|
|
|
}, this); |
|
|
|
if (this.collection.length) this.collection.each(model => this.add(model, frag)); |
|
|
|
|
|
|
|
this.$el.append(frag); |
|
|
|
this.onRender(); |
|
|
|
|