17 lines · 886 B · KotlinRaw
package com.cottondb.androidimport com.cottondb.android.briefing.BriefingModelimport com.cottondb.android.core.CottonCallingimport com.cottondb.android.navigation.Routeimport kotlinx.coroutines.CoroutineScope/** Retains one child-scoped model per briefing route while that route is on the stack. */class BriefingModels(private val core: CottonCalling, private val scope: CoroutineScope) { private val visits = mutableMapOf<String?, BriefingModel>() fun briefing(project: String?): BriefingModel = visits.getOrPut(project) { BriefingModel(core, project, scope) } fun briefing(route: Route.Briefing): BriefingModel = briefing(route.project) fun retain(routes: List<Route>) { val kept = routes.filterIsInstance<Route.Briefing>().map { it.project }.toSet() visits.keys.filterNot(kept::contains).forEach { key -> visits.remove(key)?.close() } }}