From 875a9283735bfb91f824c2f29ee7bfe68cd24ddc Mon Sep 17 00:00:00 2001 From: Natan Vivo Date: Sat, 22 Jun 2013 09:49:06 -0300 Subject: [PATCH 1/8] Remove template property from View, its not part of the class. --- backbone/backbone.d.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/backbone/backbone.d.ts b/backbone/backbone.d.ts index 2a4a60819..49b6234ff 100644 --- a/backbone/backbone.d.ts +++ b/backbone/backbone.d.ts @@ -266,7 +266,6 @@ declare module Backbone { $(selector: string): JQuery; model: Model; collection: Collection; - template: (data?: any) => string; make(tagName: string, attrs?, opts?): View; setElement(element: HTMLElement, delegate?: boolean); id: string; From 364bdc1176aeb8747bdd9bd2044d27ba245c51f9 Mon Sep 17 00:00:00 2001 From: Natan Vivo Date: Sat, 22 Jun 2013 09:53:33 -0300 Subject: [PATCH 2/8] Remove unused code. --- backbone/backbone.d.ts | 7 ------- 1 file changed, 7 deletions(-) diff --git a/backbone/backbone.d.ts b/backbone/backbone.d.ts index 49b6234ff..7c5daeb42 100644 --- a/backbone/backbone.d.ts +++ b/backbone/backbone.d.ts @@ -66,12 +66,6 @@ declare module Backbone { reset?: boolean; } - 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; } - class Events { on(eventName: string, callback: (...args:any[]) => void, context?: any): any; off(eventName?: string, callback?: (...args:any[]) => void, context?: any): any; @@ -281,7 +275,6 @@ declare module Backbone { render(): View; remove(): View; make(tagName, attributes?, content?); - //delegateEvents: any; delegateEvents(events?: any): any; undelegateEvents(); } From 08259b232b5e69cf23d0ad64e4801bd95e202ae3 Mon Sep 17 00:00:00 2001 From: Natan Vivo Date: Sat, 22 Jun 2013 10:24:07 -0300 Subject: [PATCH 3/8] Improvements to definition. * Model.urlRoot should be any, as it may be a string or a function. * Added internal methods to Router. * Improved definition of History: - Extends Events - Remove pushState method, it doesn't exist in the source - Added internal methods to definition. --- backbone/backbone.d.ts | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/backbone/backbone.d.ts b/backbone/backbone.d.ts index 7c5daeb42..90684b32d 100644 --- a/backbone/backbone.d.ts +++ b/backbone/backbone.d.ts @@ -86,7 +86,6 @@ declare module Backbone { sync(...arg: any[]): JQueryXHR; } - class Model extends ModelBase { static extend(properties: any, classProperties?: any): any; // do not use, prefer TypeScript's extend functionality @@ -97,7 +96,7 @@ declare module Backbone { id: any; idAttribute: string; validationError: any; - urlRoot(): string; + urlRoot: any; constructor (attributes?: any, options?: any); initialize(attributes?: any); @@ -229,16 +228,31 @@ declare module Backbone { route(route: string, name: string, callback?: (...parameter: any[]) => void); navigate(fragment: string, options?: NavigateOptions); navigate(fragment: string, trigger?: boolean); + + _bindRoutes(): void; + _routeToRegExp(route: string): RegExp; + _extractParameters(route: RegExp, fragment: string): string[]; } var history: History; - class History { + + class History extends Events { + + handlers: any[]; + interval: number; + start(options?: HistoryOptions); - navigate(fragment: string, options: any); - pushSate(); - getFragment(fragment?: string, forcePushState?: boolean): string; + getHash(window?: Window): string; + getFragment(fragment?: string, forcePushState?: boolean): string; + stop(): void; + route(route: string, callback: (...args: any[]) => void ); + checkUrl(e?: any): void; + loadUrl(fragmentOverride: string): boolean; + navigate(fragment: string, options?: any); started: boolean; + + _updateHash(location: Location, fragment: string, replace: bool); } interface ViewOptions { @@ -294,3 +308,4 @@ declare module Backbone { function setDomLibrary(jQueryNew); } + From d6c2d01c5cc77110ec1a095bce3a28b73d0c1162 Mon Sep 17 00:00:00 2001 From: Natan Vivo Date: Sat, 22 Jun 2013 10:54:14 -0300 Subject: [PATCH 4/8] Add internal methods and mixins to Model and Collection. --- backbone/backbone.d.ts | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/backbone/backbone.d.ts b/backbone/backbone.d.ts index 90684b32d..b2a5092cb 100644 --- a/backbone/backbone.d.ts +++ b/backbone/backbone.d.ts @@ -123,6 +123,19 @@ declare module Backbone { save(attributes?: any, options?: ModelSaveOptions); unset(attribute: string, options?: Silenceable); validate(attributes: any, options?: any): any; + + _validate(attrs: any, options: any): boolean; + + // mixins from underscore + + keys(): string[]; + values(): any[]; + pairs(): any[]; + invert(): any; + pick(keys: string[]): any; + pick(...keys: string[]): any; + omit(keys: string[]): any; + omit(...keys: string[]): any; } class Collection extends ModelBase { @@ -158,6 +171,12 @@ declare module Backbone { unshift(model: Model, options?: AddOptions); where(properies: any): Model[]; + _prepareModel(attrs?: any, options?: any): any; + _removeReference(model: Model): void; + _onModelEvent(event: string, model: Model, collection: Collection, options: any): void; + + // mixins from underscore + all(iterator: (element: Model, index: number) => boolean, context?: any): boolean; any(iterator: (element: Model, index: number) => boolean, context?: any): boolean; collect(iterator: (element: Model, index: number, context?: any) => any[], context?: any): any[]; From 38e50c8b104da6a2674f9be9f5c9aaefd7e3ea47 Mon Sep 17 00:00:00 2001 From: Natan Vivo Date: Sat, 22 Jun 2013 11:06:05 -0300 Subject: [PATCH 5/8] Add internal method to View. --- backbone/backbone.d.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/backbone/backbone.d.ts b/backbone/backbone.d.ts index b2a5092cb..c1030dcfc 100644 --- a/backbone/backbone.d.ts +++ b/backbone/backbone.d.ts @@ -310,6 +310,8 @@ declare module Backbone { make(tagName, attributes?, content?); delegateEvents(events?: any): any; undelegateEvents(); + + _ensureElement() : void; } // SYNC From 2167e6f5b0277a2847eafa0eb08a0ac1759fc3d0 Mon Sep 17 00:00:00 2001 From: Natan Vivo Date: Sat, 22 Jun 2013 11:43:21 -0300 Subject: [PATCH 6/8] Fix test, remove duplicated declaration for _ and $. --- backbone/backbone-tests.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/backbone/backbone-tests.ts b/backbone/backbone-tests.ts index 2a2bf3b41..c1292c1c2 100644 --- a/backbone/backbone-tests.ts +++ b/backbone/backbone-tests.ts @@ -1,8 +1,6 @@ /// /// -declare var _, $; - function test_events() { var object = new Backbone.Events(); From 3c72be6a9318ef1e8ec92ab98b2a9707b212819f Mon Sep 17 00:00:00 2001 From: Natan Vivo Date: Sat, 22 Jun 2013 12:39:21 -0300 Subject: [PATCH 7/8] Add missing property View.cid. --- backbone/backbone.d.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/backbone/backbone.d.ts b/backbone/backbone.d.ts index c1030dcfc..79a7be1ab 100644 --- a/backbone/backbone.d.ts +++ b/backbone/backbone.d.ts @@ -296,6 +296,7 @@ declare module Backbone { make(tagName: string, attrs?, opts?): View; setElement(element: HTMLElement, delegate?: boolean); id: string; + cid: string; className: string; tagName: string; events: any; From bcb5914a8686c259dc1720056b4cc5234200ab81 Mon Sep 17 00:00:00 2001 From: Natan Vivo Date: Sat, 22 Jun 2013 12:39:21 -0300 Subject: [PATCH 8/8] Add missing property View.cid. --- backbone/backbone.d.ts | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/backbone/backbone.d.ts b/backbone/backbone.d.ts index 79a7be1ab..cfc3c3d2f 100644 --- a/backbone/backbone.d.ts +++ b/backbone/backbone.d.ts @@ -67,11 +67,11 @@ declare module Backbone { } class Events { - on(eventName: string, callback: (...args:any[]) => void, context?: any): any; - off(eventName?: string, callback?: (...args:any[]) => void, context?: any): any; + 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; + 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; @@ -98,7 +98,7 @@ declare module Backbone { validationError: any; urlRoot: any; - constructor (attributes?: any, options?: any); + constructor(attributes?: any, options?: any); initialize(attributes?: any); fetch(options?: ModelFetchOptions): JQueryXHR; @@ -147,7 +147,7 @@ declare module Backbone { collection: Model; length: number; - constructor (models?: any, options?: any); + constructor(models?: any, options?: any); fetch(options?: CollectionFetchOptions): JQueryXHR; @@ -189,7 +189,7 @@ declare module Backbone { difference(...model: Model[]): Model[]; drop(): Model; drop(n: number): Model[]; - each(iterator: (element: Model, index: number, list?: any) => void, context?: any); + each(iterator: (element: Model, index: number, list?: any) => void , context?: any); every(iterator: (element: Model, index: number) => boolean, context?: any): boolean; filter(iterator: (element: Model, index: number) => boolean, context?: any): Model[]; find(iterator: (element: Model, index: number) => boolean, context?: any): Model; @@ -197,7 +197,7 @@ declare module Backbone { first(n: number): Model[]; flatten(shallow?: boolean): 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); + forEach(iterator: (element: Model, index: number, list?: any) => void , context?: any); include(value: any): boolean; indexOf(element: Model, isSorted?: boolean): number; initial(): Model; @@ -242,9 +242,9 @@ declare module Backbone { routes: any; - constructor (options?: RouterOptions); - initialize (options?: RouterOptions); - route(route: string, name: string, callback?: (...parameter: any[]) => void); + constructor(options?: RouterOptions); + initialize(options?: RouterOptions); + route(route: string, name: string, callback?: (...parameter: any[]) => void ); navigate(fragment: string, options?: NavigateOptions); navigate(fragment: string, trigger?: boolean); @@ -288,7 +288,7 @@ declare module Backbone { static extend(properties: any, classProperties?: any): any; // do not use, prefer TypeScript's extend functionality - constructor (options?: ViewOptions); + constructor(options?: ViewOptions); $(selector: string): JQuery; model: Model; @@ -296,7 +296,7 @@ declare module Backbone { make(tagName: string, attrs?, opts?): View; setElement(element: HTMLElement, delegate?: boolean); id: string; - cid: string; + cid: string; className: string; tagName: string; events: any; @@ -312,19 +312,19 @@ declare module Backbone { delegateEvents(events?: any): any; undelegateEvents(); - _ensureElement() : void; + _ensureElement(): void; } // SYNC function sync(method, model, options?: JQueryAjaxSettings); - var emulateHTTP: boolean; - var emulateJSONBackbone: boolean; + var emulateHTTP: boolean; + var emulateJSONBackbone: boolean; // Utility // 0.9 cannot return modules anymore, and "typeof " is not compiling for some reason // returning "any" until this is fixed - + //function noConflict(): typeof Backbone; function noConflict(): any;