Files
DefinitelyTyped/backbone-associations/backbone-associations-tests.ts
Masahiro Wakame e2d55cb761 Merge pull request #6401 from Spinarooni/backbone-comparator-issue#6394
Update Backbone collection.comparator definition to accpet string and…
2016-03-27 01:25:32 +09:00

80 lines
2.4 KiB
TypeScript

/// <reference path="../backbone/backbone.d.ts" />
/// <reference path="backbone-associations.d.ts" />
// borrowed from the Backbone.Associations tutorials
// separated out into modules to avoid namespace clashes
namespace Backbone.Associations.Tests {
namespace OneToOne {
class EmployeeWithManager extends Backbone.AssociatedModel {
constructor(options?) {
super(options);
this.relations = [
{
type: Backbone.One, //nature of the relationship
key: 'manager', // attribute of Employee
relatedModel: 'Employee' //AssociatedModel for attribute key
}
];
}
defaults() {
return {
age: 0,
fname: "",
lname: "",
manager: null
};
}
}
}
namespace OneToMany {
class Location extends Backbone.AssociatedModel {
defaults() {
return {
add1: "",
add2: null,
zip: "",
state: ""
};
}
}
class Locations extends Backbone.Collection<Location> {
comparator = (c: Backbone.Model) => {
return c.get("Number");
}
}
class Project extends Backbone.AssociatedModel {
constructor(options?) {
super(options);
this.relations = [
{
type: Backbone.Many, //nature of the relation
key: 'locations', //attribute of Project
collectionType: Locations, //Collection to be used.
relatedModel: Location //Optional
}
];
}
defaults() {
return {
name: "",
number: 0,
locations: []
}
}
}
function reverseAssociationTest() {
var local = new Location({ state: "Hertfordshire" });
var project = new Project({ name: "The Old Pond Project" });
local.set("oddRelationTo", project);
var parents = project.parents;
}
}
}