-
Notifications
You must be signed in to change notification settings - Fork 6
View
##Summary
The View class is responsible for rendering a chunk of markup in the page programatically. Views are responsible for the following:
- Rendering content
- Exposing a root element
- Exposing lifetime hooks in which code can execute
- Consuming data and updating the content if appropriate
- Managing view hierarchy relationships for supporting bubbling and traversal scenarios
The basic interface for a view is simple:
interface IView {
element: HTMLElement;
viewModel: any;
parent: IView;
owner: IView;
children: IView[];
render() : HTMLElement;
activate();
resize();
update();
setData(data: any, forceUpdate?: boolean);
deactivate();
dispose();
}
The purpose of the interface is to provide a baseline contract that can be expected of every view implementation. Having this contract means that the template compiler can expect these basic things when generating code, and enables sub-view nesting.
While you are free to implement the interface on your own, there are base implementations of the IView interface that can provide some boilerplate logic for you.
The most basic implementation of this interface is the BaseView class, which implements the interface methods and introduces a set of overrideable "on" prefixed overridable methods that will only be called at the right time in the control stages. It also provides basic child management methods for adding/removing children.
The primary implementation however, the View class, is what the template compiler subclasses generated views from by default. It subclasses BaseView and provides additional methods for binding event handlers, pulling values from the view model, and translating binding state to dom updates.