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
new Activity()
Creates a new activity instance.
Static members
Activity.View staticprotected
Returns a view builder for the activity’s view, to be set for each activity class.
Instance members
activeSignal
AbortSignal for the current activation.title
A user-facing name for this activity, if any.view
The current view, if any (attached automatically).delegate()
Delegates incoming events to methods of this object, notably from the attached view.isActive()
Returns true if this activity is currently active.activate()
Activates the activity.deactivate()
Deactivates the activity.afterActive() protected
Called after activation, for initialization (may be async).afterInactive() protected
Called after deactivation, for cleanup (may be async).beforeUnlink() protected
Called immediately before the activity is unlinked.showDialogAsync()
Shows a dialog activity, and returns a promise that resolves when the dialog is closed.setRenderMode() protected
Set rendering mode and additional options.findViewContent()
Searches the view hierarchy for view objects of the provided type.navigateAsync() protected
Handles navigation to a provided path, from the current activity.onNavigate() protected
Handles aNavigateevent emitted by the current view.onNavigateBack() protected
Handles aNavigateBackevent emitted by the current view.
Inherited members
emit()
Emits an event, immediately calling all event handlers.emitChange()
Emits a change event.listen()
Adds a handler for all events emitted by this object.listenOnce()
Returns a promise for a single event with the provided name.listenAsync()
Adds a handler for all events emitted by this object, and returns an async iterable.observe()
Observes a property, a bound property from an attached parent, or an observable object.observeAsync()
Observes one or more targets asynchronously, batching or debouncing/throttling updates.attach() protected
Attaches the specified observable object to this object.isUnlinked()
Returns true if the object has been unlinked.unlink()
Unlinks this observable object.
