Share via


Shell.Utilities.js

 

Applies To: Windows Azure Pack

Contains a set of general-utility methods.

Widgets

None.

Types

Shell.Promise(init, cancel)

A Promise provides a mechanism to schedule work to be done on a value that has not yet been computed. It is a convenient abstraction for managing interactions with asynchronous APIs.

Name

Type

Description

init

Function

Function called during construction of the Promise. The function is given three arguments (complete, error, progress).

cancel

Function

Optional. Function to call if a down-stream consumer of this Promise wants to attempt to cancel its undone work. Promises are not required to be cancelable.

Properties

None.

Methods

Name

Description

Returns

Parameters

Shell.Promise.addEventListener

Adds an event listener to the control.

Nothing

eventType: The type (name) of the event.

listener: The listener to invoke when the event is raised.

capture: Specifies whether or not to initiate capture.

Shell.Promise.any

Returns a Promise which is fulfilled when one of the input Promises has been fulfilled.

Promise

values (Array): Array of values including Promise objects or Object whose property values include Promise objects.

Shell.Promise.as

Returns a Promise, if the value is already a Promise it is returned otherwise the value is wrapped in a Promise.

Promise

Value: Value to be treated as a Promise.

Shell.Promise.cancel

Attempts to cancel the realization of a promised value. If the Promise hasn't already been fulfilled and cancellation is supported the Promise will enter the error state with a value of new Error("Canceled").

Nothing

None

Shell.Utilities.deepEquals

Compares two objects deeply and returns true if they are equals. Compares two arrays deeply and returns true if they are equals.

Boolean

a (Object):

b (Object):

a (Array):

b (Array):

Shell.Promise.dispatchEvent

Raises an event of the specified type and with additional properties. Returns true if preventDefault was called on the event.

Boolean

eventType: The type (name) of the event.

Details: The set of additional properties to be attached to the event object when the event is raised.

Shell.Utilities.download

Downloads content to the browser. The returned object is the iFrame that will host the download.

Object

uri (String): URI of the content to be downloaded

Shell.Utilities.getAntiForgeryId

Gets the anti-forgery token ID.

String

None

Shell.Promise.is

Determine whether a value fulfills the Promise contract. True is returned if the value is a Promise.

Boolean

Value:A value which may be a Promise.

Shell.Promise.join

Creates a Promise that is fulfilled when all the values are realized.

Return is a Promise whose value is a record with the same field names as the input where each field is a realized value.

Promise

values (Object): Record whose fields contains values, some of which may be Promises.

Shell.Utilities.newGuid

Returns new a GUID.

String

None

Shell.Promise.removeEventListener

Removes an event listener from the control.

Nothing

eventType: The type (name) of the event.

Listener: The listener to remove from the invoke list.

Capture: Specifies whether or not to initiate capture.

Shell.Promise.then

Static forwarder to the Promise instance method then(). Returns Promise whose value will be the result of running the provided function.

Promise

complete (Function): Function to be called if the Promise is fulfilled successfully with a value. If null then the Promise will provide a default implementation which simply returns the value. The value will be passed as the single argument.

error (Function): Function to be called if the Promise is fulfilled with an error. The error will be passed as the single argument.

progress (Function): Function to be called if the Promise reports progress. Data about the progress will be passed as the single argument. Promises are not required to support progress.

Shell.Promise.thenEach

Performs an operation on all of the input promises and returns a Promise which is in the shape of the input and contains the result of the operation having been performed on each input.

Returns a Promise that is the result of calling Promise.Join in the parameter values.

Promise

complete (Function): Function to be called if the Promise is fulfilled successfully with a value. If null then the Promise will provide a default implementation which simply returns the value. The value will be passed as the single argument.

error (Function): Function to be called if the Promise is fulfilled with an error. The error will be passed as the single argument.

progress (Function): Function to be called if the Promise reports progress. Data about the progress will be passed as the single argument. Promises are not required to support progress.

Shell.Promise.timeout

Create a promise which is fulfilled after the supplied timeout period. Returns a Promise that is completed asynchronously after the milliseconds indicated by timeout.

Shell.Promise

timeout (Number): Timeout period, if 0 or not specified this is implemented using msSetImmediate, otherwise using setTimeout.

Shell.Promise.wrap

Wrap a non-Promise value in a promise, this is useful if you need to pass a value to a function which requires a Promise. Returns a Promise which is successfully fulfilled with the specified value.

Shell.Promise

Value: A non-Promise value to wrap in a promise.

Shell.Promise.wrapError

Wrap a non-Promise error value in a promise, this is useful if you need to pass an error to a function which requires a Promise. Returns a Promise which is fulfilled in an error state with the specified value.

Shell.Promise

Error: A non-Promise error to be wrapped in a Promise.

See Also

Windows Azure Pack Extension Shell Library Reference