Move definitions and test in separate folders

This enables each definition to have a readme if necessary.
Also a .json metadata file to help with package managers.
And last, to have different versions of the definitions.
This commit is contained in:
Boris Yankov
2012-11-18 22:28:44 +02:00
parent b2e85b459f
commit c91c45f9ae
92 changed files with 1354 additions and 1354 deletions
+246
View File
@@ -0,0 +1,246 @@
// Type definitions for Backbone 0.9
// Project: http://backbonejs.org/
// Definitions by: Boris Yankov <https://github.com/borisyankov/>
// Definitions: https://github.com/borisyankov/DefinitelyTyped
/// <reference path="jquery-1.8.d.ts" />
declare module Backbone {
export interface AddOptions extends Silenceable {
at: number;
}
export interface CreateOptions extends Silenceable {
wait: bool;
}
export interface HistoryOptions extends Silenceable {
pushState: bool;
root: string;
}
export interface NavigateOptions {
trigger: bool;
}
export interface RouterOptions {
routes: any;
}
export interface Silenceable {
silent: bool;
}
interface on { (eventName: string, callback: (...args: any[]) => void, context?: any): any; }
interface off { (eventName?: string, callback?: (...args: any[]) => void, context?: any): any; }
interface trigger { (eventName: string, ...args: any[]): any; }
interface bind { (eventName: string, callback: (...args: any[]) => void, context?: any): any; }
interface unbind { (eventName?: string, callback?: (...args: any[]) => void, context?: any): any; }
declare class Events {
on(eventName: string, callback: (...args:any[]) => void, context?: any): any;
off(eventName?: string, callback?: (...args:any[]) => void, context?: any): any;
trigger(eventName: string, ...args: any[]): any;
bind(eventName: string, callback: (...args:any[]) => void, context?: any): any;
unbind(eventName?: string, callback?: (...args:any[]) => void, context?: any): any;
}
export class ModelBase extends Events {
fetch(options?: JQueryAjaxSettings);
url(): string;
parse(response);
toJSON(): any;
}
export class Model extends ModelBase {
static extend(properties: any, classProperties?: any): any; // do not use, prefer TypeScript's extend functionality
attributes: any;
changed: any[];
cid: string;
id: any;
idAttribute: string;
urlRoot() : string;
constructor (attributes?: any, options?: any);
initialize(attributes?: any);
get(attributeName: string): any;
set(attributeName: string, value: any);
set(obj: any);
change();
changedAttributes(attributes?: any): any[];
clear(options?: Silenceable);
clone(): Model;
defaults(): any;
destroy(options?: JQueryAjaxSettings);
escape(attribute: string);
has(attribute: string): bool;
hasChanged(attribute?: string): bool;
isNew(): bool;
isValid(): string;
previous(attribute: string): any;
previousAttributes(): any[];
save(attributes?: any, options?: JQueryAjaxSettings);
unset(attribute: string, options?: Silenceable);
validate(attributes: any): any;
}
export class Collection extends ModelBase {
static extend(properties: any, classProperties?: any): any; // do not use, prefer TypeScript's extend functionality
model: Model;
models: any;
collection: Model;
length: number;
constructor (models?: any, options?: any);
comparator(element: Model): number;
comparator(element: Model): string;
comparator(compare: Model, to?: Model): number;
add(model: Model, options?: AddOptions);
add(models: Model[], options?: AddOptions);
at(index: number): Model;
get(id: any): Model;
getByCid(cid): Model;
create(attributes: any, options?: CreateOptions): Model;
pluck(attribute: string): any[];
push(model: Model, options?: AddOptions);
pop(options?: Silenceable);
remove(model: Model, options?: Silenceable);
remove(models: Model[], options?: Silenceable);
reset(models?: Model[], options?: Silenceable);
shift(options?: Silenceable);
sort(options?: Silenceable);
unshift(model: Model, options?: AddOptions);
where(properies: any): Model[];
all(iterator: (element: Model, index: number) => bool, context?: any): bool;
any(iterator: (element: Model, index: number) => bool, context?: any): bool;
collect(iterator: (element: Model, index: number, context?: any) => any[], context?: any): any[];
compact(): Model[];
contains(value: any): bool;
countBy(iterator: (element: Model, index: number) => any): any[];
countBy(attribute: string): any[];
detect(iterator: (item: any) => bool, context?: any): any; // ???
difference(...model: Model[]): Model[];
drop(): Model;
drop(n: number): Model[];
each(iterator: (element: Model, index: number, list?: any) => void, context?: any);
every(iterator: (element: Model, index: number) => bool, context?: any): bool;
filter(iterator: (element: Model, index: number) => bool, context?: any): Model[];
find(iterator: (element: Model, index: number) => bool, context?: any): Model;
first(): Model;
first(n: number): Model[];
flatten(shallow?: bool): Model[];
foldl(iterator: (memo: any, element: Model, index: number) => any, initialMemo: any, context?: any): any;
forEach(iterator: (element: Model, index: number, list?: any) => void, context?: any);
include(value: any): bool;
indexOf(element: Model, isSorted?: bool): number;
initial(): Model;
initial(n: number): Model[];
inject(iterator: (memo: any, element: Model, index: number) => any, initialMemo: any, context?: any): any;
intersection(...model: Model[]): Model[];
isEmpty(object: any): bool;
invoke(methodName: string, arguments?: any[]);
last(): Model;
last(n: number): Model[];
lastIndexOf(element: Model, fromIndex?: number): number;
map(iterator: (element: Model, index: number, context?: any) => any[], context?: any): any[];
max(iterator?: (element: Model, index: number) => any, context?: any): Model;
min(iterator?: (element: Model, index: number) => any, context?: any): Model;
object(...values: any[]): any[];
reduce(iterator: (memo: any, element: Model, index: number) => any, initialMemo: any, context?: any): any;
select(iterator: any, context?: any): any[];
size(): number;
shuffle(): any[];
some(iterator: (element: Model, index: number) => bool, context?: any): bool;
sortBy(iterator: (element: Model, index: number) => number, context?: any): Model[];
sortBy(attribute: string, context?: any): Model[];
sortedIndex(element: Model, iterator?: (element: Model, index: number) => number): number;
range(stop: number, step?: number);
range(start: number, stop: number, step?: number);
reduceRight(iterator: (memo: any, element: Model, index: number) => any, initialMemo: any, context?: any): any[];
reject(iterator: (element: Model, index: number) => bool, context?: any): Model[];
rest(): Model;
rest(n: number): Model[];
tail(): Model;
tail(n: number): Model[];
toArray(): any[];
union(...model: Model[]): Model[];
uniq(isSorted?: bool, iterator?: (element: Model, index: number) => bool): Model[];
without(...values: any[]): Model[];
zip(...model: Model[]): Model[];
}
export class Router {
static extend(properties: any, classProperties?: any): any; // do not use, prefer TypeScript's extend functionality
routes: any;
constructor (options?: RouterOptions);
initialize (options?: RouterOptions);
route(route: string, name: string, callback?: (...parameter: any[]) => void);
navigate(fragment: string, options?: NavigateOptions);
}
export var history: History;
export class History {
start(options?: HistoryOptions);
navigate(fragment: string, options: any);
pushSate();
}
export interface ViewOptions {
model?: Backbone.Model;
collection?: Backbone.Collection;
el?: Element;
id?: string;
className?: string;
tagName?: string;
attributes?: any[];
}
export class View extends Events {
static extend(properties: any, classProperties?: any): any; // do not use, prefer TypeScript's extend functionality
constructor (options?: ViewOptions);
$(selector: string): any;
model: Model;
make(tagName: string, attrs?, opts?): View;
setElement(element: HTMLElement, delegate?: bool);
tagName: string;
events: any;
el: HTMLElement;
$el;
setElement(element);
attributes;
$(selector);
render();
remove();
make(tagName, attributes?, content?);
//delegateEvents: any;
delegateEvents(events?: any): any;
undelegateEvents();
}
// SYNC
function sync(method, model, options?: JQueryAjaxSettings);
var emulateHTTP: bool;
var emulateJSONBackbone: bool;
// Utility
function noConflict(): Backbone;
function setDomLibrary(jQueryNew);
}
+113
View File
@@ -0,0 +1,113 @@
/// <reference path="../Definitions/backbone-0.9.d.ts" />
declare var _, $;
function test_events() {
var object = new Backbone.Events();
object.on("alert", (msg) => alert("Triggered " + msg));
object.trigger("alert", "an event");
var onChange = () => alert('whatever');
var context: any;
object.off("change", onChange);
object.off("change");
object.off(null, onChange);
object.off(null, null, context);
object.off();
}
function test_models() {
var Sidebar = Backbone.Model.extend({
promptColor: function () {
var cssColor = prompt("Please enter a CSS color:");
this.set({ color: cssColor });
}
});
var sidebar = new Sidebar();
sidebar.on('change:color', (model, color) => $('#sidebar').css({ background: color }));
sidebar.set({ color: 'white' });
sidebar.promptColor();
////////
var Note = Backbone.Model.extend({
initialize: () => { },
author: () => { },
coordinates: () => { },
allowedToEdit: (account) => {
return true;
}
});
var PrivateNote = Note.extend({
allowedToEdit: function (account) {
return account.owns(this);
}
});
//////////
var note = Backbone.Model.extend({
set: function (attributes, options) {
Backbone.Model.prototype.set.call(this, attributes, options);
}
});
note.get("title")
note.set({ title: "March 20", content: "In his eyes she eclipses..." });
note.set("title", "A Scandal in Bohemia");
}
class Employee extends Backbone.Model {
reports: EmployeeCollection;
constructor (options? ) {
super(options);
this.reports = new EmployeeCollection();
this.reports.url = '../api/employees/' + this.id + '/reports';
}
more() {
this.reports.reset();
}
}
class EmployeeCollection extends Backbone.Collection {
url: string = "../api/employees";
findByName(key) { }
}
function test_collection() {
var Book: Backbone.Model;
var Library = Backbone.Collection.extend({
model: Book
});
var Books: Backbone.Collection;
Books.each(function (book) {
});
var titles = Books.map(function (book) {
return book.get("title");
});
var publishedBooks = Books.filter(function (book) {
return book.get("published") === true;
});
var alphabetical = Books.sortBy(function (book) {
});
}
//////////
Backbone.history.start();