View Model

Rico Suter edited this page Jun 1, 2015 · 8 revisions

Base class: ViewModel

Each view can only have one view model class. The view model class is an abstract representation of the view and contains observable variables and methods. These variables and methods are bound to the view's HTML code using bindings so that the UI is automatically updated. The view model should only contain business logic and no UI logic. All UI logic should be implemented using either bindings or in the view "code-behind" class.

The view model class

Every view model must extend the class ViewModel:

import visto = import("libs/visto");
export class MyViewModel extends visto.ViewModel {
    ....
}

Methods provided by the ViewModel base class:

  • Event methods
  • subscribe(observable, callback)
    • Subscribes the callback on the observable and adds the subscription to the internal collection of disposables
    • Registers a change event callback on the observable. the view model holds a reference to the subscription and closes it on destroy...
    • See also Avoiding memory leaks

Properties provided by the ViewModel base class:

You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.