From 8e188ed9f200d3a4bd0b7dfdea8b90f0edbb75ab Mon Sep 17 00:00:00 2001 From: Joel Mueller Date: Sat, 24 Jan 2015 10:44:04 -0600 Subject: [PATCH 1/5] Improvements to m.prop, m.redraw.strategy. Makes m.prop() generic for better type inference, allows access to m.redraw.strategy, which was previously impossible. --- mithril/mithril.d.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/mithril/mithril.d.ts b/mithril/mithril.d.ts index 39c9539f8..faee830c8 100644 --- a/mithril/mithril.d.ts +++ b/mithril/mithril.d.ts @@ -8,13 +8,13 @@ interface MithrilStatic { (selector: string, attributes: Object, children?: any): MithrilVirtualElement; (selector: string, children?: any): MithrilVirtualElement; - prop(value?: any): (value?: any) => any; + prop(value?: T): (value?: T) => T; withAttr(property: string, callback: (value: any) => void): (e: Event) => any; module(rootElement: Node, module: MithrilModule): void; trust(html: string): String; render(rootElement: Element, children?: any): void; render(rootElement: HTMLDocument, children?: any): void; - redraw(): void; + redraw: MithrilRedraw; route(rootElement: Element, defaultRoute: string, routes: { [key: string]: MithrilModule }): void; route(rootElement: HTMLDocument, defaultRoute: string, routes: { [key: string]: MithrilModule }): void; route(path: string, params?: any, shouldReplaceHistory?: boolean): void; @@ -27,6 +27,11 @@ interface MithrilStatic { endComputation(): void; } +interface MithrilRedraw { + (): void; + strategy: (value?: string) => string; +} + interface MithrilVirtualElement { tag: string; attrs: Object; From ef95fea38b7bae256d81bd3054cab1781ab8ee2f Mon Sep 17 00:00:00 2001 From: Joel Mueller Date: Sat, 24 Jan 2015 10:46:52 -0600 Subject: [PATCH 2/5] Fixing indentation to be consistent. --- mithril/mithril.d.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/mithril/mithril.d.ts b/mithril/mithril.d.ts index faee830c8..d106025ba 100644 --- a/mithril/mithril.d.ts +++ b/mithril/mithril.d.ts @@ -8,13 +8,13 @@ interface MithrilStatic { (selector: string, attributes: Object, children?: any): MithrilVirtualElement; (selector: string, children?: any): MithrilVirtualElement; - prop(value?: T): (value?: T) => T; + prop(value?: T): (value?: T) => T; withAttr(property: string, callback: (value: any) => void): (e: Event) => any; module(rootElement: Node, module: MithrilModule): void; trust(html: string): String; render(rootElement: Element, children?: any): void; render(rootElement: HTMLDocument, children?: any): void; - redraw: MithrilRedraw; + redraw: MithrilRedraw; route(rootElement: Element, defaultRoute: string, routes: { [key: string]: MithrilModule }): void; route(rootElement: HTMLDocument, defaultRoute: string, routes: { [key: string]: MithrilModule }): void; route(path: string, params?: any, shouldReplaceHistory?: boolean): void; @@ -28,8 +28,8 @@ interface MithrilStatic { } interface MithrilRedraw { - (): void; - strategy: (value?: string) => string; + (): void; + strategy: (value?: string) => string; } interface MithrilVirtualElement { From e4b22c838ce69c66e650d36a3132c9639dbf58aa Mon Sep 17 00:00:00 2001 From: Joel Mueller Date: Sat, 24 Jan 2015 18:17:38 -0600 Subject: [PATCH 3/5] Added generics to promise/defer. Allowing for better type-safety. --- mithril/mithril.d.ts | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/mithril/mithril.d.ts b/mithril/mithril.d.ts index d106025ba..525ded3aa 100644 --- a/mithril/mithril.d.ts +++ b/mithril/mithril.d.ts @@ -20,9 +20,9 @@ interface MithrilStatic { route(path: string, params?: any, shouldReplaceHistory?: boolean): void; route(): string; route(element: Element, isInitialized: boolean): void; - request(options: MithrilXHROptions): MithrilPromise; - deferred(): MithrilDeferred; - sync(promises: MithrilPromise[]): MithrilPromise; + request(options: MithrilXHROptions): MithrilPromise; + deferred(): MithrilDeferred; + sync(promises: MithrilPromise[]): MithrilPromise; startComputation(): void; endComputation(): void; } @@ -43,15 +43,15 @@ interface MithrilModule { view: Function; } -interface MithrilDeferred { - resolve(value?: any): void; - reject(value?: any): void; - promise: MithrilPromise; +interface MithrilDeferred { + resolve(value?: T): void; + reject(value?: any): void; + promise: MithrilPromise; } -interface MithrilPromise { - (value?: any): any; - then(successCallback?: (value: any) => any, errorCallback?: (value: any) => any): MithrilPromise; +interface MithrilPromise { + (value?: T): T; + then(successCallback?: (value: T) => R, errorCallback?: (value: any) => any): MithrilPromise; } interface MithrilXHROptions { From 73cb5747b334121222595f20563d98beb47aa2e8 Mon Sep 17 00:00:00 2001 From: Joel Mueller Date: Sat, 24 Jan 2015 18:19:17 -0600 Subject: [PATCH 4/5] Better typing for MithrilModule Reflects that the view function can accept a controller and is required to return a MithrilVirtualElement. --- mithril/mithril.d.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mithril/mithril.d.ts b/mithril/mithril.d.ts index 525ded3aa..3b9690080 100644 --- a/mithril/mithril.d.ts +++ b/mithril/mithril.d.ts @@ -39,8 +39,8 @@ interface MithrilVirtualElement { } interface MithrilModule { - controller: Function; - view: Function; + controller: Function; + view: (controller?: any) => MithrilVirtualElement; } interface MithrilDeferred { From 3429cb03da79795d57d2884b143659dfaa8524d8 Mon Sep 17 00:00:00 2001 From: Joel Mueller Date: Mon, 26 Jan 2015 22:59:00 -0600 Subject: [PATCH 5/5] Adding requested review changes. --- mithril/mithril.d.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/mithril/mithril.d.ts b/mithril/mithril.d.ts index 3b9690080..e01dbcc02 100644 --- a/mithril/mithril.d.ts +++ b/mithril/mithril.d.ts @@ -8,7 +8,8 @@ interface MithrilStatic { (selector: string, attributes: Object, children?: any): MithrilVirtualElement; (selector: string, children?: any): MithrilVirtualElement; - prop(value?: T): (value?: T) => T; + prop(value?: T): (value?: T) => T; + prop(promise: MithrilPromise): MithrilPromiseProperty; withAttr(property: string, callback: (value: any) => void): (e: Event) => any; module(rootElement: Node, module: MithrilModule): void; trust(html: string): String; @@ -52,6 +53,13 @@ interface MithrilDeferred { interface MithrilPromise { (value?: T): T; then(successCallback?: (value: T) => R, errorCallback?: (value: any) => any): MithrilPromise; + then(successCallback?: (value: T) => MithrilPromise, errorCallback?: (value: any) => any): MithrilPromise; +} + +interface MithrilPromiseProperty extends MithrilPromise { + (): T; + (value: T): T; + toJSON(): T; } interface MithrilXHROptions {