API reference › @evolu/common › local‑first/Evolu › subscribeAppOwnerState
function subscribeAppOwnerState<
S extends Readonly<
Record<string, Readonly<Record<string, AnyStandardSchemaV1>>>
>,
>(
current: ReadonlyStore<CurrentAppOwner<S> | null>,
onChange: (state: AppOwnerState<S>) => void,
): Unsubscribe;
Defined in: packages/common/src/local-first/Evolu.ts:2220
Follows current, such as EvoluApp.current, as an
AppOwnerState, and calls onChange with the state at once and
whenever it changes. Another instance, as when the tab opens another
AppOwner, or the AppOwner again after a removal and restore or its database's
deletion, is Opening until its promise resolves, and then Open, so a UI
keyed by the instance remounts. Another CurrentAppOwner with the same
instance keeps the state's type and instance, with the new current. An
instance that opens after the tab moved on changes nothing, and one that
never opens, as an aborted open's, leaves the state Opening. Once
unsubscribed, an instance that opens changes nothing.
The UI bindings follow the app with it, and so can an app without one.
Example
import {
assertType,
subscribeAppOwnerState,
type EvoluApp,
type Name,
type TestEvoluSchema,
type Unsubscribe,
} from "@evolu/common";
// Renders the open AppOwner's database name, or what shows meanwhile.
const renderApp = (
app: EvoluApp<TestEvoluSchema>,
render: (text: Name | "Opening" | "None") => void,
): Unsubscribe =>
subscribeAppOwnerState(app.current, (state) => {
render(state.type === "Open" ? state.evolu.name : state.type);
});
assertType<ReturnType<typeof renderApp>, Unsubscribe>();