remove list_view.js ListView is unused
parent
46fa6e39f6
commit
7e72566cba
@ -1,42 +0,0 @@
|
|||||||
/* global Backbone, Whisper, _ */
|
|
||||||
|
|
||||||
// eslint-disable-next-line func-names
|
|
||||||
(function() {
|
|
||||||
'use strict';
|
|
||||||
|
|
||||||
window.Whisper = window.Whisper || {};
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Generic list view that watches a given collection, wraps its members in
|
|
||||||
* a given child view and adds the child view elements to its own element.
|
|
||||||
*/
|
|
||||||
Whisper.ListView = Backbone.View.extend({
|
|
||||||
tagName: 'ul',
|
|
||||||
itemView: Backbone.View,
|
|
||||||
initialize(options) {
|
|
||||||
this.options = options || {};
|
|
||||||
this.listenTo(this.collection, 'add', this.addOne);
|
|
||||||
this.listenTo(this.collection, 'reset', this.addAll);
|
|
||||||
},
|
|
||||||
|
|
||||||
addOne(model) {
|
|
||||||
if (this.itemView) {
|
|
||||||
const options = _.extend({}, this.options.toInclude, { model });
|
|
||||||
// eslint-disable-next-line new-cap
|
|
||||||
const view = new this.itemView(options);
|
|
||||||
this.$el.append(view.render().el);
|
|
||||||
this.$el.trigger('add');
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
addAll() {
|
|
||||||
this.$el.html('');
|
|
||||||
this.collection.each(this.addOne, this);
|
|
||||||
},
|
|
||||||
|
|
||||||
render() {
|
|
||||||
this.addAll();
|
|
||||||
return this;
|
|
||||||
},
|
|
||||||
});
|
|
||||||
})();
|
|
@ -1,23 +0,0 @@
|
|||||||
/* global Backbone, Whisper */
|
|
||||||
|
|
||||||
describe('ListView', () => {
|
|
||||||
let collection;
|
|
||||||
|
|
||||||
beforeEach(() => {
|
|
||||||
collection = new Backbone.Collection();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should add children to the list element as they are added to the collection', () => {
|
|
||||||
const view = new Whisper.ListView({ collection });
|
|
||||||
collection.add('hello');
|
|
||||||
assert.equal(view.$el.children().length, 1);
|
|
||||||
collection.add('world');
|
|
||||||
assert.equal(view.$el.children().length, 2);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should add all the children to the list element on reset', () => {
|
|
||||||
const view = new Whisper.ListView({ collection });
|
|
||||||
collection.reset(['goodbye', 'world']);
|
|
||||||
assert.equal(view.$el.children().length, 2);
|
|
||||||
});
|
|
||||||
});
|
|
Loading…
Reference in New Issue