Docs (4.0.0)
Views

class ViewComposite

A class that encapsulates a dynamic view.

abstract

class ViewComposite<TView extends View = View>
extends View

Description

View composites contain a single (attached) view object. ViewComposite instances are themselves also views, and as such can be included in a view hierarchy or used as the view object of an Activity. When rendered, view composites display the contained view component.

The encapsulated view is referenced by the body property, which is usually set automatically, either when the ViewComposite is instantiated or right before rendering. It may be changed or unlinked at any time; the rendered view will be updated accordingly by the ViewComposite itself.

The body property is watched using ManagedObject.autoAttach, which means that setting it to a view instance automatically attaches the object to the ViewComposite. Setting the property to undefined will unlink the existing view, and setting it to a new view will unlink an existing one. Therefore, the ViewComposite instance can only contain a single view object at a time.

Since the view is attached to the ViewComposite object, bindings continue to work, and events can be handled either by the ViewComposite object or by a containing object.

View composites are primarily used in two different ways:

  • As a way to control an encapsulated view. Refer to e.g. UIConditionalView and UIListView, which are built-in ViewComposite classes.
  • As a way to create reusable view structures. Refer to the static withPreset() method which can be used to create a ViewComposite class using a function and/or a class.

Note the similarities with the Activity class, which also encapsulates a single view object. As a rule, use activities if event handlers or other class methods include business logic. Use view composites if the class is only concerned with the look and feel of a set of UI components, and all content can be preset, bound, or provided by a view model.

Constructor

Type Members

Static Members

Instance Members

Inherited Members