App Lifecycle

← Lifecycle
STRVCT

SvApp singleton initialization sequence, extension points, runtime environment hooks, user alert routing, and UI readiness promises.

Overview

SvApp is the application singleton. It owns the persistent object pool, root model object graph, and top-level user interface (SvUserInterface). Subclasses override a small set of hook methods to initialize application models and user interfaces in a clean, predictable order.

1. setupModel() Store open, root object exists 2. setupUi() Model ready; UI instantiated 3. appDidInit() Posts "appDidInit" note 4. afterAppUiDidInit() UI visible; processes URL params Model initialization is fully separated from UI rendering; app runs identically in browser or headless Node.js.

Extension Point Hook Methods

Hook MethodWhen ExecutedPurpose & Usage
setupModel()Object pool store is open; root model exists.Initialize application data models; create or fetch top-level subnodes.
setupUi()Model object graph is ready.Customize top-level UI presentation and window settings.
appDidInit()Everything is wired up and live.Post-initialization tasks; posts "appDidInit" notification.
afterAppUiDidInit()UI elements are mounted and visible.Parse URL search parameters via handleSearchParams(params).
handleSearchParams(params)Called automatically from afterAppUiDidInit().Process URL query parameters for deep-linking.

Top-Level Root Subnode Persistence (rootSubnodeWithTitleForProto):

To instantiate top-level application root nodes safely across reloads:

setupModel () {
    super.setupModel();
    // Creates on first run; reuses from storage on subsequent loads
    this._tasksNode = this.rootSubnodeWithTitleForProto("Tasks", TaskManagerNode);
}

Waiting for Initialization & UI Readiness

1. App Initialization Promise (didInitPromise)

Code that needs to wait for complete application setup awaits didInitPromise():

await SvApp.shared().didInitPromise();
// App is now fully initialized and live

2. UI Readiness Promise (promiseUserInterfaceReady)

UI-dependent code (e.g. sending navigation selection requests) awaits promiseUserInterfaceReady():

const ui = await SvApp.shared().promiseUserInterfaceReady();
if (ui.providesNavigation()) {
    // Safe to send navigation requests
    this.postNoteNamed("onRequestSelectNodePath", { path: ["Workspace", "Tasks"] });
}

Runtime Environment Event Hooks

SvApp captures environment lifecycle signals and translates them into environment-agnostic hooks on SvModel:

Model Hook Method (SvModel)Browser Signal EventHeadless Signal EventPurpose & Action
onAppDidGoOnline()online event—Network connectivity restored
onAppDidGoOffline()offline event—Network connectivity lost
onAppWillSuspend()visibilitychange (hidden)—App backgrounded; flush volatile state
onAppWillTerminate()beforeunload (sync)SIGTERM / SIGINTShutdown/unload cleanup. Return true to block unload.

Model User Alerts (`onRequestUserAlert`)

Domain models request user notifications without referencing UI or DOM classes:

this.postNoteNamed("onRequestUserAlert", {
    name: "syncFailure",
    title: "Sync Error",
    message: "Failed to sync changes with cloud store.",
    level: "error" // "info" | "warning" | "error"
});

SvUserInterface observes onRequestUserAlert. In the browser (SvWebUserInterface), it opens an SvPanelView overlay; in headless Node.js, it logs the alert to console.