From 1d55f70e34b851d9bd2c9a855fb923e64db70ffb Mon Sep 17 00:00:00 2001 From: Anand Prakash Date: Sun, 27 Apr 2014 17:29:43 -0700 Subject: [PATCH 1/5] Fixed local, roaming and temp definitions on WinJS.Application object. These should be instances on IOHelper as defined in WinJS. --- winjs/winjs.d.ts | 161 +++++++++++++++-------------------------------- 1 file changed, 49 insertions(+), 112 deletions(-) diff --git a/winjs/winjs.d.ts b/winjs/winjs.d.ts index 20263a3bb9..d14238eeeb 100644 --- a/winjs/winjs.d.ts +++ b/winjs/winjs.d.ts @@ -25,7 +25,49 @@ and limitations under the License. **/ interface Element { winControl: any; // TODO: This should be control? -}/** +} + +/** + * Utility class for easy access to operations on application folders +**/ +interface IOHelper { + /** + * Instance of the currently wrapped application folder + **/ + folder: Windows.Storage.StorageFolder; + + /** + * Determines whether the specified file exists in the folder. + * @param filename The name of the file. + * @returns A promise that completes with a value of either true (if the file exists) or false. + **/ + exists(filename: string): WinJS.Promise; + + /** + * Reads the specified file. If the file doesn't exist, the specified default value is returned. + * @param fileName The file to read from. + * @param def The default value to be returned if the file failed to open. + * @returns A promise that completes with a value that is either the contents of the file, or the specified default value. + **/ + readText(fileName: string, def?: string): WinJS.Promise; + + /** + * Deletes a file from the folder. + * @param fileName The file to be deleted. + * @returns A promise that is fulfilled when the file has been deleted. + **/ + remove(fileName: string): WinJS.Promise; + + /** + * Writes the specified text to the specified file. + * @param fileName The name of the file. + * @param text The content to be written to the file. + * @returns A promise that completes with a value that is the number of characters written. + **/ + writeText(fileName: string, text: string): WinJS.Promise; +} + +/** * Provides application-level functionality, for example activation, storage, and application events. **/ declare module WinJS.Application { @@ -34,128 +76,23 @@ declare module WinJS.Application { /** * The local storage of the application. **/ - var local: { - //#region Methods - - /** - * Determines whether the specified file exists in the folder. - * @param filename The name of the file. - * @returns A promise that completes with a value of either true (if the file exists) or false. - **/ - exists(filename: string): Promise; - - /** - * Reads the specified file. If the file doesn't exist, the specified default value is returned. - * @param fileName The file to read from. - * @param def The default value to be returned if the file failed to open. - * @returns A promise that completes with a value that is either the contents of the file, or the specified default value. - **/ - readText(fileName: string, def?: string): Promise; - - /** - * Deletes a file from the folder. - * @param fileName The file to be deleted. - * @returns A promise that is fulfilled when the file has been deleted. - **/ - remove(fileName: string): Promise; - - /** - * Writes the specified text to the specified file. - * @param fileName The name of the file. - * @param text The content to be written to the file. - * @returns A promise that completes with a value that is the number of characters written. - **/ - writeText(fileName: string, text: string): Promise; - - //#endregion Methods - - }; + var local: IOHelper; /** * The roaming storage of the application. **/ - var roaming: { - //#region Methods + var roaming: IOHelper; - /** - * Determines whether the specified file exists in the folder. - * @param filename The name of the file. - * @returns A promise that completes with a value of either true (if the file exists) or false. - **/ - exists(filename: string): Promise; - - /** - * Reads the specified file. If the file doesn't exist, the specified default value is returned. - * @param fileName The file to read from. - * @param def The default value to be returned if the file failed to open. - * @returns A promise that completes with a value that is either the contents of the file, or the specified default value. - **/ - readText(fileName: string, def?: string): Promise; - - /** - * Deletes a file from the folder. - * @param fileName The file to be deleted. - * @returns A promise that is fulfilled when the file has been deleted. - **/ - remove(fileName: string): Promise; - - /** - * Writes the specified text to the specified file. - * @param fileName The name of the file. - * @param text The content to be written to the file. - * @returns A promise that completes with a value that is the number of characters written. - **/ - writeText(fileName: string, text: string): Promise; - - //#endregion Methods - - }; + /** + * The temp storage of the application. + **/ + var temp: IOHelper; /** * An object used for storing app information that can be used to restore the app's state after it has been suspended and then resumed. Data that can usefully be contained in this object includes the current navigation page or any information the user has added to the input controls on the page. You should not add information about customization (for example colors) or user-defined lists of content. **/ var sessionState: any; - /** - * The temp storage of the application. - **/ - var temp: { - //#region Methods - - /** - * Determines whether the specified file exists in the folder. - * @param filename The name of the file. - * @returns A promise that completes with a value of either true (if the file exists) or false. - **/ - exists(filename: string): Promise; - - /** - * Reads the specified file. If the file doesn't exist, the specified default value is returned. - * @param fileName The file to read from. - * @param def The default value to be returned if the file failed to open. - * @returns A promise that completes with a value that is either the contents of the file, or the specified default value. - **/ - readText(fileName: string, def?: string): Promise; - - /** - * Deletes a file from the folder. - * @param fileName The file to be deleted. - * @returns A promise that is fulfilled when the file has been deleted. - **/ - remove(fileName: string): Promise; - - /** - * Writes the specified text to the specified file. - * @param fileName The name of the file. - * @param text The text to write. - * @returns A Promise that completes with the number of bytes successfully written to the file. - **/ - writeText(fileName: string, text: string): Promise; - - //#endregion Methods - - }; - //#endregion Objects //#region Methods From 5051de332ff6c146df87526fe810f6b2d3313bd2 Mon Sep 17 00:00:00 2001 From: Anand Prakash Date: Sun, 27 Apr 2014 17:33:12 -0700 Subject: [PATCH 2/5] Changed QueryCollection to be an interface instead of class so that it can extend Array interface. In WinJS implementaion, QueryCollection extends Array and all Array members should be available on QueryCollection. --- winjs/winjs.d.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/winjs/winjs.d.ts b/winjs/winjs.d.ts index d14238eeeb..f58c11d12d 100644 --- a/winjs/winjs.d.ts +++ b/winjs/winjs.d.ts @@ -76,17 +76,17 @@ declare module WinJS.Application { /** * The local storage of the application. **/ - var local: IOHelper; + var local: IOHelper; /** * The roaming storage of the application. **/ - var roaming: IOHelper; + var roaming: IOHelper; /** * The temp storage of the application. **/ - var temp: IOHelper; + var temp: IOHelper; /** * An object used for storing app information that can be used to restore the app's state after it has been suspended and then resumed. Data that can usefully be contained in this object includes the current navigation page or any information the user has added to the input controls on the page. You should not add information about customization (for example colors) or user-defined lists of content. @@ -7904,7 +7904,7 @@ declare module WinJS.Utilities { /** * Represents the result of a query selector, and provides various operations that perform actions over the elements of the collection. **/ - class QueryCollection { + interface QueryCollection extends Array { //#region Constructors /** From bfe38c6de7878946433025a4b69e34f53dc6ffab Mon Sep 17 00:00:00 2001 From: Anand Prakash Date: Sun, 27 Apr 2014 17:35:19 -0700 Subject: [PATCH 3/5] Made element parameter optional in WinJS.Utilities.query as it is optional in WinJS implementation. See http://msdn.microsoft.com/en-us/library/windows/apps/br229847.aspx. --- winjs/winjs.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/winjs/winjs.d.ts b/winjs/winjs.d.ts index f58c11d12d..a2e95e557f 100644 --- a/winjs/winjs.d.ts +++ b/winjs/winjs.d.ts @@ -8243,7 +8243,7 @@ declare module WinJS.Utilities { * @param element Optional. The root element at which to start the query. If this parameter is omitted, the scope of the query is the entire document. * @returns A QueryCollection with zero or one elements matching the specified selector query. **/ - function query(query: any, element: HTMLElement): QueryCollection; + function query(query: any, element?: HTMLElement): QueryCollection; /** * Ensures that the specified function executes only after the DOMContentLoaded event has fired for the current page. The DOMContentLoaded event occurs after the page has been parsed but before all the resources are loaded. From 63ae54c867e3123af911927e7b2eab4b7f89174c Mon Sep 17 00:00:00 2001 From: Anand Prakash Date: Sun, 27 Apr 2014 18:38:43 -0700 Subject: [PATCH 4/5] Added constructor support for QueryCollection interface --- winjs/winjs.d.ts | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/winjs/winjs.d.ts b/winjs/winjs.d.ts index a2e95e557f..b5ded7a592 100644 --- a/winjs/winjs.d.ts +++ b/winjs/winjs.d.ts @@ -7905,17 +7905,6 @@ declare module WinJS.Utilities { * Represents the result of a query selector, and provides various operations that perform actions over the elements of the collection. **/ interface QueryCollection extends Array { - //#region Constructors - - /** - * Initializes a new instance of a QueryCollection. - * @constructor - * @param items The items resulting from the query. - **/ - constructor(items: T[]); - - //#endregion Constructors - //#region Methods /** @@ -8062,6 +8051,14 @@ declare module WinJS.Utilities { } + /** + * Constructor support for QueryCollection interface + **/ + export var QueryCollection: { + new (items: T[]): QueryCollection; + prototype: QueryCollection; + } + //#endregion Objects //#region Functions From 375d64188a59d22929054d98c32b8a96d9330577 Mon Sep 17 00:00:00 2001 From: Anand Prakash Date: Mon, 5 May 2014 19:02:45 -0700 Subject: [PATCH 5/5] Updated IOHelper.writeText to return WinJS.Promise instead of WinJS.Promise --- winjs/winjs.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/winjs/winjs.d.ts b/winjs/winjs.d.ts index b5ded7a592..2b8e95c357 100644 --- a/winjs/winjs.d.ts +++ b/winjs/winjs.d.ts @@ -64,7 +64,7 @@ interface IOHelper { * @param text The content to be written to the file. * @returns A promise that completes with a value that is the number of characters written. **/ - writeText(fileName: string, text: string): WinJS.Promise; + writeText(fileName: string, text: string): WinJS.Promise; } /**