Updated collection tests and added comments

This commit is contained in:
Omid K. Rad
2014-07-16 18:32:07 -07:00
parent 06392eab94
commit d205eb8726

View File

@@ -113,9 +113,12 @@ class EmployeeCollection extends Backbone.Collection<Employee> {
class Book extends Backbone.Model {
title: string;
author: string;
published: boolean;
}
class Library extends Backbone.Collection<Book> {
// This model definition is here only to test type compatibility of the model, but it
// is not necessary in working code as it is automatically inferred through generics.
model: typeof Book;
}
@@ -123,31 +126,26 @@ class Books extends Backbone.Collection<Book> { }
function test_collection() {
var books = new Library();
var books = new Books();
books.each(book => {
book.get("title");
});
var book1: Book = new Book({ title: "Title 1", author: "Mike" });
books.add(book1);
var titles = books.map(book => {
return book.get("title");
});
var publishedBooks = books.filter(book => {
return book.get("published") === true;
});
var alphabetical = books.sortBy((book: Book): number => {
return null;
});
var model: Book = new Book({title: "Test", author: "Mike"});
books.add(model);
var model2: Book = model.collection.first();
if (model !== model2) {
var model: Book = book1.collection.first();
if (model !== book1) {
throw new Error("Error");
}
books.each(book =>
book.get("title"));
var titles = books.map(book =>
book.get("title"));
var publishedBooks = books.filter(book =>
book.get("published") === true);
var alphabetical = books.sortBy((book: Book): number => null);
}
//////////