Browse Source

Move DomainViews to TS

ts-components
Artur Arseniev 4 years ago
parent
commit
fb03589fa3
  1. 29
      src/domain_abstract/view/DomainViews.ts

29
src/domain_abstract/view/DomainViews.js → src/domain_abstract/view/DomainViews.ts

@ -1,7 +1,12 @@
import { includes } from 'underscore'; import { includes } from 'underscore';
import Backbone from 'backbone'; import { ObjectAny, View } from '../../common';
export default class DomainViews extends View {
config?: any;
items: any[];
ns?: string;
itemView?: any;
export default class DomainViews extends Backbone.View {
// Defines the View per type // Defines the View per type
itemsView = ''; itemsView = '';
@ -9,7 +14,7 @@ export default class DomainViews extends Backbone.View {
reuseView = false; reuseView = false;
constructor(opts = {}, config, autoAdd = false) { constructor(opts: any = {}, config?: any, autoAdd = false) {
super(opts); super(opts);
this.config = config || opts.config || {}; this.config = config || opts.config || {};
autoAdd && this.listenTo(this.collection, 'add', this.addTo); autoAdd && this.listenTo(this.collection, 'add', this.addTo);
@ -21,11 +26,11 @@ export default class DomainViews extends Backbone.View {
* @param {Model} model * @param {Model} model
* @private * @private
* */ * */
addTo(model) { addTo(model: any) {
this.add(model); this.add(model);
} }
itemViewNotFound(type) { itemViewNotFound(type: string) {
const { config, ns } = this; const { config, ns } = this;
const { em } = config; const { em } = config;
const warn = `${ns ? `[${ns}]: ` : ''}'${type}' type not found`; const warn = `${ns ? `[${ns}]: ` : ''}'${type}' type not found`;
@ -38,8 +43,9 @@ export default class DomainViews extends Backbone.View {
* @param {Object} fragment Fragment collection * @param {Object} fragment Fragment collection
* @private * @private
* */ * */
add(model, fragment) { add(model: any, fragment?: DocumentFragment) {
const { config, reuseView, items, itemsView = {} } = this; const { config, reuseView, items } = this;
const itemsView = (this.itemsView || {}) as ObjectAny;
const inputTypes = [ const inputTypes = [
'button', 'button',
'checkbox', 'checkbox',
@ -95,6 +101,7 @@ export default class DomainViews extends Backbone.View {
if (this.collection.length) if (this.collection.length)
this.collection.each(function (model) { this.collection.each(function (model) {
// @ts-ignore
this.add(model, frag); this.add(model, frag);
}, this); }, this);
@ -104,16 +111,16 @@ export default class DomainViews extends Backbone.View {
} }
onRender() {} onRender() {}
onRemoveBefore(items?: any, opts?: any) {}
onRemoveBefore() {} onRemove(items?: any, opts?: any) {}
onRemove() {}
remove(opts = {}) { remove(opts = {}) {
const { items } = this; const { items } = this;
this.onRemoveBefore(items, opts); this.onRemoveBefore(items, opts);
this.clearItems(); this.clearItems();
Backbone.View.prototype.remove.apply(this, arguments); super.remove();
this.onRemove(items, opts); this.onRemove(items, opts);
return this;
} }
clearItems() { clearItems() {
Loading…
Cancel
Save