mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-06-28 14:20:12 +00:00
Updated collection tests and added comments
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
//////////
|
||||
|
||||
Reference in New Issue
Block a user