createViewModel

fun Page.createViewModel(scope: CoroutineScope, appState: AppStateImpl, gameSession: MutableState<GameSession>, audioThemeState: MutableState<AudioThemeState>, pagesState: MutableState<PagesState>): ViewModel<out UiState>?

Creates and returns the appropriate ViewModel instance based on the current Page type.

This extension function acts as a factory method that maps each page type to its corresponding ViewModel implementation. It properly wires up all dependencies including coroutine scopes, state management callbacks, and navigation handlers.

Receiver

The Page instance for which to create a ViewModel.

Return

A ViewModel instance appropriate for the current page type.

Parameters

scope

The CoroutineScope used for launching coroutines within ViewModels.

appState

The current application state providing access to game, theme, and service.

gameSession

Mutable state holding the current game session (game + player name).

audioThemeState

Mutable state holding audio and theme configuration.

pagesState

Mutable state holding current page and navigation state.

See also