Updated the signatures and included some of the recent changes of Backbone.js v1.0.0

This commit is contained in:
Kazi Manzur Rashid
2013-04-19 05:20:09 +06:00
parent aa28425843
commit 2a9a991418
+68 -22
View File
@@ -12,10 +12,6 @@ declare module Backbone {
at: number;
}
export interface CreateOptions extends Silenceable {
wait: bool;
}
export interface HistoryOptions extends Silenceable {
pushState?: bool;
root?: string;
@@ -33,27 +29,69 @@ declare module Backbone {
silent?: bool;
}
interface Validable {
validate?: bool;
}
interface Waitable {
wait?: bool;
}
interface Parseable {
parse?: any;
}
export interface PersistenceOptions {
url?: string;
beforeSend?: (jqxhr: JQueryXHR) => void;
success?: (modelOrCollection?: any, response?: any, options?: any) => void;
error?: (modelOrCollection: any, jqxhr: JQueryXHR, options?: any) => void;
}
export interface ModelSetOptions extends Silenceable extends Validable {
}
export interface ModelFetchOptions extends PersistenceOptions extends ModelSetOptions extends Parseable {
}
export interface ModelSaveOptions extends Silenceable extends Waitable extends Validable extends Parseable extends PersistenceOptions {
patch?: bool;
}
export interface ModelDestroyOptions extends Waitable extends PersistenceOptions {
}
export interface CollectionFetchOptions extends PersistenceOptions extends Parseable {
reset?: 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;
once(events: string, callback: (...args: any[]) => void , context?: any): any;
listenTo(object: any, events: string, callback: (...args: any[]) => void ): any;
listenToOnce(object: any, events: string, callback: (...args: any[]) => void ): any;
stopListening(object: any, events?: string, callback?: (...args: any[]) => void ): any;
}
export class ModelBase extends Events {
fetch(options?: JQueryAjaxSettings);
url: any;
parse(response);
toJSON(): any;
parse(response, options?: any);
toJSON(options?: any): any;
sync(...arg: any[]): JQueryXHR;
}
export class Model extends ModelBase {
static extend(properties: any, classProperties?: any): any; // do not use, prefer TypeScript's extend functionality
@@ -63,21 +101,24 @@ declare module Backbone {
cid: string;
id: any;
idAttribute: string;
urlRoot() : string;
validationError: any;
urlRoot(): string;
constructor (attributes?: any, options?: any);
initialize(attributes?: any);
fetch(options?: ModelFetchOptions): JQueryXHR;
get(attributeName: string): any;
set(attributeName: string, value: any, options?: Silenceable);
set(obj: any, options?: Silenceable);
set(attributeName: string, value: any, options?: ModelSetOptions);
set(obj: any, options?: ModelSetOptions);
change();
changedAttributes(attributes?: any): any[];
clear(options?: Silenceable);
clone(): Model;
defaults(): any;
destroy(options?: JQueryAjaxSettings);
destroy(options?: ModelDestroyOptions);
escape(attribute: string);
has(attribute: string): bool;
hasChanged(attribute?: string): bool;
@@ -85,9 +126,9 @@ declare module Backbone {
isValid(): string;
previous(attribute: string): any;
previousAttributes(): any[];
save(attributes?: any, options?: JQueryAjaxSettings);
save(attributes?: any, options?: ModelSaveOptions);
unset(attribute: string, options?: Silenceable);
validate(attributes: any): any;
validate(attributes: any, options?: any): any;
}
export class Collection extends ModelBase {
@@ -101,6 +142,8 @@ declare module Backbone {
constructor (models?: any, options?: any);
fetch(options?: CollectionFetchOptions): JQueryXHR;
comparator(element: Model): number;
comparator(element: Model): string;
comparator(compare: Model, to?: Model): number;
@@ -109,7 +152,7 @@ declare module Backbone {
add(models: Model[], options?: AddOptions);
at(index: number): Model;
get(id: any): Model;
create(attributes: any, options?: CreateOptions): Model;
create(attributes: any, options?: ModelSaveOptions): Model;
pluck(attribute: string): any[];
push(model: Model, options?: AddOptions);
pop(options?: Silenceable);
@@ -124,6 +167,7 @@ declare module Backbone {
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[];
chain(): any;
compact(): Model[];
contains(value: any): bool;
countBy(iterator: (element: Model, index: number) => any): any[];
@@ -189,6 +233,7 @@ declare module Backbone {
initialize (options?: RouterOptions);
route(route: string, name: string, callback?: (...parameter: any[]) => void);
navigate(fragment: string, options?: NavigateOptions);
navigate(fragment: string, trigger?: bool);
}
export var history: History;
@@ -204,7 +249,7 @@ declare module Backbone {
export interface ViewOptions {
model?: Backbone.Model;
collection?: Backbone.Collection;
el?: Element;
el?: any;
id?: string;
className?: string;
tagName?: string;
@@ -217,20 +262,21 @@ declare module Backbone {
constructor (options?: ViewOptions);
$(selector: string): any;
$(selector: string): JQuery;
model: Model;
collection: Collection;
make(tagName: string, attrs?, opts?): View;
setElement(element: HTMLElement, delegate?: bool);
tagName: string;
events: any;
el: HTMLElement;
$el;
el: any;
$el: JQuery;
setElement(element);
attributes;
$(selector);
render();
remove();
$(selector): JQuery;
render(): View;
remove(): View;
make(tagName, attributes?, content?);
//delegateEvents: any;
delegateEvents(events?: any): any;