Skip to content

TypeScript Method Objects

For each Custom Method you define, a class will be created on the corresponding TypeScript ViewModel (instance methods) or ListViewModel (static methods) that contains the properties and functions for interaction with the method. This class is accessible through a static property named after the method. An instance of this class will also be created on each instance of its parent - this instance is in a property with the camel-cased name of the method.

Here's an example for a method called Rename that takes a single parameter 'string name' and returns a string.

c#
public string Rename(string name)
{
    FirstName = name;
    return FullName; // Return the new full name of the person.
}

Base Members

The following members are available on the method object for all client methods:

public result: KnockoutObservable<string>

Observable that will contain the results of the method call after it is complete.

public rawResult: KnockoutObservable<Coalesce.ApiResult>

Observable with the raw, deserialized JSON result of the method call. If the method call returns an object, this will contain the deserialized JSON object from the server before it has been loaded into ViewModels and its properties loaded into observables.

public isLoading: KnockoutObservable<boolean>

Observable boolean which is true while the call to the server is pending.

public message: KnockoutObservable<string>

If the method was not successful, this contains exception information.

public wasSuccessful: KnockoutObservable<boolean>

Observable boolean that indicates whether the method call was successful or not.

ListResult<T> Base Members

For methods that return a ListResult<T>, the following additional members on the method object will be available:

public page: KnockoutObservable<number>

Page number of the results.

public pageSize: KnockoutObservable<number>

Page size of the results.

public pageCount: KnockoutObservable<number>

Total number of possible result pages.

public totalCount: KnockoutObservable<number>

Total number of results.

Method-specific Members

public static Rename = class Rename extends Coalesce.ClientMethod<Person, string> { ... }

Declaration of the method object class. This will be generated on the parent ViewModel or ListViewModel.

public readonly rename = new Person.Rename(this)

Default instance of the method for easy calling of the method without needing to manually instantiate the class. This will be generated on the parent ViewModel or ListViewModel.

public invoke: (name: string, callback: (result: string) => void = null, reload: boolean = true): JQueryPromise<any>

Function that takes all the method parameters and a callback. If reload is true, the ViewModel or ListViewModel that owns the method will be reloaded after the call is complete, and only after that happens will the callback be called.

public static Args = class Args { public name: KnockoutObservable<string> = ko.observable(null); }

Class with one observable member per method argument for binding method arguments to user input. Only generated for methods with arguments.

public args = new Rename.Args()

Default instance of the args class. Only generated for methods with arguments.

public invokeWithArgs: (args = this.args, callback?: (result: string) => void, reload: boolean = true) => JQueryPromise<any>

Function for invoking the method using the args class. The default instance of the args class will be used if none is provided. Only generated for methods with arguments.

public invokeWithPrompts: (callback: (result: string) => void = null, reload: boolean = true) => JQueryPromise<any>

Simple interface using browser prompt() input boxes to prompt the user for the required data for the method call. The call is then made with the data provided. Only generated for methods with arguments.

public resultObjectUrl: KnockoutObservable<string | null>

Observable that will contain an Object URL representing the last successful invocation result. Only generated for methods that return a file.

public url: KnockoutComputed<string>

The URL for the method. Can be useful for using as the src attribute of an image or video HTML element for file-downloading methods. Any arguments will be populated from this.args. Only generated for HTTP GET methods, as configured by [ControllerAction].


Coalesce is a free and open-source framework created by IntelliTect to fill our desire to create better apps, faster. IntelliTect is a high-end software architecture and development consulting firm based in Spokane, Washington.

If you're looking for help with your software project, whether it be a Coalesce application, other technologies, or even just an idea, reach out to us at info@intellitect.com — we'd love to start a conversation! Our clients range from Fortune 100 companies to local small businesses and non-profits.