Documentation

class Activity

A class that represents a part of the application that can be activated when the user navigates to it.

class Activity extends ObservableObject;

Description

The activity is one of the main architectural components of an application. It represents a potential ‘place’ in the application, which can be activated and deactivated as the user navigates around.

Path-based routing is managed by ActivityRouter, NavigationContext, and AppContext.addRoutes(). Alternatively, activities can be activated and deactivated manually.

Activities emit Active and Inactive change events when state transitions occur. Override afterActive for initialization (receiving an AbortSignal for cancellation), and afterInactive for cleanup.

The static Activity.View property must be set to a function that returns a view builder, which is used to create the view object when the activity becomes active. This function is called only once for each activity, as well as when the activity is reloaded using Hot Module Replacement (HMR).

As soon as the activity is activated and a view is created, the view is rendered. The view is unlinked when the activity is deactivated, and the view property is set to undefined. To change rendering options or disable automatic rendering, use the setRenderMode() method.

Examples

// Create an activity and activate it:
class MyActivity extends Activity {
  static View = MyView; // typically imported from a view file

  // ... state, event handlers, etc.
}

app.addActivity(new MyActivity(), true);

Constructor

Static members

Instance members

Inherited members