From 04eef573e9b152f2da773ef1bcc82c91106bade4 Mon Sep 17 00:00:00 2001 From: Dmitriy Gorbunov Date: Sat, 6 Jan 2024 03:02:17 +0300 Subject: [PATCH] PmDescription and PmParams replaced with serializable arguments (PmArgs). --- libs.versions.toml | 1 + .../premo/navigation/DialogGroupNavigation.kt | 10 +-- .../dmdev/premo/navigation/DialogNavigator.kt | 4 +- .../navigation/MasterDetailNavigation.kt | 7 +- .../premo/navigation/MasterDetailNavigator.kt | 20 +++-- .../dmdev/premo/navigation/SetNavigation.kt | 7 +- .../me/dmdev/premo/navigation/SetNavigator.kt | 13 ++-- .../dmdev/premo/navigation/StackNavigation.kt | 35 +-------- .../dmdev/premo/navigation/StackNavigator.kt | 27 ++----- .../navigation/DialogGroupNavigationTest.kt | 44 +++++------ .../navigation/DialogNavigatorTest.kt | 20 ++--- .../navigation/MasterDetailNavigatorTest.kt | 42 +++++------ .../navigation/SetNavigatorTest.kt | 75 ++++++++++++------- .../navigation/StackNavigatorTest.kt | 62 +++++++++------ .../me.dmdev.premo/navigation/TestPm.kt | 36 ++++----- .../navigation/TestPmFactory.kt | 12 +-- .../me/dmdev/premo/saver/JsonPmStateSaver.kt | 12 +-- premo/build.gradle.kts | 1 + .../me/dmdev/premo/AndroidPmDelegate.kt | 13 ++-- .../me/dmdev/premo/{PmParams.kt => PmArgs.kt} | 31 ++++++-- .../kotlin/me/dmdev/premo/PmDelegate.kt | 15 ++-- .../kotlin/me/dmdev/premo/PmDescription.kt | 29 ------- .../kotlin/me/dmdev/premo/PmFactory.kt | 4 +- .../me/dmdev/premo/PresentationModel.kt | 41 +++++----- .../kotlin/me.dmdev.premo/PmDelegateTest.kt | 11 +-- .../kotlin/me.dmdev.premo/PmStateSaverTest.kt | 57 +++++++------- .../me.dmdev.premo/PresentationModelTest.kt | 10 +-- .../kotlin/me.dmdev.premo/TestPm.kt | 16 ++-- .../kotlin/me.dmdev.premo/TestPmFactory.kt | 8 +- .../kotlin/me.dmdev.premo/IosPmDelegate.kt | 13 ++-- .../kotlin/me.dmdev.premo/JsPmDelegate.kt | 13 ++-- .../kotlin/me/dmdev/premo/JvmPmDelegate.kt | 15 ++-- .../kotlin/me/dmdev/premo/sample/CounterPm.kt | 14 ++-- .../kotlin/me/dmdev/premo/sample/MainPm.kt | 19 +++-- .../me/dmdev/premo/sample/MainPmFactory.kt | 36 ++++----- .../me/dmdev/premo/sample/PremoSample.kt | 12 +-- .../kotlin/me/dmdev/premo/sample/SamplesPm.kt | 9 +-- .../kotlin/me/dmdev/premo/sample/Stubs.kt | 37 ++++----- .../bottomnavigation/BottomNavigationPm.kt | 20 +++-- .../sample/bottomnavigation/TabItemPm.kt | 17 ++--- .../premo/sample/bottomnavigation/TabPm.kt | 27 ++++--- .../dilaognavigation/DialogNavigationPm.kt | 17 ++--- .../sample/dilaognavigation/SimpleDialogPm.kt | 17 ++--- .../premo/sample/serialization/Serializers.kt | 28 +++---- .../sample/stacknavigation/SimpleScreenPm.kt | 14 ++-- .../stacknavigation/StackNavigationPm.kt | 11 ++- sample/app-compose/build.gradle.kts | 1 + .../me/dmdev/premo/sample/MainActivity.kt | 4 +- .../sample/screen/BottomNavigationScreen.kt | 6 +- .../sample/screen/DialogNavigationScreen.kt | 10 +-- .../kotlin/me/dmdev/premo/sample/Main.kt | 4 +- .../kotlin/me/dmdev/premo/sample/Main.kt | 2 +- .../app-ios-swiftui/AppDelegate.swift | 2 +- .../DialogNavigationView.swift | 8 +- .../kotlin/me.dmdev.premo.sample/Main.kt | 4 +- .../kotlin/me.dmdev.premo.sample/Main.kt | 4 +- .../component/DialogNavigationComponent.kt | 14 ++-- settings.gradle.kts | 4 +- 58 files changed, 495 insertions(+), 550 deletions(-) rename premo/src/commonMain/kotlin/me/dmdev/premo/{PmParams.kt => PmArgs.kt} (63%) delete mode 100644 premo/src/commonMain/kotlin/me/dmdev/premo/PmDescription.kt diff --git a/libs.versions.toml b/libs.versions.toml index 9acd83f6..c44af268 100644 --- a/libs.versions.toml +++ b/libs.versions.toml @@ -29,6 +29,7 @@ kotlin-test = { group = "org.jetbrains.kotlin", name = "kotlin-test", version.re kotlinx-coroutines-core = { group = "org.jetbrains.kotlinx", name = "kotlinx-coroutines-core", version.ref = "coroutines" } kotlinx-coroutines-test = { group = "org.jetbrains.kotlinx", name = "kotlinx-coroutines-test", version.ref = "coroutines" } kotlinx-coroutines-swing = { group = "org.jetbrains.kotlinx", name = "kotlinx-coroutines-swing", version.ref = "coroutines" } +kotlinx-serialization-core = { group = "org.jetbrains.kotlinx", name = "kotlinx-serialization-core", version.ref = "kotlinx-serialization" } kotlinx-serialization-json = { group = "org.jetbrains.kotlinx", name = "kotlinx-serialization-json", version.ref = "kotlinx-serialization" } kotlinx-serialization-protobuf = { group = "org.jetbrains.kotlinx", name = "kotlinx-serialization-protobuf", version.ref = "kotlinx-serialization" } diff --git a/premo-navigation/src/commonMain/kotlin/me/dmdev/premo/navigation/DialogGroupNavigation.kt b/premo-navigation/src/commonMain/kotlin/me/dmdev/premo/navigation/DialogGroupNavigation.kt index 7f2a6c00..d40c92a0 100644 --- a/premo-navigation/src/commonMain/kotlin/me/dmdev/premo/navigation/DialogGroupNavigation.kt +++ b/premo-navigation/src/commonMain/kotlin/me/dmdev/premo/navigation/DialogGroupNavigation.kt @@ -1,7 +1,7 @@ /* * The MIT License (MIT) * - * Copyright (c) 2020-2023 Dmitriy Gorbunov (dmitriy.goto@gmail.com) + * Copyright (c) 2020-2024 Dmitriy Gorbunov (dmitriy.goto@gmail.com) * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -74,10 +74,10 @@ internal class DialogGroupNavigatorImpl( hostPm.SaveableFlow( key = key, initialValueProvider = { listOf() }, - saveTypeMapper = { dialogs -> dialogs.map { it.description } }, - restoreTypeMapper = { descriptions -> - descriptions.mapNotNull { description -> - dialogNavigators.find { it.dialog?.description == description }?.dialog + saveTypeMapper = { dialogs -> dialogs.map { it.pmArgs } }, + restoreTypeMapper = { pmArgsList -> + pmArgsList.mapNotNull { pmArgs -> + dialogNavigators.find { it.dialog?.pmArgs == pmArgs }?.dialog } } ) diff --git a/premo-navigation/src/commonMain/kotlin/me/dmdev/premo/navigation/DialogNavigator.kt b/premo-navigation/src/commonMain/kotlin/me/dmdev/premo/navigation/DialogNavigator.kt index 9560fcac..7d3c6f83 100644 --- a/premo-navigation/src/commonMain/kotlin/me/dmdev/premo/navigation/DialogNavigator.kt +++ b/premo-navigation/src/commonMain/kotlin/me/dmdev/premo/navigation/DialogNavigator.kt @@ -1,7 +1,7 @@ /* * The MIT License (MIT) * - * Copyright (c) 2020-2023 Dmitriy Gorbunov (dmitriy.goto@gmail.com) + * Copyright (c) 2020-2024 Dmitriy Gorbunov (dmitriy.goto@gmail.com) * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -91,7 +91,7 @@ internal class DialogNavigatorImpl( private val _dialog: MutableStateFlow = hostPm.SaveableFlow( key = key, initialValueProvider = { null }, - saveTypeMapper = { it?.description }, + saveTypeMapper = { it?.pmArgs }, restoreTypeMapper = { it?.let { hostPm.AttachedChild(it) as D } } ) override val dialogFlow: StateFlow = _dialog.asStateFlow() diff --git a/premo-navigation/src/commonMain/kotlin/me/dmdev/premo/navigation/MasterDetailNavigation.kt b/premo-navigation/src/commonMain/kotlin/me/dmdev/premo/navigation/MasterDetailNavigation.kt index 4b80def7..e3abc981 100644 --- a/premo-navigation/src/commonMain/kotlin/me/dmdev/premo/navigation/MasterDetailNavigation.kt +++ b/premo-navigation/src/commonMain/kotlin/me/dmdev/premo/navigation/MasterDetailNavigation.kt @@ -1,7 +1,7 @@ /* * The MIT License (MIT) * - * Copyright (c) 2020-2023 Dmitriy Gorbunov (dmitriy.goto@gmail.com) + * Copyright (c) 2020-2024 Dmitriy Gorbunov (dmitriy.goto@gmail.com) * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -25,7 +25,6 @@ package me.dmdev.premo.navigation import kotlinx.coroutines.flow.StateFlow -import me.dmdev.premo.PmDescription import me.dmdev.premo.PmMessageHandler import me.dmdev.premo.PresentationModel @@ -39,13 +38,13 @@ interface MasterDetailNavigation } fun PresentationModel.MasterDetailNavigation( - masterDescription: PmDescription, + masterPm: M, key: String = DEFAULT_MASTER_DETAIL_NAVIGATOR_KEY, backHandler: (MasterDetailNavigator) -> Boolean = DEFAULT_MASTER_DETAIL_NAVIGATOR_BACK_HANDLER, initHandlers: PmMessageHandler.(navigator: MasterDetailNavigator) -> Unit = {} ): MasterDetailNavigation { return MasterDetailNavigator( - masterDescription = masterDescription, + masterPm = masterPm, key = key, backHandler = backHandler, initHandlers = initHandlers diff --git a/premo-navigation/src/commonMain/kotlin/me/dmdev/premo/navigation/MasterDetailNavigator.kt b/premo-navigation/src/commonMain/kotlin/me/dmdev/premo/navigation/MasterDetailNavigator.kt index 3cb477f1..6cb0a632 100644 --- a/premo-navigation/src/commonMain/kotlin/me/dmdev/premo/navigation/MasterDetailNavigator.kt +++ b/premo-navigation/src/commonMain/kotlin/me/dmdev/premo/navigation/MasterDetailNavigator.kt @@ -1,7 +1,7 @@ /* * The MIT License (MIT) * - * Copyright (c) 2020-2023 Dmitriy Gorbunov (dmitriy.goto@gmail.com) + * Copyright (c) 2020-2024 Dmitriy Gorbunov (dmitriy.goto@gmail.com) * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -28,7 +28,7 @@ import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.asStateFlow import me.dmdev.premo.AttachedChild -import me.dmdev.premo.PmDescription +import me.dmdev.premo.PmArgs import me.dmdev.premo.PmMessageHandler import me.dmdev.premo.PresentationModel import me.dmdev.premo.SaveableFlow @@ -57,14 +57,14 @@ fun MasterDetailNavigator<*, *>.handleBack(): Boolean { } fun PresentationModel.MasterDetailNavigator( - masterDescription: PmDescription, + masterPm: M, key: String = DEFAULT_MASTER_DETAIL_NAVIGATOR_KEY, backHandler: (MasterDetailNavigator) -> Boolean = DEFAULT_MASTER_DETAIL_NAVIGATOR_BACK_HANDLER, initHandlers: PmMessageHandler.(navigator: MasterDetailNavigator) -> Unit = {} ): MasterDetailNavigator { val navigator = MasterDetailNavigatorImpl( hostPm = this, - masterDescription = masterDescription, + masterPm = masterPm, key = key ) messageHandler.handle { backHandler.invoke(navigator) } @@ -80,19 +80,23 @@ internal val DEFAULT_MASTER_DETAIL_NAVIGATOR_BACK_HANDLER: (MasterDetailNavigato internal class MasterDetailNavigatorImpl( private val hostPm: PresentationModel, - masterDescription: PmDescription, + masterPm: M, key: String ) : MasterDetailNavigator where M : PresentationModel, D : PresentationModel { - override val master: M = hostPm.AttachedChild(masterDescription) + override val master: M = masterPm + + init { + masterPm.attachToParent() + } private val _detailFlow: MutableStateFlow = hostPm.SaveableFlow( key = "${key}_detail_pm", initialValueProvider = { null }, - saveType = typeOf(), - saveTypeMapper = { it?.description }, + saveType = typeOf(), + saveTypeMapper = { it?.pmArgs }, restoreTypeMapper = { it?.let { hostPm.AttachedChild(it) as D } } ) override val detailFlow: StateFlow = _detailFlow.asStateFlow() diff --git a/premo-navigation/src/commonMain/kotlin/me/dmdev/premo/navigation/SetNavigation.kt b/premo-navigation/src/commonMain/kotlin/me/dmdev/premo/navigation/SetNavigation.kt index bdf170d0..d8499778 100644 --- a/premo-navigation/src/commonMain/kotlin/me/dmdev/premo/navigation/SetNavigation.kt +++ b/premo-navigation/src/commonMain/kotlin/me/dmdev/premo/navigation/SetNavigation.kt @@ -1,7 +1,7 @@ /* * The MIT License (MIT) * - * Copyright (c) 2020-2023 Dmitriy Gorbunov (dmitriy.goto@gmail.com) + * Copyright (c) 2020-2024 Dmitriy Gorbunov (dmitriy.goto@gmail.com) * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -25,7 +25,6 @@ package me.dmdev.premo.navigation import kotlinx.coroutines.flow.StateFlow -import me.dmdev.premo.PmDescription import me.dmdev.premo.PresentationModel interface SetNavigation { @@ -38,13 +37,13 @@ interface SetNavigation { } fun PresentationModel.SetNavigation( - vararg initialDescriptions: PmDescription, + initValues: () -> List, key: String = DEFAULT_SET_NAVIGATOR_KEY, backHandler: (SetNavigator) -> Boolean = DEFAULT_SET_NAVIGATOR_BACK_HANDLER, onChangeCurrent: (index: Int, navigator: SetNavigator) -> Unit = DEFAULT_SET_NAVIGATOR_ON_CHANGE_CURRENT ): SetNavigation { return SetNavigator( - initialDescriptions = initialDescriptions, + initValues = initValues, key = key, backHandler = backHandler, onChangeCurrent = onChangeCurrent diff --git a/premo-navigation/src/commonMain/kotlin/me/dmdev/premo/navigation/SetNavigator.kt b/premo-navigation/src/commonMain/kotlin/me/dmdev/premo/navigation/SetNavigator.kt index d9cbd4ee..0f82cd12 100644 --- a/premo-navigation/src/commonMain/kotlin/me/dmdev/premo/navigation/SetNavigator.kt +++ b/premo-navigation/src/commonMain/kotlin/me/dmdev/premo/navigation/SetNavigator.kt @@ -27,7 +27,6 @@ package me.dmdev.premo.navigation import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.asStateFlow -import me.dmdev.premo.PmDescription import me.dmdev.premo.PmLifecycle.State.CREATED import me.dmdev.premo.PmLifecycle.State.DESTROYED import me.dmdev.premo.PmLifecycle.State.IN_FOREGROUND @@ -53,14 +52,14 @@ fun SetNavigator.handleBack(): Boolean { } fun PresentationModel.SetNavigator( - vararg initialDescriptions: PmDescription, + initValues: () -> List, key: String = DEFAULT_SET_NAVIGATOR_KEY, backHandler: (SetNavigator) -> Boolean = DEFAULT_SET_NAVIGATOR_BACK_HANDLER, onChangeCurrent: (index: Int, navigator: SetNavigator) -> Unit = DEFAULT_SET_NAVIGATOR_ON_CHANGE_CURRENT ): SetNavigator { val navigator = SetNavigatorImpl( hostPm = this, - initialValues = initialDescriptions.asList(), + initValues = initValues, key = key, onChangeCurrent = onChangeCurrent ) @@ -80,16 +79,16 @@ internal val DEFAULT_SET_NAVIGATOR_ON_CHANGE_CURRENT: (index: Int, navigator: Se internal class SetNavigatorImpl( private val hostPm: PresentationModel, - initialValues: List, + initValues: () -> List, key: String, private val onChangeCurrent: (index: Int, navigator: SetNavigator) -> Unit ) : SetNavigator { private val _valuesFlow: MutableStateFlow> = hostPm.SaveableFlow( key = "${key}_values", - initialValueProvider = { initialValues.map { hostPm.Child(it) } }, - saveTypeMapper = { values -> values.map { it.description } }, - restoreTypeMapper = { descriptions -> descriptions.map { hostPm.Child(it) } } + initialValueProvider = { initValues() }, + saveTypeMapper = { values -> values.map { it.pmArgs } }, + restoreTypeMapper = { pmArgs -> pmArgs.map { hostPm.Child(it) } } ) override val valuesFlow: StateFlow> = _valuesFlow.asStateFlow() diff --git a/premo-navigation/src/commonMain/kotlin/me/dmdev/premo/navigation/StackNavigation.kt b/premo-navigation/src/commonMain/kotlin/me/dmdev/premo/navigation/StackNavigation.kt index 7d0104f0..91b572cb 100644 --- a/premo-navigation/src/commonMain/kotlin/me/dmdev/premo/navigation/StackNavigation.kt +++ b/premo-navigation/src/commonMain/kotlin/me/dmdev/premo/navigation/StackNavigation.kt @@ -1,7 +1,7 @@ /* * The MIT License (MIT) * - * Copyright (c) 2020-2023 Dmitriy Gorbunov (dmitriy.goto@gmail.com) + * Copyright (c) 2020-2024 Dmitriy Gorbunov (dmitriy.goto@gmail.com) * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -27,7 +27,6 @@ package me.dmdev.premo.navigation import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.StateFlow import me.dmdev.premo.ExperimentalPremoApi -import me.dmdev.premo.PmDescription import me.dmdev.premo.PmMessageHandler import me.dmdev.premo.PresentationModel @@ -42,41 +41,13 @@ interface StackNavigation { } fun PresentationModel.StackNavigation( - initialDescription: PmDescription? = null, + initBackStack: () -> List, key: String = DEFAULT_STACK_NAVIGATOR_KEY, backHandler: (StackNavigator) -> Boolean = DEFAULT_STACK_NAVIGATOR_BACK_HANDLER, initHandlers: PmMessageHandler.(navigator: StackNavigator) -> Unit = {} ): StackNavigation { return StackNavigator( - initialBackStack = initialDescription?.let { listOf(it) } ?: listOf(), - key = key, - backHandler = backHandler, - initHandlers = initHandlers - ) -} - -fun PresentationModel.StackNavigation( - vararg initialDescriptions: PmDescription, - key: String = DEFAULT_STACK_NAVIGATOR_KEY, - backHandler: (StackNavigator) -> Boolean = DEFAULT_STACK_NAVIGATOR_BACK_HANDLER, - initHandlers: PmMessageHandler.(navigator: StackNavigator) -> Unit = {} -): StackNavigation { - return StackNavigator( - initialBackStack = initialDescriptions.asList(), - key = key, - backHandler = backHandler, - initHandlers = initHandlers - ) -} - -fun PresentationModel.StackNavigation( - initialBackStack: List, - key: String = DEFAULT_STACK_NAVIGATOR_KEY, - backHandler: (StackNavigator) -> Boolean = DEFAULT_STACK_NAVIGATOR_BACK_HANDLER, - initHandlers: PmMessageHandler.(navigator: StackNavigator) -> Unit = {} -): StackNavigation { - return StackNavigator( - initialBackStack = initialBackStack, + initBackStack = initBackStack, key = key, backHandler = backHandler, initHandlers = initHandlers diff --git a/premo-navigation/src/commonMain/kotlin/me/dmdev/premo/navigation/StackNavigator.kt b/premo-navigation/src/commonMain/kotlin/me/dmdev/premo/navigation/StackNavigator.kt index 6126f53c..4382f8e3 100644 --- a/premo-navigation/src/commonMain/kotlin/me/dmdev/premo/navigation/StackNavigator.kt +++ b/premo-navigation/src/commonMain/kotlin/me/dmdev/premo/navigation/StackNavigator.kt @@ -32,7 +32,6 @@ import kotlinx.coroutines.flow.flow import kotlinx.coroutines.flow.map import kotlinx.coroutines.flow.stateIn import me.dmdev.premo.ExperimentalPremoApi -import me.dmdev.premo.PmDescription import me.dmdev.premo.PmLifecycle.State.CREATED import me.dmdev.premo.PmLifecycle.State.DESTROYED import me.dmdev.premo.PmLifecycle.State.IN_FOREGROUND @@ -83,28 +82,14 @@ fun StackNavigator.handleBack(): Boolean { } fun PresentationModel.StackNavigator( - vararg initialDescriptions: PmDescription, - key: String = DEFAULT_STACK_NAVIGATOR_KEY, - backHandler: (StackNavigator) -> Boolean = DEFAULT_STACK_NAVIGATOR_BACK_HANDLER, - initHandlers: PmMessageHandler.(navigator: StackNavigator) -> Unit = {} -): StackNavigator { - return StackNavigator( - initialBackStack = initialDescriptions.asList(), - key = key, - backHandler = backHandler, - initHandlers = initHandlers - ) -} - -fun PresentationModel.StackNavigator( - initialBackStack: List, + initBackStack: () -> List = { listOf() }, key: String = DEFAULT_STACK_NAVIGATOR_KEY, backHandler: (StackNavigator) -> Boolean = DEFAULT_STACK_NAVIGATOR_BACK_HANDLER, initHandlers: PmMessageHandler.(navigator: StackNavigator) -> Unit = {} ): StackNavigator { val navigator = StackNavigatorImpl( hostPm = this, - initialBackStack = initialBackStack, + initBackStack = initBackStack, key = key ) messageHandler.handle { backHandler.invoke(navigator) } @@ -119,16 +104,16 @@ internal val DEFAULT_STACK_NAVIGATOR_BACK_HANDLER: (StackNavigator) -> Boolean = internal class StackNavigatorImpl( private val hostPm: PresentationModel, - initialBackStack: List, + initBackStack: () -> List = { listOf() }, key: String ) : StackNavigator { private val _backStackFlow: MutableStateFlow> = hostPm.stateHandler.SaveableFlow( key = "${key}_backstack", - initialValueProvider = { initialBackStack.map { hostPm.Child(it) } }, - saveTypeMapper = { backStack -> backStack.map { it.description } }, - restoreTypeMapper = { descriptions -> descriptions.map { hostPm.Child(it) } } + initialValueProvider = { initBackStack() }, + saveTypeMapper = { backStack -> backStack.map { it.pmArgs } }, + restoreTypeMapper = { backStack -> backStack.map { hostPm.Child(it) } } ) override val backStackFlow: StateFlow> = _backStackFlow diff --git a/premo-navigation/src/commonTest/kotlin/me.dmdev.premo/navigation/DialogGroupNavigationTest.kt b/premo-navigation/src/commonTest/kotlin/me.dmdev.premo/navigation/DialogGroupNavigationTest.kt index c8487d08..8bcd67d1 100644 --- a/premo-navigation/src/commonTest/kotlin/me.dmdev.premo/navigation/DialogGroupNavigationTest.kt +++ b/premo-navigation/src/commonTest/kotlin/me.dmdev.premo/navigation/DialogGroupNavigationTest.kt @@ -1,7 +1,7 @@ /* * The MIT License (MIT) * - * Copyright (c) 2020-2023 Dmitriy Gorbunov (dmitriy.goto@gmail.com) + * Copyright (c) 2020-2024 Dmitriy Gorbunov (dmitriy.goto@gmail.com) * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -60,9 +60,9 @@ class DialogGroupNavigationTest { stateSaverFactory = TestStateSaverFactory() parentPm = TestPm.buildRootPm(stateSaverFactory) parentPm.lifecycle.moveTo(PmLifecycle.State.IN_FOREGROUND) - dialogPm1 = parentPm.Child(TestPm.PM1_DESCRIPTION) - dialogPm2 = parentPm.Child(TestPm.PM2_DESCRIPTION) - dialogPm3 = parentPm.Child(TestPm.PM3_DESCRIPTION) + dialogPm1 = parentPm.Child(TestPm.PM1_ARGS) + dialogPm2 = parentPm.Child(TestPm.PM2_ARGS) + dialogPm3 = parentPm.Child(TestPm.PM3_ARGS) navigator1 = parentPm.DialogNavigator(DIALOG_KEY1) navigator2 = parentPm.DialogNavigator(DIALOG_KEY2) navigator3 = parentPm.DialogNavigator(DIALOG_KEY3) @@ -122,18 +122,18 @@ class DialogGroupNavigationTest { val stateSaverFactory = TestStateSaverFactory( initialState = mutableMapOf( TestPm.ROOT_PM_KEY to mutableMapOf( - DIALOG_KEY1 to TestPm.PM1_DESCRIPTION, - DIALOG_KEY2 to TestPm.PM2_DESCRIPTION, - DIALOG_KEY3 to TestPm.PM3_DESCRIPTION, + DIALOG_KEY1 to TestPm.PM1_ARGS, + DIALOG_KEY2 to TestPm.PM2_ARGS, + DIALOG_KEY3 to TestPm.PM3_ARGS, DEFAULT_DIALOG_GROUP_NAVIGATION_KEY to listOf( - TestPm.PM1_DESCRIPTION, - TestPm.PM3_DESCRIPTION, - TestPm.PM2_DESCRIPTION + TestPm.PM1_ARGS, + TestPm.PM3_ARGS, + TestPm.PM2_ARGS ) ), - "${TestPm.ROOT_PM_KEY}/${TestPm.PM1_DESCRIPTION.key}" to mutableMapOf(), - "${TestPm.ROOT_PM_KEY}/${TestPm.PM2_DESCRIPTION.key}" to mutableMapOf(), - "${TestPm.ROOT_PM_KEY}/${TestPm.PM3_DESCRIPTION.key}" to mutableMapOf() + "${TestPm.ROOT_PM_KEY}/${TestPm.PM1_ARGS.key}" to mutableMapOf(), + "${TestPm.ROOT_PM_KEY}/${TestPm.PM2_ARGS.key}" to mutableMapOf(), + "${TestPm.ROOT_PM_KEY}/${TestPm.PM3_ARGS.key}" to mutableMapOf() ) ) @@ -170,18 +170,18 @@ class DialogGroupNavigationTest { assertEquals( mutableMapOf( TestPm.ROOT_PM_KEY to mutableMapOf( - DIALOG_KEY1 to TestPm.PM1_DESCRIPTION, - DIALOG_KEY2 to TestPm.PM2_DESCRIPTION, - DIALOG_KEY3 to TestPm.PM3_DESCRIPTION, + DIALOG_KEY1 to TestPm.PM1_ARGS, + DIALOG_KEY2 to TestPm.PM2_ARGS, + DIALOG_KEY3 to TestPm.PM3_ARGS, DEFAULT_DIALOG_GROUP_NAVIGATION_KEY to listOf( - TestPm.PM1_DESCRIPTION, - TestPm.PM3_DESCRIPTION, - TestPm.PM2_DESCRIPTION + TestPm.PM1_ARGS, + TestPm.PM3_ARGS, + TestPm.PM2_ARGS ) ), - "${TestPm.ROOT_PM_KEY}/${TestPm.PM1_DESCRIPTION.key}" to mutableMapOf(), - "${TestPm.ROOT_PM_KEY}/${TestPm.PM2_DESCRIPTION.key}" to mutableMapOf(), - "${TestPm.ROOT_PM_KEY}/${TestPm.PM3_DESCRIPTION.key}" to mutableMapOf() + "${TestPm.ROOT_PM_KEY}/${TestPm.PM1_ARGS.key}" to mutableMapOf(), + "${TestPm.ROOT_PM_KEY}/${TestPm.PM2_ARGS.key}" to mutableMapOf(), + "${TestPm.ROOT_PM_KEY}/${TestPm.PM3_ARGS.key}" to mutableMapOf() ), stateSaverFactory.pmStates ) diff --git a/premo-navigation/src/commonTest/kotlin/me.dmdev.premo/navigation/DialogNavigatorTest.kt b/premo-navigation/src/commonTest/kotlin/me.dmdev.premo/navigation/DialogNavigatorTest.kt index 62c17ecb..4ad1309c 100644 --- a/premo-navigation/src/commonTest/kotlin/me.dmdev.premo/navigation/DialogNavigatorTest.kt +++ b/premo-navigation/src/commonTest/kotlin/me.dmdev.premo/navigation/DialogNavigatorTest.kt @@ -1,7 +1,7 @@ /* * The MIT License (MIT) * - * Copyright (c) 2020-2023 Dmitriy Gorbunov (dmitriy.goto@gmail.com) + * Copyright (c) 2020-2024 Dmitriy Gorbunov (dmitriy.goto@gmail.com) * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -53,8 +53,8 @@ class DialogNavigatorTest { Dispatchers.setMain(Dispatchers.Unconfined) parentPm = TestPm.buildRootPm() parentPm.lifecycle.moveTo(IN_FOREGROUND) - dialogPm = parentPm.Child(TestPm.PM1_DESCRIPTION) - dialogPm2 = parentPm.Child(TestPm.PM2_DESCRIPTION) + dialogPm = parentPm.Child(TestPm.PM1_ARGS) + dialogPm2 = parentPm.Child(TestPm.PM2_ARGS) navigator = parentPm.DialogNavigator(DIALOG_KEY) } @@ -120,9 +120,9 @@ class DialogNavigatorTest { val stateSaverFactory = TestStateSaverFactory( initialState = mutableMapOf( TestPm.ROOT_PM_KEY to mutableMapOf( - DIALOG_KEY to TestPm.PM1_DESCRIPTION + DIALOG_KEY to TestPm.PM1_ARGS ), - "${TestPm.ROOT_PM_KEY}/${TestPm.PM1_DESCRIPTION.key}" to mutableMapOf() + "${TestPm.ROOT_PM_KEY}/${TestPm.PM1_ARGS.key}" to mutableMapOf() ) ) @@ -130,8 +130,8 @@ class DialogNavigatorTest { parentPm.lifecycle.moveTo(IN_FOREGROUND) val navigator = parentPm.DialogNavigator(DIALOG_KEY) - assertEquals(TestPm.PM1_DESCRIPTION, navigator.dialog?.description) - assertEquals(TestPm.PM1_DESCRIPTION, navigator.dialogFlow.value?.description) + assertEquals(TestPm.PM1_ARGS, navigator.dialog?.pmArgs) + assertEquals(TestPm.PM1_ARGS, navigator.dialogFlow.value?.pmArgs) assertEquals(IN_FOREGROUND, navigator.dialog?.lifecycle?.state) } @@ -140,7 +140,7 @@ class DialogNavigatorTest { val stateSaverFactory = TestStateSaverFactory() val parentPm = TestPm.buildRootPm(stateSaverFactory) - val dialogPm = parentPm.Child(TestPm.PM1_DESCRIPTION) + val dialogPm = parentPm.Child(TestPm.PM1_ARGS) val navigator = parentPm.DialogNavigator(DIALOG_KEY) parentPm.lifecycle.moveTo(IN_FOREGROUND) @@ -150,9 +150,9 @@ class DialogNavigatorTest { assertEquals( mutableMapOf( TestPm.ROOT_PM_KEY to mutableMapOf( - DIALOG_KEY to TestPm.PM1_DESCRIPTION + DIALOG_KEY to TestPm.PM1_ARGS ), - "${TestPm.ROOT_PM_KEY}/${TestPm.PM1_DESCRIPTION.key}" to mutableMapOf() + "${TestPm.ROOT_PM_KEY}/${TestPm.PM1_ARGS.key}" to mutableMapOf() ), stateSaverFactory.pmStates ) diff --git a/premo-navigation/src/commonTest/kotlin/me.dmdev.premo/navigation/MasterDetailNavigatorTest.kt b/premo-navigation/src/commonTest/kotlin/me.dmdev.premo/navigation/MasterDetailNavigatorTest.kt index 0b32f7e6..cf817732 100644 --- a/premo-navigation/src/commonTest/kotlin/me.dmdev.premo/navigation/MasterDetailNavigatorTest.kt +++ b/premo-navigation/src/commonTest/kotlin/me.dmdev.premo/navigation/MasterDetailNavigatorTest.kt @@ -1,7 +1,7 @@ /* * The MIT License (MIT) * - * Copyright (c) 2020-2023 Dmitriy Gorbunov (dmitriy.goto@gmail.com) + * Copyright (c) 2020-2024 Dmitriy Gorbunov (dmitriy.goto@gmail.com) * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -36,9 +36,9 @@ import kotlin.test.assertTrue class MasterDetailNavigatorTest { companion object { - private val MASTER_PM_DESCRIPTION = TestPm.Description("master_pm") - private val DETAIL_PM1_DESCRIPTION = TestPm.Description("detail_pm1") - private val DETAIL_PM2_DESCRIPTION = TestPm.Description("detail_pm2") + private val MASTER_PM_ARGS = TestPm.Args("master_pm") + private val DETAIL_PM1_ARGS = TestPm.Args("detail_pm1") + private val DETAIL_PM2_ARGS = TestPm.Args("detail_pm2") } private lateinit var navigator: MasterDetailNavigator @@ -50,16 +50,16 @@ class MasterDetailNavigatorTest { fun setUp() { parentPm = TestPm.buildRootPm() parentPm.lifecycle.moveTo(IN_FOREGROUND) - detailPm1 = parentPm.Child(DETAIL_PM1_DESCRIPTION) - detailPm2 = parentPm.Child(DETAIL_PM2_DESCRIPTION) + detailPm1 = parentPm.Child(DETAIL_PM1_ARGS) + detailPm2 = parentPm.Child(DETAIL_PM2_ARGS) navigator = parentPm.MasterDetailNavigator( - masterDescription = MASTER_PM_DESCRIPTION + masterPm = parentPm.Child(MASTER_PM_ARGS) ) } @Test fun testInitialState() { - assertEquals(MASTER_PM_DESCRIPTION, navigator.master.description) + assertEquals(MASTER_PM_ARGS, navigator.master.pmArgs) assertEquals(IN_FOREGROUND, navigator.master.lifecycle.state) assertNull(navigator.detail) } @@ -115,13 +115,13 @@ class MasterDetailNavigatorTest { @Test fun testRestoreState() { - val masterPmDescription = TestPm.Description("master_pm") - val detailPmDescription = TestPm.Description("detail_pm") + val masterPmArgs = TestPm.Args("master_pm") + val detailPmArgs = TestPm.Args("detail_pm") val stateSaverFactory = TestStateSaverFactory( initialState = mutableMapOf( TestPm.ROOT_PM_KEY to mutableMapOf( - DEFAULT_MASTER_DETAIL_NAVIGATOR_DETAIL_STATE_KEY to detailPmDescription + DEFAULT_MASTER_DETAIL_NAVIGATOR_DETAIL_STATE_KEY to detailPmArgs ) ) ) @@ -129,38 +129,38 @@ class MasterDetailNavigatorTest { val parentPm = TestPm.buildRootPm(stateSaverFactory) parentPm.lifecycle.moveTo(IN_FOREGROUND) val navigator: MasterDetailNavigator = parentPm.MasterDetailNavigator( - masterDescription = masterPmDescription + masterPm = parentPm.Child(masterPmArgs) ) - assertEquals(masterPmDescription, navigator.master.description) - assertEquals(detailPmDescription, navigator.detail?.description) + assertEquals(masterPmArgs, navigator.master.pmArgs) + assertEquals(detailPmArgs, navigator.detail?.pmArgs) assertEquals(IN_FOREGROUND, navigator.master.lifecycle.state) assertEquals(IN_FOREGROUND, navigator.detail?.lifecycle?.state) } @Test fun testSaveState() { - val masterPmDescription = TestPm.Description("master_pm") - val detailPmDescription = TestPm.Description("detail_pm") + val masterPmArgs = TestPm.Args("master_pm") + val detailPmArgs = TestPm.Args("detail_pm") val stateSaverFactory = TestStateSaverFactory() val parentPm = TestPm.buildRootPm(stateSaverFactory) parentPm.lifecycle.moveTo(IN_FOREGROUND) val navigator: MasterDetailNavigator = parentPm.MasterDetailNavigator( - masterDescription = masterPmDescription + masterPm = parentPm.Child(masterPmArgs) ) - navigator.changeDetail(parentPm.Child(detailPmDescription)) + navigator.changeDetail(parentPm.Child(detailPmArgs)) parentPm.stateHandler.saveState() assertEquals( mutableMapOf( TestPm.ROOT_PM_KEY to mutableMapOf( - DEFAULT_MASTER_DETAIL_NAVIGATOR_DETAIL_STATE_KEY to detailPmDescription + DEFAULT_MASTER_DETAIL_NAVIGATOR_DETAIL_STATE_KEY to detailPmArgs ), - "${TestPm.ROOT_PM_KEY}/${masterPmDescription.key}" to mutableMapOf(), - "${TestPm.ROOT_PM_KEY}/${detailPmDescription.key}" to mutableMapOf() + "${TestPm.ROOT_PM_KEY}/${masterPmArgs.key}" to mutableMapOf(), + "${TestPm.ROOT_PM_KEY}/${detailPmArgs.key}" to mutableMapOf() ), stateSaverFactory.pmStates ) diff --git a/premo-navigation/src/commonTest/kotlin/me.dmdev.premo/navigation/SetNavigatorTest.kt b/premo-navigation/src/commonTest/kotlin/me.dmdev.premo/navigation/SetNavigatorTest.kt index 73ddb003..b0980dff 100644 --- a/premo-navigation/src/commonTest/kotlin/me.dmdev.premo/navigation/SetNavigatorTest.kt +++ b/premo-navigation/src/commonTest/kotlin/me.dmdev.premo/navigation/SetNavigatorTest.kt @@ -1,7 +1,7 @@ /* * The MIT License (MIT) * - * Copyright (c) 2020-2023 Dmitriy Gorbunov (dmitriy.goto@gmail.com) + * Copyright (c) 2020-2024 Dmitriy Gorbunov (dmitriy.goto@gmail.com) * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -27,12 +27,13 @@ package me.dmdev.premo.navigation import me.dmdev.premo.PmLifecycle.State.CREATED import me.dmdev.premo.PmLifecycle.State.DESTROYED import me.dmdev.premo.PmLifecycle.State.IN_FOREGROUND -import me.dmdev.premo.navigation.TestPm.Companion.PM1_DESCRIPTION -import me.dmdev.premo.navigation.TestPm.Companion.PM2_DESCRIPTION -import me.dmdev.premo.navigation.TestPm.Companion.PM3_DESCRIPTION -import me.dmdev.premo.navigation.TestPm.Companion.PM4_DESCRIPTION -import me.dmdev.premo.navigation.TestPm.Companion.PM5_DESCRIPTION -import me.dmdev.premo.navigation.TestPm.Companion.PM6_DESCRIPTION +import me.dmdev.premo.childrenOf +import me.dmdev.premo.navigation.TestPm.Companion.PM1_ARGS +import me.dmdev.premo.navigation.TestPm.Companion.PM2_ARGS +import me.dmdev.premo.navigation.TestPm.Companion.PM3_ARGS +import me.dmdev.premo.navigation.TestPm.Companion.PM4_ARGS +import me.dmdev.premo.navigation.TestPm.Companion.PM5_ARGS +import me.dmdev.premo.navigation.TestPm.Companion.PM6_ARGS import kotlin.test.BeforeTest import kotlin.test.Test import kotlin.test.assertEquals @@ -52,13 +53,15 @@ class SetNavigatorTest { fun setUp() { parentPm = TestPm.buildRootPm() parentPm.lifecycle.moveTo(IN_FOREGROUND) - pm1 = parentPm.Child(PM1_DESCRIPTION) - pm2 = parentPm.Child(PM2_DESCRIPTION) - pm3 = parentPm.Child(PM3_DESCRIPTION) - pm4 = parentPm.Child(PM4_DESCRIPTION) - pm5 = parentPm.Child(PM5_DESCRIPTION) - pm6 = parentPm.Child(PM6_DESCRIPTION) - navigator = parentPm.SetNavigator() + pm1 = parentPm.Child(PM1_ARGS) + pm2 = parentPm.Child(PM2_ARGS) + pm3 = parentPm.Child(PM3_ARGS) + pm4 = parentPm.Child(PM4_ARGS) + pm5 = parentPm.Child(PM5_ARGS) + pm6 = parentPm.Child(PM6_ARGS) + navigator = parentPm.SetNavigator( + initValues = { listOf() } + ) navigator.changeValues(listOf(pm1, pm2, pm3)) } @@ -102,7 +105,9 @@ class SetNavigatorTest { @Test fun testEmptySetNavigator() { - val navigator = parentPm.SetNavigator() + val navigator = parentPm.SetNavigator( + initValues = { listOf() } + ) assertEquals(listOf(), navigator.values) assertEquals(null, navigator.current) @@ -110,7 +115,9 @@ class SetNavigatorTest { @Test fun testSetValuesToEmptyNavigator() { - val navigator = parentPm.SetNavigator() + val navigator = parentPm.SetNavigator( + initValues = { listOf() } + ) navigator.changeValues(listOf(pm1, pm2, pm3)) @@ -154,9 +161,9 @@ class SetNavigatorTest { initialState = mutableMapOf( TestPm.ROOT_PM_KEY to mutableMapOf( DEFAULT_SET_NAVIGATOR_STATE_VALUES_KEY to listOf( - PM1_DESCRIPTION, - PM2_DESCRIPTION, - PM3_DESCRIPTION + PM1_ARGS, + PM2_ARGS, + PM3_ARGS ), DEFAULT_SET_NAVIGATOR_STATE_CURRENT_INDEX_KEY to 0 ) @@ -165,7 +172,9 @@ class SetNavigatorTest { val parentPm = TestPm.buildRootPm(stateSaverFactory) parentPm.lifecycle.moveTo(IN_FOREGROUND) - val navigator = parentPm.SetNavigator() + val navigator = parentPm.SetNavigator( + initValues = { listOf() } + ) assertEquals( listOf(IN_FOREGROUND, CREATED, CREATED), @@ -173,8 +182,8 @@ class SetNavigatorTest { ) assertEquals( - listOf(PM1_DESCRIPTION, PM2_DESCRIPTION, PM3_DESCRIPTION), - navigator.values.map { it.description } + listOf(PM1_ARGS, PM2_ARGS, PM3_ARGS), + navigator.values.map { it.pmArgs } ) } @@ -184,7 +193,15 @@ class SetNavigatorTest { val parentPm = TestPm.buildRootPm(stateSaverFactory) parentPm.lifecycle.moveTo(IN_FOREGROUND) - val navigator = parentPm.SetNavigator(PM1_DESCRIPTION, PM2_DESCRIPTION, PM3_DESCRIPTION) + val navigator = parentPm.SetNavigator( + initValues = { + parentPm.childrenOf( + PM1_ARGS, + PM2_ARGS, + PM3_ARGS + ) + } + ) navigator.changeCurrent(1) parentPm.stateHandler.saveState() @@ -193,15 +210,15 @@ class SetNavigatorTest { mutableMapOf( TestPm.ROOT_PM_KEY to mutableMapOf( DEFAULT_SET_NAVIGATOR_STATE_VALUES_KEY to listOf( - PM1_DESCRIPTION, - PM2_DESCRIPTION, - PM3_DESCRIPTION + PM1_ARGS, + PM2_ARGS, + PM3_ARGS ), DEFAULT_SET_NAVIGATOR_STATE_CURRENT_INDEX_KEY to 1 ), - "${TestPm.ROOT_PM_KEY}/${PM1_DESCRIPTION.key}" to mutableMapOf(), - "${TestPm.ROOT_PM_KEY}/${PM2_DESCRIPTION.key}" to mutableMapOf(), - "${TestPm.ROOT_PM_KEY}/${PM3_DESCRIPTION.key}" to mutableMapOf() + "${TestPm.ROOT_PM_KEY}/${PM1_ARGS.key}" to mutableMapOf(), + "${TestPm.ROOT_PM_KEY}/${PM2_ARGS.key}" to mutableMapOf(), + "${TestPm.ROOT_PM_KEY}/${PM3_ARGS.key}" to mutableMapOf() ), stateSaverFactory.pmStates ) diff --git a/premo-navigation/src/commonTest/kotlin/me.dmdev.premo/navigation/StackNavigatorTest.kt b/premo-navigation/src/commonTest/kotlin/me.dmdev.premo/navigation/StackNavigatorTest.kt index 428756ac..842f2b01 100644 --- a/premo-navigation/src/commonTest/kotlin/me.dmdev.premo/navigation/StackNavigatorTest.kt +++ b/premo-navigation/src/commonTest/kotlin/me.dmdev.premo/navigation/StackNavigatorTest.kt @@ -1,7 +1,7 @@ /* * The MIT License (MIT) * - * Copyright (c) 2020-2023 Dmitriy Gorbunov (dmitriy.goto@gmail.com) + * Copyright (c) 2020-2024 Dmitriy Gorbunov (dmitriy.goto@gmail.com) * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -27,9 +27,10 @@ package me.dmdev.premo.navigation import me.dmdev.premo.PmLifecycle.State.CREATED import me.dmdev.premo.PmLifecycle.State.DESTROYED import me.dmdev.premo.PmLifecycle.State.IN_FOREGROUND -import me.dmdev.premo.navigation.TestPm.Companion.PM1_DESCRIPTION -import me.dmdev.premo.navigation.TestPm.Companion.PM2_DESCRIPTION -import me.dmdev.premo.navigation.TestPm.Companion.PM3_DESCRIPTION +import me.dmdev.premo.childrenOf +import me.dmdev.premo.navigation.TestPm.Companion.PM1_ARGS +import me.dmdev.premo.navigation.TestPm.Companion.PM2_ARGS +import me.dmdev.premo.navigation.TestPm.Companion.PM3_ARGS import kotlin.test.BeforeTest import kotlin.test.Test import kotlin.test.assertEquals @@ -49,9 +50,9 @@ class StackNavigatorTest { fun setUp() { parentPm = TestPm.buildRootPm() parentPm.lifecycle.moveTo(IN_FOREGROUND) - pm1 = parentPm.Child(PM1_DESCRIPTION) - pm2 = parentPm.Child(PM2_DESCRIPTION) - pm3 = parentPm.Child(PM3_DESCRIPTION) + pm1 = parentPm.Child(PM1_ARGS) + pm2 = parentPm.Child(PM2_ARGS) + pm3 = parentPm.Child(PM3_ARGS) navigator = parentPm.StackNavigator() } @@ -64,16 +65,23 @@ class StackNavigatorTest { @Test fun testInitialPm() { - val navigator = parentPm.StackNavigator(PM1_DESCRIPTION, PM2_DESCRIPTION, PM3_DESCRIPTION) - + val navigator = parentPm.StackNavigator( + initBackStack = { + parentPm.childrenOf( + PM1_ARGS, + PM2_ARGS, + PM3_ARGS + ) + } + ) assertEquals( listOf(CREATED, CREATED, IN_FOREGROUND), navigator.backStack.map { it.lifecycle.state } ) assertEquals( - listOf(PM1_DESCRIPTION, PM2_DESCRIPTION, PM3_DESCRIPTION), - navigator.backStack.map { it.description } + listOf(PM1_ARGS, PM2_ARGS, PM3_ARGS), + navigator.backStack.map { it.pmArgs } ) } @@ -269,9 +277,9 @@ class StackNavigatorTest { initialState = mutableMapOf( TestPm.ROOT_PM_KEY to mutableMapOf( DEFAULT_STACK_NAVIGATOR_BACKSTACK_STATE_KEY to listOf( - PM1_DESCRIPTION, - PM2_DESCRIPTION, - PM3_DESCRIPTION + PM1_ARGS, + PM2_ARGS, + PM3_ARGS ) ) ) @@ -287,8 +295,8 @@ class StackNavigatorTest { ) assertEquals( - listOf(PM1_DESCRIPTION, PM2_DESCRIPTION, PM3_DESCRIPTION), - navigator.backStack.map { it.description } + listOf(PM1_ARGS, PM2_ARGS, PM3_ARGS), + navigator.backStack.map { it.pmArgs } ) } @@ -298,7 +306,15 @@ class StackNavigatorTest { val parentPm = TestPm.buildRootPm(stateSaverFactory) parentPm.lifecycle.moveTo(IN_FOREGROUND) - val navigator = parentPm.StackNavigator(PM1_DESCRIPTION, PM2_DESCRIPTION, PM3_DESCRIPTION) + val navigator = parentPm.StackNavigator( + initBackStack = { + parentPm.childrenOf( + PM1_ARGS, + PM2_ARGS, + PM3_ARGS + ) + } + ) parentPm.stateHandler.saveState() @@ -306,14 +322,14 @@ class StackNavigatorTest { mutableMapOf( TestPm.ROOT_PM_KEY to mutableMapOf( DEFAULT_STACK_NAVIGATOR_BACKSTACK_STATE_KEY to listOf( - PM1_DESCRIPTION, - PM2_DESCRIPTION, - PM3_DESCRIPTION + PM1_ARGS, + PM2_ARGS, + PM3_ARGS ) ), - "${TestPm.ROOT_PM_KEY}/${PM1_DESCRIPTION.key}" to mutableMapOf(), - "${TestPm.ROOT_PM_KEY}/${PM2_DESCRIPTION.key}" to mutableMapOf(), - "${TestPm.ROOT_PM_KEY}/${PM3_DESCRIPTION.key}" to mutableMapOf() + "${TestPm.ROOT_PM_KEY}/${PM1_ARGS.key}" to mutableMapOf(), + "${TestPm.ROOT_PM_KEY}/${PM2_ARGS.key}" to mutableMapOf(), + "${TestPm.ROOT_PM_KEY}/${PM3_ARGS.key}" to mutableMapOf() ), stateSaverFactory.pmStates ) diff --git a/premo-navigation/src/commonTest/kotlin/me.dmdev.premo/navigation/TestPm.kt b/premo-navigation/src/commonTest/kotlin/me.dmdev.premo/navigation/TestPm.kt index b445f143..cdef71ce 100644 --- a/premo-navigation/src/commonTest/kotlin/me.dmdev.premo/navigation/TestPm.kt +++ b/premo-navigation/src/commonTest/kotlin/me.dmdev.premo/navigation/TestPm.kt @@ -1,7 +1,7 @@ /* * The MIT License (MIT) * - * Copyright (c) 2020-2023 Dmitriy Gorbunov (dmitriy.goto@gmail.com) + * Copyright (c) 2020-2024 Dmitriy Gorbunov (dmitriy.goto@gmail.com) * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -24,16 +24,15 @@ package me.dmdev.premo.navigation -import me.dmdev.premo.PmDescription +import me.dmdev.premo.PmArgs import me.dmdev.premo.PmMessage -import me.dmdev.premo.PmParams import me.dmdev.premo.PresentationModel -class TestPm(pmParams: PmParams) : PresentationModel(pmParams) { +class TestPm(args: Args) : PresentationModel(args) { - data class Description( + data class Args( override val key: String = "test_pm" - ) : PmDescription + ) : PmArgs() sealed class ResultMessage : PmMessage { data object Ok : ResultMessage() @@ -46,23 +45,20 @@ class TestPm(pmParams: PmParams) : PresentationModel(pmParams) { companion object { const val ROOT_PM_KEY = "root_pm" - private val ROOT_PM_DESCRIPTION = Description(ROOT_PM_KEY) - val PM1_DESCRIPTION = Description("pm1") - val PM2_DESCRIPTION = Description("pm2") - val PM3_DESCRIPTION = Description("pm3") - val PM4_DESCRIPTION = Description("pm4") - val PM5_DESCRIPTION = Description("pm5") - val PM6_DESCRIPTION = Description("pm6") + val PM1_ARGS = Args("pm1") + val PM2_ARGS = Args("pm2") + val PM3_ARGS = Args("pm3") + val PM4_ARGS = Args("pm4") + val PM5_ARGS = Args("pm5") + val PM6_ARGS = Args("pm6") - fun buildRootPm(stateSaverFactory: TestStateSaverFactory = TestStateSaverFactory()): TestPm { + fun buildRootPm(pmStateSaverFactory: TestStateSaverFactory = TestStateSaverFactory()): TestPm { return TestPm( - pmParams = PmParams( - description = ROOT_PM_DESCRIPTION, - parent = null, - factory = TestPmFactory(), - stateSaverFactory = stateSaverFactory - ) + Args(ROOT_PM_KEY).apply { + overridePmFactory(TestPmFactory()) + overridePmStateSaverFactory(pmStateSaverFactory) + } ) } } diff --git a/premo-navigation/src/commonTest/kotlin/me.dmdev.premo/navigation/TestPmFactory.kt b/premo-navigation/src/commonTest/kotlin/me.dmdev.premo/navigation/TestPmFactory.kt index 46277d28..93df9f73 100644 --- a/premo-navigation/src/commonTest/kotlin/me.dmdev.premo/navigation/TestPmFactory.kt +++ b/premo-navigation/src/commonTest/kotlin/me.dmdev.premo/navigation/TestPmFactory.kt @@ -1,7 +1,7 @@ /* * The MIT License (MIT) * - * Copyright (c) 2020-2023 Dmitriy Gorbunov (dmitriy.goto@gmail.com) + * Copyright (c) 2020-2024 Dmitriy Gorbunov (dmitriy.goto@gmail.com) * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -24,16 +24,16 @@ package me.dmdev.premo.navigation +import me.dmdev.premo.PmArgs import me.dmdev.premo.PmFactory -import me.dmdev.premo.PmParams import me.dmdev.premo.PresentationModel class TestPmFactory : PmFactory { - override fun createPm(params: PmParams): PresentationModel { - return when (params.description) { - is TestPm.Description -> TestPm(params) + override fun createPm(args: PmArgs): PresentationModel { + return when (args) { + is TestPm.Args -> TestPm(args) else -> throw IllegalArgumentException( - "Not handled instance creation for pm description ${params.description}" + "Not handled instance creation for pm args $args" ) } } diff --git a/premo-saver-json/src/commonMain/kotlin/me/dmdev/premo/saver/JsonPmStateSaver.kt b/premo-saver-json/src/commonMain/kotlin/me/dmdev/premo/saver/JsonPmStateSaver.kt index a857bc01..306c70c1 100644 --- a/premo-saver-json/src/commonMain/kotlin/me/dmdev/premo/saver/JsonPmStateSaver.kt +++ b/premo-saver-json/src/commonMain/kotlin/me/dmdev/premo/saver/JsonPmStateSaver.kt @@ -1,7 +1,7 @@ /* * The MIT License (MIT) * - * Copyright (c) 2020-2023 Dmitriy Gorbunov (dmitriy.goto@gmail.com) + * Copyright (c) 2020-2024 Dmitriy Gorbunov (dmitriy.goto@gmail.com) * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -30,7 +30,7 @@ import kotlinx.serialization.SerializationException import kotlinx.serialization.builtins.ListSerializer import kotlinx.serialization.json.Json import kotlinx.serialization.serializer -import me.dmdev.premo.PmDescription +import me.dmdev.premo.PmArgs import kotlin.reflect.KType @Suppress("UNCHECKED_CAST") @@ -47,7 +47,7 @@ class JsonPmStateSaver( } catch (e: SerializationException) { // Workaround for JS and Native https://github.com/Kotlin/kotlinx.serialization/issues/1077 try { - val serializer = polymorphicPmDescriptionSerializer as KSerializer + val serializer = polymorphicPmArgsSerializer as KSerializer map[key] = json.encodeToString(serializer, value) return } catch (_: Throwable) {} @@ -73,7 +73,7 @@ class JsonPmStateSaver( } catch (e: SerializationException) { // Workaround for JS and Native https://github.com/Kotlin/kotlinx.serialization/issues/1077 try { - val serializer = polymorphicPmDescriptionSerializer as KSerializer + val serializer = polymorphicPmArgsSerializer as KSerializer return json.decodeFromString(serializer, jsonString) } catch (_: Throwable) {} @@ -87,9 +87,9 @@ class JsonPmStateSaver( } } - private val polymorphicPmDescriptionSerializer = PolymorphicSerializer(PmDescription::class) + private val polymorphicPmArgsSerializer = PolymorphicSerializer(PmArgs::class) private val polymorphicListSerializer = ListSerializer( - PolymorphicSerializer(PmDescription::class) + PolymorphicSerializer(PmArgs::class) ) } diff --git a/premo/build.gradle.kts b/premo/build.gradle.kts index 79d1370c..ae3f95f5 100644 --- a/premo/build.gradle.kts +++ b/premo/build.gradle.kts @@ -38,6 +38,7 @@ kotlin { commonMain { dependencies { + api(libs.kotlinx.serialization.core) api(libs.kotlinx.coroutines.core) } } diff --git a/premo/src/androidMain/kotlin/me/dmdev/premo/AndroidPmDelegate.kt b/premo/src/androidMain/kotlin/me/dmdev/premo/AndroidPmDelegate.kt index 682ce4fa..030ec1e5 100644 --- a/premo/src/androidMain/kotlin/me/dmdev/premo/AndroidPmDelegate.kt +++ b/premo/src/androidMain/kotlin/me/dmdev/premo/AndroidPmDelegate.kt @@ -1,7 +1,7 @@ /* * The MIT License (MIT) * - * Copyright (c) 2020-2023 Dmitriy Gorbunov (dmitriy.goto@gmail.com) + * Copyright (c) 2020-2024 Dmitriy Gorbunov (dmitriy.goto@gmail.com) * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -31,19 +31,16 @@ import me.dmdev.premo.saver.BundleStateSaver class AndroidPmDelegate( private val pmActivity: Activity, - pmDescription: PmDescription, + pmArgs: PmArgs, pmFactory: PmFactory, private val pmStateSaver: BundleStateSaver ) { private val pmDelegate: PmDelegate by lazy { PmDelegate( - pmParams = PmParams( - description = pmDescription, - parent = null, - factory = pmFactory, - stateSaverFactory = pmStateSaver - ) + pmArgs = pmArgs, + pmFactory = pmFactory, + pmStateSaverFactory = pmStateSaver ) } diff --git a/premo/src/commonMain/kotlin/me/dmdev/premo/PmParams.kt b/premo/src/commonMain/kotlin/me/dmdev/premo/PmArgs.kt similarity index 63% rename from premo/src/commonMain/kotlin/me/dmdev/premo/PmParams.kt rename to premo/src/commonMain/kotlin/me/dmdev/premo/PmArgs.kt index 27e33197..4ed0f72b 100644 --- a/premo/src/commonMain/kotlin/me/dmdev/premo/PmParams.kt +++ b/premo/src/commonMain/kotlin/me/dmdev/premo/PmArgs.kt @@ -1,7 +1,7 @@ /* * The MIT License (MIT) * - * Copyright (c) 2020-2023 Dmitriy Gorbunov (dmitriy.goto@gmail.com) + * Copyright (c) 2020-2024 Dmitriy Gorbunov (dmitriy.goto@gmail.com) * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -24,11 +24,28 @@ package me.dmdev.premo +import kotlinx.serialization.Serializable +import kotlinx.serialization.Transient import me.dmdev.premo.saver.PmStateSaverFactory -class PmParams( - val description: PmDescription, - val parent: PresentationModel?, - val factory: PmFactory, - val stateSaverFactory: PmStateSaverFactory -) +@Serializable +abstract class PmArgs { + open val key: String get() = this::class.simpleName ?: "" + + @Transient + internal var parent: PresentationModel? = null + + @Transient + internal lateinit var pmFactory: PmFactory + + @Transient + internal lateinit var pmStateSaverFactory: PmStateSaverFactory + + fun overridePmFactory(pmFactory: PmFactory) { + this.pmFactory = pmFactory + } + + fun overridePmStateSaverFactory(pmStateSaverFactory: PmStateSaverFactory) { + this.pmStateSaverFactory = pmStateSaverFactory + } +} diff --git a/premo/src/commonMain/kotlin/me/dmdev/premo/PmDelegate.kt b/premo/src/commonMain/kotlin/me/dmdev/premo/PmDelegate.kt index bcdbc426..05d9227f 100644 --- a/premo/src/commonMain/kotlin/me/dmdev/premo/PmDelegate.kt +++ b/premo/src/commonMain/kotlin/me/dmdev/premo/PmDelegate.kt @@ -1,7 +1,7 @@ /* * The MIT License (MIT) * - * Copyright (c) 2020-2023 Dmitriy Gorbunov (dmitriy.goto@gmail.com) + * Copyright (c) 2020-2024 Dmitriy Gorbunov (dmitriy.goto@gmail.com) * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -27,15 +27,20 @@ package me.dmdev.premo import me.dmdev.premo.PmLifecycle.State.CREATED import me.dmdev.premo.PmLifecycle.State.DESTROYED import me.dmdev.premo.PmLifecycle.State.IN_FOREGROUND +import me.dmdev.premo.saver.PmStateSaverFactory class PmDelegate( - private val pmParams: PmParams + private val pmArgs: PmArgs, + private val pmFactory: PmFactory, + private val pmStateSaverFactory: PmStateSaverFactory ) { @Suppress("UNCHECKED_CAST") val presentationModel: PM by lazy { - val pm = PmStore[pmParams.description.key] as? PM ?: pmParams.factory.createPm(pmParams) as PM - PmStore[pmParams.description.key] = pm + pmArgs.pmFactory = pmFactory + pmArgs.pmStateSaverFactory = pmStateSaverFactory + val pm = PmStore[pmArgs.key] as? PM ?: pmArgs.pmFactory.createPm(pmArgs) as PM + PmStore[pmArgs.key] = pm pm } @@ -53,7 +58,7 @@ class PmDelegate( fun onDestroy() { presentationModel.lifecycle.moveTo(DESTROYED) - PmStore.remove(pmParams.description.key) + PmStore.remove(pmArgs.key) } fun onSave() { diff --git a/premo/src/commonMain/kotlin/me/dmdev/premo/PmDescription.kt b/premo/src/commonMain/kotlin/me/dmdev/premo/PmDescription.kt deleted file mode 100644 index 07672b55..00000000 --- a/premo/src/commonMain/kotlin/me/dmdev/premo/PmDescription.kt +++ /dev/null @@ -1,29 +0,0 @@ -/* - * The MIT License (MIT) - * - * Copyright (c) 2020-2023 Dmitriy Gorbunov (dmitriy.goto@gmail.com) - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package me.dmdev.premo - -interface PmDescription { - val key: String get() = this::class.simpleName ?: "" -} diff --git a/premo/src/commonMain/kotlin/me/dmdev/premo/PmFactory.kt b/premo/src/commonMain/kotlin/me/dmdev/premo/PmFactory.kt index 33e3eab4..4f3acc7e 100644 --- a/premo/src/commonMain/kotlin/me/dmdev/premo/PmFactory.kt +++ b/premo/src/commonMain/kotlin/me/dmdev/premo/PmFactory.kt @@ -1,7 +1,7 @@ /* * The MIT License (MIT) * - * Copyright (c) 2020-2023 Dmitriy Gorbunov (dmitriy.goto@gmail.com) + * Copyright (c) 2020-2024 Dmitriy Gorbunov (dmitriy.goto@gmail.com) * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -25,5 +25,5 @@ package me.dmdev.premo fun interface PmFactory { - fun createPm(params: PmParams): PresentationModel + fun createPm(args: PmArgs): PresentationModel } diff --git a/premo/src/commonMain/kotlin/me/dmdev/premo/PresentationModel.kt b/premo/src/commonMain/kotlin/me/dmdev/premo/PresentationModel.kt index eef9bd86..07cd92b9 100644 --- a/premo/src/commonMain/kotlin/me/dmdev/premo/PresentationModel.kt +++ b/premo/src/commonMain/kotlin/me/dmdev/premo/PresentationModel.kt @@ -31,20 +31,22 @@ import kotlinx.coroutines.flow.MutableStateFlow import me.dmdev.premo.PmLifecycle.State.CREATED import me.dmdev.premo.PmLifecycle.State.DESTROYED import me.dmdev.premo.PmLifecycle.State.IN_FOREGROUND +import me.dmdev.premo.saver.PmStateSaverFactory import kotlin.reflect.KType import kotlin.reflect.typeOf -abstract class PresentationModel(params: PmParams) { +abstract class PresentationModel( + val pmArgs: PmArgs +) { - private val pmFactory: PmFactory = params.factory - private val pmStateSaverFactory = params.stateSaverFactory + private val pmFactory: PmFactory = pmArgs.pmFactory + private val pmStateSaverFactory: PmStateSaverFactory = pmArgs.pmStateSaverFactory - val description: PmDescription = params.description - val parent: PresentationModel? = params.parent + val parent: PresentationModel? = pmArgs.parent val tag: String = if (parent != null) { - "${parent.tag}/${description.key}" + "${parent.tag}/${pmArgs.key}" } else { - description.key + pmArgs.key } val lifecycle: PmLifecycle = PmLifecycle() val scope: CoroutineScope = MainScope() @@ -72,15 +74,12 @@ abstract class PresentationModel(params: PmParams) { } @Suppress("FunctionName", "UNCHECKED_CAST") - fun Child(description: PmDescription): PM { - val config = PmParams( - parent = this, - description = description, - factory = pmFactory, - stateSaverFactory = pmStateSaverFactory - ) - - val childPm = pmFactory.createPm(config) as PM + fun Child(args: PmArgs): PM { + args.pmFactory = pmFactory + args.pmStateSaverFactory = pmStateSaverFactory + args.parent = this + + val childPm = pmFactory.createPm(args) as PM allChildren.add(childPm) return childPm } @@ -119,6 +118,12 @@ abstract class PresentationModel(params: PmParams) { } } +fun PresentationModel.childrenOf( + vararg args: PmArgs +): List { + return args.map { Child(it) } +} + fun PresentationModel.attachToParent() { parent?.attachChild(this) } @@ -128,8 +133,8 @@ fun PresentationModel.detachFromParent() { } @Suppress("FunctionName") -fun PresentationModel.AttachedChild(description: PmDescription): PM { - return Child(description).also { +fun PresentationModel.AttachedChild(args: PmArgs): PM { + return Child(args).also { attachChild(it) } } diff --git a/premo/src/commonTest/kotlin/me.dmdev.premo/PmDelegateTest.kt b/premo/src/commonTest/kotlin/me.dmdev.premo/PmDelegateTest.kt index 179e9cc1..385354d1 100644 --- a/premo/src/commonTest/kotlin/me.dmdev.premo/PmDelegateTest.kt +++ b/premo/src/commonTest/kotlin/me.dmdev.premo/PmDelegateTest.kt @@ -1,7 +1,7 @@ /* * The MIT License (MIT) * - * Copyright (c) 2020-2024 Dmitriy Gorbunov (dmitriy.goto@gmail.com) + * Copyright (c) 2020-2023 Dmitriy Gorbunov (dmitriy.goto@gmail.com) * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -43,12 +43,9 @@ class PmDelegateTest { fun setUp() { pmFactory = TestPmFactory() delegate = PmDelegate( - PmParams( - parent = null, - description = TestPm.Description(), - factory = pmFactory, - stateSaverFactory = NoPmStateSaverFactory - ) + pmArgs = TestPm.Args(), + pmFactory = pmFactory, + pmStateSaverFactory = NoPmStateSaverFactory ) } diff --git a/premo/src/commonTest/kotlin/me.dmdev.premo/PmStateSaverTest.kt b/premo/src/commonTest/kotlin/me.dmdev.premo/PmStateSaverTest.kt index 5a5eab0a..3cfed6ce 100644 --- a/premo/src/commonTest/kotlin/me.dmdev.premo/PmStateSaverTest.kt +++ b/premo/src/commonTest/kotlin/me.dmdev.premo/PmStateSaverTest.kt @@ -1,7 +1,7 @@ /* * The MIT License (MIT) * - * Copyright (c) 2020-2023 Dmitriy Gorbunov (dmitriy.goto@gmail.com) + * Copyright (c) 2020-2024 Dmitriy Gorbunov (dmitriy.goto@gmail.com) * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -62,25 +62,22 @@ class PmStateSaverTest { private fun createPmDelegate(): PmDelegate { return PmDelegate( - pmParams = PmParams( - parent = null, - description = RootPm.Description, - factory = MainPmFactory(), - stateSaverFactory = stateSaverFactory - ) + pmArgs = RootPm.Args, + pmFactory = MainPmFactory(), + pmStateSaverFactory = stateSaverFactory ) } } -private class RootPm(params: PmParams) : PresentationModel(params) { +private class RootPm(args: Args) : PresentationModel(args) { @Serializable - object Description : PmDescription + object Args : PmArgs() val keys = listOf("container1", "container2", "container3", "container4", "container5") val children: List = keys.map { key -> - Child(ContainerPm.Description) + Child(ContainerPm.Args) } override fun equals(other: Any?): Boolean { @@ -106,15 +103,15 @@ private class RootPm(params: PmParams) : PresentationModel(params) { } } -private class ContainerPm(params: PmParams) : PresentationModel(params) { +private class ContainerPm(args: Args) : PresentationModel(args) { @Serializable - object Description : PmDescription + object Args : PmArgs() val keys = listOf("child1", "child2", "child3", "child4", "child5") val children: List = keys.map { key -> - Child(ChildPm.Description(key)) + Child(ChildPm.Args(key)) } override fun equals(other: Any?): Boolean { @@ -140,12 +137,12 @@ private class ContainerPm(params: PmParams) : PresentationModel(params) { } } -private class ChildPm(params: PmParams) : PresentationModel(params) { +private class ChildPm(args: Args) : PresentationModel(args) { private val state = SaveableFlow("state", null) @Serializable - class Description(override val key: String) : PmDescription + class Args(override val key: String) : PmArgs() fun setNumber(number: Int) { state.value = State( @@ -187,12 +184,12 @@ private class ChildPm(params: PmParams) : PresentationModel(params) { } private class MainPmFactory : PmFactory { - override fun createPm(params: PmParams): PresentationModel { - return when (val description = params.description) { - is RootPm.Description -> RootPm(params) - is ContainerPm.Description -> ContainerPm(params) - is ChildPm.Description -> ChildPm(params) - else -> throw IllegalArgumentException("Not handled instance creation for pm description $description") + override fun createPm(args: PmArgs): PresentationModel { + return when (args) { + is RootPm.Args -> RootPm(args) + is ContainerPm.Args -> ContainerPm(args) + is ChildPm.Args -> ChildPm(args) + else -> throw IllegalArgumentException("Not handled instance creation for pm args $args") } } } @@ -236,19 +233,19 @@ class JsonPmStateSaver( val json = Json { serializersModule = SerializersModule { polymorphic( - PmDescription::class, - RootPm.Description::class, - RootPm.Description.serializer() + PmArgs::class, + RootPm.Args::class, + RootPm.Args.serializer() ) polymorphic( - PmDescription::class, - ContainerPm.Description::class, - ContainerPm.Description.serializer() + PmArgs::class, + ContainerPm.Args::class, + ContainerPm.Args.serializer() ) polymorphic( - PmDescription::class, - ChildPm.Description::class, - ChildPm.Description.serializer() + PmArgs::class, + ChildPm.Args::class, + ChildPm.Args.serializer() ) polymorphic( ChildPm.State::class, diff --git a/premo/src/commonTest/kotlin/me.dmdev.premo/PresentationModelTest.kt b/premo/src/commonTest/kotlin/me.dmdev.premo/PresentationModelTest.kt index af787071..e7e77b40 100644 --- a/premo/src/commonTest/kotlin/me.dmdev.premo/PresentationModelTest.kt +++ b/premo/src/commonTest/kotlin/me.dmdev.premo/PresentationModelTest.kt @@ -1,7 +1,7 @@ /* * The MIT License (MIT) * - * Copyright (c) 2020-2023 Dmitriy Gorbunov (dmitriy.goto@gmail.com) + * Copyright (c) 2020-2024 Dmitriy Gorbunov (dmitriy.goto@gmail.com) * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -77,8 +77,8 @@ class PresentationModelTest { @Test fun testNotAttachedChildrenLifecycle() { - val pm1 = pm.Child(TestPm.Description()) - val pm2 = pm.Child(TestPm.Description()) + val pm1 = pm.Child(TestPm.Args()) + val pm2 = pm.Child(TestPm.Args()) pm.lifecycle.moveTo(IN_FOREGROUND) @@ -88,8 +88,8 @@ class PresentationModelTest { @Test fun testAttachedChildrenLifecycle() { - val pm1 = pm.AttachedChild(TestPm.Description("pm1")) - val pm2 = pm.AttachedChild(TestPm.Description("pm2")) + val pm1 = pm.AttachedChild(TestPm.Args("pm1")) + val pm2 = pm.AttachedChild(TestPm.Args("pm2")) pm.lifecycle.moveTo(IN_FOREGROUND) diff --git a/premo/src/commonTest/kotlin/me.dmdev.premo/TestPm.kt b/premo/src/commonTest/kotlin/me.dmdev.premo/TestPm.kt index c9b8aa40..dbd1b364 100644 --- a/premo/src/commonTest/kotlin/me.dmdev.premo/TestPm.kt +++ b/premo/src/commonTest/kotlin/me.dmdev.premo/TestPm.kt @@ -27,15 +27,13 @@ package me.dmdev.premo import me.dmdev.premo.saver.NoPmStateSaverFactory class TestPm( - pmParams: PmParams = PmParams( - description = Description(), - parent = null, - factory = TestPmFactory(), - stateSaverFactory = NoPmStateSaverFactory - ) -) : PresentationModel(pmParams) { + args: Args = Args().apply { + overridePmFactory(TestPmFactory()) + overridePmStateSaverFactory(NoPmStateSaverFactory) + } +) : PresentationModel(args) { - data class Description( + data class Args( override val key: String = "test_pm" - ) : PmDescription + ) : PmArgs() } diff --git a/premo/src/commonTest/kotlin/me.dmdev.premo/TestPmFactory.kt b/premo/src/commonTest/kotlin/me.dmdev.premo/TestPmFactory.kt index c97b5aba..6635b567 100644 --- a/premo/src/commonTest/kotlin/me.dmdev.premo/TestPmFactory.kt +++ b/premo/src/commonTest/kotlin/me.dmdev.premo/TestPmFactory.kt @@ -1,7 +1,7 @@ /* * The MIT License (MIT) * - * Copyright (c) 2020-2023 Dmitriy Gorbunov (dmitriy.goto@gmail.com) + * Copyright (c) 2020-2024 Dmitriy Gorbunov (dmitriy.goto@gmail.com) * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -25,9 +25,9 @@ package me.dmdev.premo class TestPmFactory : PmFactory { - override fun createPm(params: PmParams): PresentationModel { - return when (params.description) { - is TestPm.Description -> TestPm(params) + override fun createPm(args: PmArgs): PresentationModel { + return when (args) { + is TestPm.Args -> TestPm(args) else -> throw IllegalArgumentException("") } } diff --git a/premo/src/iosMain/kotlin/me.dmdev.premo/IosPmDelegate.kt b/premo/src/iosMain/kotlin/me.dmdev.premo/IosPmDelegate.kt index 9832b4cf..bf55ea5d 100644 --- a/premo/src/iosMain/kotlin/me.dmdev.premo/IosPmDelegate.kt +++ b/premo/src/iosMain/kotlin/me.dmdev.premo/IosPmDelegate.kt @@ -1,7 +1,7 @@ /* * The MIT License (MIT) * - * Copyright (c) 2020-2023 Dmitriy Gorbunov (dmitriy.goto@gmail.com) + * Copyright (c) 2020-2024 Dmitriy Gorbunov (dmitriy.goto@gmail.com) * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -29,19 +29,16 @@ import platform.Foundation.NSCoder @Suppress("unused") class IosPmDelegate( - pmDescription: PmDescription, + pmArgs: PmArgs, pmFactory: PmFactory, private val pmStateSaver: NSCoderStateSaver ) { private val pmDelegate: PmDelegate by lazy { PmDelegate( - pmParams = PmParams( - description = pmDescription, - parent = null, - factory = pmFactory, - stateSaverFactory = pmStateSaver - ) + pmArgs = pmArgs, + pmFactory = pmFactory, + pmStateSaverFactory = pmStateSaver ) } diff --git a/premo/src/jsMain/kotlin/me.dmdev.premo/JsPmDelegate.kt b/premo/src/jsMain/kotlin/me.dmdev.premo/JsPmDelegate.kt index acdf04e7..b4302eb4 100644 --- a/premo/src/jsMain/kotlin/me.dmdev.premo/JsPmDelegate.kt +++ b/premo/src/jsMain/kotlin/me.dmdev.premo/JsPmDelegate.kt @@ -1,7 +1,7 @@ /* * The MIT License (MIT) * - * Copyright (c) 2020-2023 Dmitriy Gorbunov (dmitriy.goto@gmail.com) + * Copyright (c) 2020-2024 Dmitriy Gorbunov (dmitriy.goto@gmail.com) * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -33,19 +33,16 @@ import org.w3c.dom.get import org.w3c.dom.set class JsPmDelegate( - pmDescription: PmDescription, + pmArgs: PmArgs, pmFactory: PmFactory, private val pmStateSaver: StringStateSaver ) { private val pmDelegate: PmDelegate by lazy { PmDelegate( - pmParams = PmParams( - description = pmDescription, - parent = null, - factory = pmFactory, - stateSaverFactory = pmStateSaver - ) + pmArgs = pmArgs, + pmFactory = pmFactory, + pmStateSaverFactory = pmStateSaver ) } diff --git a/premo/src/jvmMain/kotlin/me/dmdev/premo/JvmPmDelegate.kt b/premo/src/jvmMain/kotlin/me/dmdev/premo/JvmPmDelegate.kt index f301eb23..68bfc618 100644 --- a/premo/src/jvmMain/kotlin/me/dmdev/premo/JvmPmDelegate.kt +++ b/premo/src/jvmMain/kotlin/me/dmdev/premo/JvmPmDelegate.kt @@ -1,7 +1,7 @@ /* * The MIT License (MIT) * - * Copyright (c) 2020-2023 Dmitriy Gorbunov (dmitriy.goto@gmail.com) + * Copyright (c) 2020-2024 Dmitriy Gorbunov (dmitriy.goto@gmail.com) * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -28,20 +28,17 @@ import me.dmdev.premo.saver.FileStateSaver import java.io.File class JvmPmDelegate( - pmDescription: PmDescription, + pmArgs: PmArgs, pmFactory: PmFactory, private val pmStateSaver: FileStateSaver, private val pmStateFile: File = File("pm_state.txt") ) { private val pmDelegate: PmDelegate by lazy { - PmDelegate( - pmParams = PmParams( - description = pmDescription, - parent = null, - factory = pmFactory, - stateSaverFactory = pmStateSaver - ) + PmDelegate( + pmArgs = pmArgs, + pmFactory = pmFactory, + pmStateSaverFactory = pmStateSaver ) } diff --git a/sample/app-common/src/commonMain/kotlin/me/dmdev/premo/sample/CounterPm.kt b/sample/app-common/src/commonMain/kotlin/me/dmdev/premo/sample/CounterPm.kt index da20e167..6758823d 100644 --- a/sample/app-common/src/commonMain/kotlin/me/dmdev/premo/sample/CounterPm.kt +++ b/sample/app-common/src/commonMain/kotlin/me/dmdev/premo/sample/CounterPm.kt @@ -1,7 +1,7 @@ /* * The MIT License (MIT) * - * Copyright (c) 2020-2023 Dmitriy Gorbunov (dmitriy.goto@gmail.com) + * Copyright (c) 2020-2024 Dmitriy Gorbunov (dmitriy.goto@gmail.com) * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -27,18 +27,16 @@ package me.dmdev.premo.sample import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.asStateFlow import kotlinx.serialization.Serializable -import me.dmdev.premo.PmDescription -import me.dmdev.premo.PmParams +import me.dmdev.premo.PmArgs import me.dmdev.premo.PresentationModel import me.dmdev.premo.SaveableFlow class CounterPm( - maxCount: Int, - params: PmParams -) : PresentationModel(params) { + args: Args +) : PresentationModel(args) { @Serializable - data class Description(val maxCount: Int) : PmDescription + data class Args(val maxCount: Int) : PmArgs() @Serializable data class State( @@ -51,7 +49,7 @@ class CounterPm( private val _stateFlow = SaveableFlow( key = "count", - initialValue = State(maxCount = maxCount, count = 0) + initialValue = State(maxCount = args.maxCount, count = 0) ) val stateFlow: StateFlow = _stateFlow.asStateFlow() val state: State get() = stateFlow.value diff --git a/sample/app-common/src/commonMain/kotlin/me/dmdev/premo/sample/MainPm.kt b/sample/app-common/src/commonMain/kotlin/me/dmdev/premo/sample/MainPm.kt index cce306e2..c3694486 100644 --- a/sample/app-common/src/commonMain/kotlin/me/dmdev/premo/sample/MainPm.kt +++ b/sample/app-common/src/commonMain/kotlin/me/dmdev/premo/sample/MainPm.kt @@ -1,7 +1,7 @@ /* * The MIT License (MIT) * - * Copyright (c) 2020-2023 Dmitriy Gorbunov (dmitriy.goto@gmail.com) + * Copyright (c) 2020-2024 Dmitriy Gorbunov (dmitriy.goto@gmail.com) * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -25,8 +25,7 @@ package me.dmdev.premo.sample import kotlinx.serialization.Serializable -import me.dmdev.premo.PmDescription -import me.dmdev.premo.PmParams +import me.dmdev.premo.PmArgs import me.dmdev.premo.PresentationModel import me.dmdev.premo.navigation.MasterDetailNavigation import me.dmdev.premo.onMessage @@ -34,25 +33,25 @@ import me.dmdev.premo.sample.bottomnavigation.BottomNavigationPm import me.dmdev.premo.sample.dilaognavigation.DialogNavigationPm import me.dmdev.premo.sample.stacknavigation.StackNavigationPm -class MainPm(params: PmParams) : PresentationModel(params) { +class MainPm(args: PmArgs) : PresentationModel(args) { @Serializable - object Description : PmDescription + object Args : PmArgs() val navigation = MasterDetailNavigation( - masterDescription = SamplesPm.Description + masterPm = Child(SamplesPm.Args) ) { navigator -> onMessage { - navigator.changeDetail(Child(CounterPm.Description(10))) + navigator.changeDetail(Child(CounterPm.Args(10))) } onMessage { - navigator.changeDetail(Child(StackNavigationPm.Description)) + navigator.changeDetail(Child(StackNavigationPm.Args)) } onMessage { - navigator.changeDetail(Child(BottomNavigationPm.Description)) + navigator.changeDetail(Child(BottomNavigationPm.Args)) } onMessage { - navigator.changeDetail(Child(DialogNavigationPm.Description)) + navigator.changeDetail(Child(DialogNavigationPm.Args)) } } } diff --git a/sample/app-common/src/commonMain/kotlin/me/dmdev/premo/sample/MainPmFactory.kt b/sample/app-common/src/commonMain/kotlin/me/dmdev/premo/sample/MainPmFactory.kt index 13077df7..154df360 100644 --- a/sample/app-common/src/commonMain/kotlin/me/dmdev/premo/sample/MainPmFactory.kt +++ b/sample/app-common/src/commonMain/kotlin/me/dmdev/premo/sample/MainPmFactory.kt @@ -1,7 +1,7 @@ /* * The MIT License (MIT) * - * Copyright (c) 2020-2023 Dmitriy Gorbunov (dmitriy.goto@gmail.com) + * Copyright (c) 2020-2024 Dmitriy Gorbunov (dmitriy.goto@gmail.com) * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -24,8 +24,8 @@ package me.dmdev.premo.sample +import me.dmdev.premo.PmArgs import me.dmdev.premo.PmFactory -import me.dmdev.premo.PmParams import me.dmdev.premo.PresentationModel import me.dmdev.premo.sample.bottomnavigation.BottomNavigationPm import me.dmdev.premo.sample.bottomnavigation.TabItemPm @@ -36,25 +36,19 @@ import me.dmdev.premo.sample.stacknavigation.SimpleScreenPm import me.dmdev.premo.sample.stacknavigation.StackNavigationPm class MainPmFactory : PmFactory { - override fun createPm(params: PmParams): PresentationModel { - return when (val description = params.description) { - is MainPm.Description -> MainPm(params) - is SamplesPm.Description -> SamplesPm(params) - is CounterPm.Description -> CounterPm(description.maxCount, params) - is StackNavigationPm.Description -> StackNavigationPm(params) - is SimpleScreenPm.Description -> SimpleScreenPm(description.number, params) - is BottomNavigationPm.Description -> BottomNavigationPm(params) - is TabPm.Description -> TabPm(description.tabTitle, params) - is TabItemPm.Description -> TabItemPm(description.screenTitle, description.tabTitle, params) - is DialogNavigationPm.Description -> DialogNavigationPm(params) - is SimpleDialogPm.Description -> SimpleDialogPm( - description.title, - description.message, - description.okButtonText, - description.cancelButtonText, - params - ) - else -> throw IllegalArgumentException("Not handled instance creation for pm description $description") + override fun createPm(args: PmArgs): PresentationModel { + return when (args) { + is MainPm.Args -> MainPm(args) + is SamplesPm.Args -> SamplesPm(args) + is CounterPm.Args -> CounterPm(args) + is StackNavigationPm.Args -> StackNavigationPm(args) + is SimpleScreenPm.Args -> SimpleScreenPm(args) + is BottomNavigationPm.Args -> BottomNavigationPm(args) + is TabPm.Args -> TabPm(args) + is TabItemPm.Args -> TabItemPm(args) + is DialogNavigationPm.Args -> DialogNavigationPm(args) + is SimpleDialogPm.Args -> SimpleDialogPm(args) + else -> throw IllegalArgumentException("Not handled instance creation for pm args $args") } } } diff --git a/sample/app-common/src/commonMain/kotlin/me/dmdev/premo/sample/PremoSample.kt b/sample/app-common/src/commonMain/kotlin/me/dmdev/premo/sample/PremoSample.kt index 8f3290ab..1f33cf0e 100644 --- a/sample/app-common/src/commonMain/kotlin/me/dmdev/premo/sample/PremoSample.kt +++ b/sample/app-common/src/commonMain/kotlin/me/dmdev/premo/sample/PremoSample.kt @@ -1,7 +1,7 @@ /* * The MIT License (MIT) * - * Copyright (c) 2020-2023 Dmitriy Gorbunov (dmitriy.goto@gmail.com) + * Copyright (c) 2020-2024 Dmitriy Gorbunov (dmitriy.goto@gmail.com) * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -25,7 +25,6 @@ package me.dmdev.premo.sample import me.dmdev.premo.PmDelegate -import me.dmdev.premo.PmParams import me.dmdev.premo.sample.serialization.SimpleJsonPmStateSaverFactory import me.dmdev.premo.saver.PmStateSaverFactory @@ -33,11 +32,8 @@ object PremoSample { fun createPmDelegate( pmStateSaver: PmStateSaverFactory = SimpleJsonPmStateSaverFactory() ): PmDelegate = PmDelegate( - pmParams = PmParams( - description = MainPm.Description, - parent = null, - factory = MainPmFactory(), - stateSaverFactory = pmStateSaver - ) + pmArgs = MainPm.Args, + pmFactory = MainPmFactory(), + pmStateSaverFactory = pmStateSaver ) } diff --git a/sample/app-common/src/commonMain/kotlin/me/dmdev/premo/sample/SamplesPm.kt b/sample/app-common/src/commonMain/kotlin/me/dmdev/premo/sample/SamplesPm.kt index 654f53f0..49121c32 100644 --- a/sample/app-common/src/commonMain/kotlin/me/dmdev/premo/sample/SamplesPm.kt +++ b/sample/app-common/src/commonMain/kotlin/me/dmdev/premo/sample/SamplesPm.kt @@ -1,7 +1,7 @@ /* * The MIT License (MIT) * - * Copyright (c) 2020-2023 Dmitriy Gorbunov (dmitriy.goto@gmail.com) + * Copyright (c) 2020-2024 Dmitriy Gorbunov (dmitriy.goto@gmail.com) * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -25,14 +25,13 @@ package me.dmdev.premo.sample import kotlinx.serialization.Serializable -import me.dmdev.premo.PmDescription -import me.dmdev.premo.PmParams +import me.dmdev.premo.PmArgs import me.dmdev.premo.PresentationModel -class SamplesPm(params: PmParams) : PresentationModel(params) { +class SamplesPm(args: Args) : PresentationModel(args) { @Serializable - object Description : PmDescription + object Args : PmArgs() fun counterSample() { messageHandler.send(CounterSampleMessage) diff --git a/sample/app-common/src/commonMain/kotlin/me/dmdev/premo/sample/Stubs.kt b/sample/app-common/src/commonMain/kotlin/me/dmdev/premo/sample/Stubs.kt index 4b9b27ad..852d2c61 100644 --- a/sample/app-common/src/commonMain/kotlin/me/dmdev/premo/sample/Stubs.kt +++ b/sample/app-common/src/commonMain/kotlin/me/dmdev/premo/sample/Stubs.kt @@ -1,7 +1,7 @@ /* * The MIT License (MIT) * - * Copyright (c) 2020-2023 Dmitriy Gorbunov (dmitriy.goto@gmail.com) + * Copyright (c) 2020-2024 Dmitriy Gorbunov (dmitriy.goto@gmail.com) * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -24,44 +24,35 @@ package me.dmdev.premo.sample -import me.dmdev.premo.PmDescription -import me.dmdev.premo.PmParams +import me.dmdev.premo.PmArgs import me.dmdev.premo.PresentationModel import me.dmdev.premo.sample.bottomnavigation.BottomNavigationPm import me.dmdev.premo.sample.bottomnavigation.TabItemPm import me.dmdev.premo.sample.bottomnavigation.TabPm import me.dmdev.premo.sample.dilaognavigation.DialogNavigationPm import me.dmdev.premo.sample.dilaognavigation.SimpleDialogPm -import me.dmdev.premo.sample.serialization.Serializers import me.dmdev.premo.sample.stacknavigation.SimpleScreenPm import me.dmdev.premo.sample.stacknavigation.StackNavigationPm -import me.dmdev.premo.saver.JsonStateSaver object Stubs { private val mainPmFactory = MainPmFactory() - val mainPm = createPm(MainPm.Description) - val samplesPm = createPm(SamplesPm.Description) - val counterPm = createPm(CounterPm.Description(10)) - val stackNavigationPm = createPm(StackNavigationPm.Description) - val simplePm = createPm(SimpleScreenPm.Description(1)) - val bottomBarPm = createPm(BottomNavigationPm.Description) - val tabPm = createPm(TabPm.Description("Tab #")) - val tabItemPm = createPm(TabItemPm.Description("Screen #", "Tab #")) - val dialogNavigationPm = createPm(DialogNavigationPm.Description) + val mainPm = createPm(MainPm.Args) + val samplesPm = createPm(SamplesPm.Args) + val counterPm = createPm(CounterPm.Args(10)) + val stackNavigationPm = createPm(StackNavigationPm.Args) + val simplePm = createPm(SimpleScreenPm.Args(1)) + val bottomBarPm = createPm(BottomNavigationPm.Args) + val tabPm = createPm(TabPm.Args("Tab #")) + val tabItemPm = createPm(TabItemPm.Args("Screen #", "Tab #")) + val dialogNavigationPm = createPm(DialogNavigationPm.Args) val simpleDialogPm = createPm( - SimpleDialogPm.Description("Title", "Text", "Ок", "Cancel") + SimpleDialogPm.Args("Title", "Text", "Ок", "Cancel") ) - private fun createPm(description: PmDescription): PM { - val config = PmParams( - parent = null, - description = description, - factory = mainPmFactory, - stateSaverFactory = JsonStateSaver(Serializers.json) - ) + private fun createPm(args: PmArgs): PM { @Suppress("UNCHECKED_CAST") - return mainPmFactory.createPm(config) as PM + return mainPmFactory.createPm(args) as PM } } diff --git a/sample/app-common/src/commonMain/kotlin/me/dmdev/premo/sample/bottomnavigation/BottomNavigationPm.kt b/sample/app-common/src/commonMain/kotlin/me/dmdev/premo/sample/bottomnavigation/BottomNavigationPm.kt index 921a1857..04f2dca1 100644 --- a/sample/app-common/src/commonMain/kotlin/me/dmdev/premo/sample/bottomnavigation/BottomNavigationPm.kt +++ b/sample/app-common/src/commonMain/kotlin/me/dmdev/premo/sample/bottomnavigation/BottomNavigationPm.kt @@ -1,7 +1,7 @@ /* * The MIT License (MIT) * - * Copyright (c) 2020-2023 Dmitriy Gorbunov (dmitriy.goto@gmail.com) + * Copyright (c) 2020-2024 Dmitriy Gorbunov (dmitriy.goto@gmail.com) * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -25,19 +25,23 @@ package me.dmdev.premo.sample.bottomnavigation import kotlinx.serialization.Serializable -import me.dmdev.premo.PmDescription -import me.dmdev.premo.PmParams +import me.dmdev.premo.PmArgs import me.dmdev.premo.PresentationModel +import me.dmdev.premo.childrenOf import me.dmdev.premo.navigation.SetNavigation -class BottomNavigationPm(params: PmParams) : PresentationModel(params) { +class BottomNavigationPm(args: Args) : PresentationModel(args) { @Serializable - object Description : PmDescription + object Args : PmArgs() val navigation = SetNavigation( - TabPm.Description("Tab #1"), - TabPm.Description("Tab #2"), - TabPm.Description("Tab #3") + initValues = { + childrenOf( + TabPm.Args("Tab #1"), + TabPm.Args("Tab #2"), + TabPm.Args("Tab #3") + ) + } ) } diff --git a/sample/app-common/src/commonMain/kotlin/me/dmdev/premo/sample/bottomnavigation/TabItemPm.kt b/sample/app-common/src/commonMain/kotlin/me/dmdev/premo/sample/bottomnavigation/TabItemPm.kt index ef2b37ab..c689fa43 100644 --- a/sample/app-common/src/commonMain/kotlin/me/dmdev/premo/sample/bottomnavigation/TabItemPm.kt +++ b/sample/app-common/src/commonMain/kotlin/me/dmdev/premo/sample/bottomnavigation/TabItemPm.kt @@ -1,7 +1,7 @@ /* * The MIT License (MIT) * - * Copyright (c) 2020-2023 Dmitriy Gorbunov (dmitriy.goto@gmail.com) + * Copyright (c) 2020-2024 Dmitriy Gorbunov (dmitriy.goto@gmail.com) * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -25,23 +25,22 @@ package me.dmdev.premo.sample.bottomnavigation import kotlinx.serialization.Serializable -import me.dmdev.premo.PmDescription -import me.dmdev.premo.PmParams +import me.dmdev.premo.PmArgs import me.dmdev.premo.PresentationModel import me.dmdev.premo.sample.NextClickMessage import me.dmdev.premo.sample.PreviousClickMessage class TabItemPm( - val screenTitle: String, - val tabTitle: String, - params: PmParams -) : PresentationModel(params) { + args: Args +) : PresentationModel(args) { + + val title: String = args.screenTitle @Serializable - class Description( + class Args( val screenTitle: String, val tabTitle: String - ) : PmDescription { + ) : PmArgs() { override val key: String get() = "$tabTitle/$screenTitle" } diff --git a/sample/app-common/src/commonMain/kotlin/me/dmdev/premo/sample/bottomnavigation/TabPm.kt b/sample/app-common/src/commonMain/kotlin/me/dmdev/premo/sample/bottomnavigation/TabPm.kt index ee621988..ebacfc58 100644 --- a/sample/app-common/src/commonMain/kotlin/me/dmdev/premo/sample/bottomnavigation/TabPm.kt +++ b/sample/app-common/src/commonMain/kotlin/me/dmdev/premo/sample/bottomnavigation/TabPm.kt @@ -1,7 +1,7 @@ /* * The MIT License (MIT) * - * Copyright (c) 2020-2023 Dmitriy Gorbunov (dmitriy.goto@gmail.com) + * Copyright (c) 2020-2024 Dmitriy Gorbunov (dmitriy.goto@gmail.com) * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -25,9 +25,9 @@ package me.dmdev.premo.sample.bottomnavigation import kotlinx.serialization.Serializable -import me.dmdev.premo.PmDescription -import me.dmdev.premo.PmParams +import me.dmdev.premo.PmArgs import me.dmdev.premo.PresentationModel +import me.dmdev.premo.childrenOf import me.dmdev.premo.handle import me.dmdev.premo.navigation.BackMessage import me.dmdev.premo.navigation.StackNavigation @@ -39,28 +39,33 @@ import me.dmdev.premo.sample.NextClickMessage import me.dmdev.premo.sample.PreviousClickMessage class TabPm( - val tabTitle: String, - params: PmParams -) : PresentationModel(params) { + args: Args +) : PresentationModel(args) { + + val title: String = args.tabTitle @Serializable - class Description( + data class Args( val tabTitle: String - ) : PmDescription { + ) : PmArgs() { override val key: String get() = tabTitle } private var number: Int = 1 val navigation = StackNavigation( - initialDescription = TabItemPm.Description(nextScreenTitle(), tabTitle) + initBackStack = { + childrenOf( + TabItemPm.Args(nextScreenTitle(), args.tabTitle) + ) + } ) { navigator -> onMessage { navigator.push( Child( - TabItemPm.Description( + TabItemPm.Args( screenTitle = nextScreenTitle(), - tabTitle = tabTitle + tabTitle = args.tabTitle ) ) ) diff --git a/sample/app-common/src/commonMain/kotlin/me/dmdev/premo/sample/dilaognavigation/DialogNavigationPm.kt b/sample/app-common/src/commonMain/kotlin/me/dmdev/premo/sample/dilaognavigation/DialogNavigationPm.kt index cf6f8d02..1f761471 100644 --- a/sample/app-common/src/commonMain/kotlin/me/dmdev/premo/sample/dilaognavigation/DialogNavigationPm.kt +++ b/sample/app-common/src/commonMain/kotlin/me/dmdev/premo/sample/dilaognavigation/DialogNavigationPm.kt @@ -1,7 +1,7 @@ /* * The MIT License (MIT) * - * Copyright (c) 2020-2023 Dmitriy Gorbunov (dmitriy.goto@gmail.com) + * Copyright (c) 2020-2024 Dmitriy Gorbunov (dmitriy.goto@gmail.com) * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -26,19 +26,18 @@ package me.dmdev.premo.sample.dilaognavigation import kotlinx.coroutines.launch import kotlinx.serialization.Serializable -import me.dmdev.premo.PmDescription -import me.dmdev.premo.PmParams +import me.dmdev.premo.PmArgs import me.dmdev.premo.PresentationModel import me.dmdev.premo.navigation.DialogGroupNavigation import me.dmdev.premo.navigation.DialogNavigator import me.dmdev.premo.sample.dilaognavigation.SimpleDialogPm.ResultMessage class DialogNavigationPm( - params: PmParams -) : PresentationModel(params) { + args: Args +) : PresentationModel(args) { @Serializable - object Description : PmDescription + object Args : PmArgs() private val simpleDialog = DialogNavigator("simple_dialog") private val dialogForResult = DialogNavigator("dialog_for_result") { result -> @@ -50,7 +49,7 @@ class DialogNavigationPm( showResultDialog.show( Child( - SimpleDialogPm.Description( + SimpleDialogPm.Args( title = "Dialog Result", message = resultMessage, okButtonText = "Close", @@ -70,7 +69,7 @@ class DialogNavigationPm( fun showSimpleDialogClick() { simpleDialog.show( Child( - SimpleDialogPm.Description( + SimpleDialogPm.Args( title = "Simple dialog", message = "This is a simple dialog, click ok to close.", okButtonText = "Ok", @@ -84,7 +83,7 @@ class DialogNavigationPm( inForegroundScope?.launch { dialogForResult.show( Child( - SimpleDialogPm.Description( + SimpleDialogPm.Args( title = "Simple result dialog", message = "This is a simple dialog that sends a result message to show which button is clicked.", okButtonText = "Ok", diff --git a/sample/app-common/src/commonMain/kotlin/me/dmdev/premo/sample/dilaognavigation/SimpleDialogPm.kt b/sample/app-common/src/commonMain/kotlin/me/dmdev/premo/sample/dilaognavigation/SimpleDialogPm.kt index c7e6180e..c2b197bb 100644 --- a/sample/app-common/src/commonMain/kotlin/me/dmdev/premo/sample/dilaognavigation/SimpleDialogPm.kt +++ b/sample/app-common/src/commonMain/kotlin/me/dmdev/premo/sample/dilaognavigation/SimpleDialogPm.kt @@ -1,7 +1,7 @@ /* * The MIT License (MIT) * - * Copyright (c) 2020-2023 Dmitriy Gorbunov (dmitriy.goto@gmail.com) + * Copyright (c) 2020-2024 Dmitriy Gorbunov (dmitriy.goto@gmail.com) * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -25,26 +25,21 @@ package me.dmdev.premo.sample.dilaognavigation import kotlinx.serialization.Serializable -import me.dmdev.premo.PmDescription +import me.dmdev.premo.PmArgs import me.dmdev.premo.PmMessage -import me.dmdev.premo.PmParams import me.dmdev.premo.PresentationModel class SimpleDialogPm( - val title: String, - val message: String, - val okButtonText: String, - val cancelButtonText: String, - params: PmParams -) : PresentationModel(params) { + val args: Args +) : PresentationModel(args) { @Serializable - data class Description( + data class Args( val title: String, val message: String, val okButtonText: String, val cancelButtonText: String - ) : PmDescription + ) : PmArgs() sealed interface ResultMessage : PmMessage data object Ok : ResultMessage diff --git a/sample/app-common/src/commonMain/kotlin/me/dmdev/premo/sample/serialization/Serializers.kt b/sample/app-common/src/commonMain/kotlin/me/dmdev/premo/sample/serialization/Serializers.kt index aeb1185a..bc2e2424 100644 --- a/sample/app-common/src/commonMain/kotlin/me/dmdev/premo/sample/serialization/Serializers.kt +++ b/sample/app-common/src/commonMain/kotlin/me/dmdev/premo/sample/serialization/Serializers.kt @@ -1,7 +1,7 @@ /* * The MIT License (MIT) * - * Copyright (c) 2020-2023 Dmitriy Gorbunov (dmitriy.goto@gmail.com) + * Copyright (c) 2020-2024 Dmitriy Gorbunov (dmitriy.goto@gmail.com) * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -31,7 +31,7 @@ import kotlinx.serialization.modules.SerializersModule import kotlinx.serialization.modules.polymorphic import kotlinx.serialization.modules.subclass import kotlinx.serialization.protobuf.ProtoBuf -import me.dmdev.premo.PmDescription +import me.dmdev.premo.PmArgs import me.dmdev.premo.sample.CounterPm import me.dmdev.premo.sample.MainPm import me.dmdev.premo.sample.SamplesPm @@ -46,7 +46,7 @@ import me.dmdev.premo.sample.stacknavigation.StackNavigationPm object Serializers { val module = SerializersModule { - polymorphic(PmDescription::class) { registerPmDescriptionSubclasses() } + polymorphic(PmArgs::class) { registerPmArgsSubclasses() } } val json = Json { @@ -58,16 +58,16 @@ object Serializers { serializersModule = module } - private fun PolymorphicModuleBuilder.registerPmDescriptionSubclasses() { - subclass(MainPm.Description::class) - subclass(SamplesPm.Description::class) - subclass(CounterPm.Description::class) - subclass(StackNavigationPm.Description::class) - subclass(SimpleScreenPm.Description::class) - subclass(BottomNavigationPm.Description::class) - subclass(TabPm.Description::class) - subclass(TabItemPm.Description::class) - subclass(DialogNavigationPm.Description::class) - subclass(SimpleDialogPm.Description::class) + private fun PolymorphicModuleBuilder.registerPmArgsSubclasses() { + subclass(MainPm.Args::class) + subclass(SamplesPm.Args::class) + subclass(CounterPm.Args::class) + subclass(StackNavigationPm.Args::class) + subclass(SimpleScreenPm.Args::class) + subclass(BottomNavigationPm.Args::class) + subclass(TabPm.Args::class) + subclass(TabItemPm.Args::class) + subclass(DialogNavigationPm.Args::class) + subclass(SimpleDialogPm.Args::class) } } diff --git a/sample/app-common/src/commonMain/kotlin/me/dmdev/premo/sample/stacknavigation/SimpleScreenPm.kt b/sample/app-common/src/commonMain/kotlin/me/dmdev/premo/sample/stacknavigation/SimpleScreenPm.kt index 3435d50c..9eec3e59 100644 --- a/sample/app-common/src/commonMain/kotlin/me/dmdev/premo/sample/stacknavigation/SimpleScreenPm.kt +++ b/sample/app-common/src/commonMain/kotlin/me/dmdev/premo/sample/stacknavigation/SimpleScreenPm.kt @@ -1,7 +1,7 @@ /* * The MIT License (MIT) * - * Copyright (c) 2020-2023 Dmitriy Gorbunov (dmitriy.goto@gmail.com) + * Copyright (c) 2020-2024 Dmitriy Gorbunov (dmitriy.goto@gmail.com) * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -25,20 +25,18 @@ package me.dmdev.premo.sample.stacknavigation import kotlinx.serialization.Serializable -import me.dmdev.premo.PmDescription -import me.dmdev.premo.PmParams +import me.dmdev.premo.PmArgs import me.dmdev.premo.PresentationModel class SimpleScreenPm( - number: Int, - params: PmParams -) : PresentationModel(params) { + args: Args +) : PresentationModel(args) { @Serializable - class Description(val number: Int) : PmDescription { + class Args(val number: Int) : PmArgs() { override val key: String get() = "${super.key}/$number" } - val numberText = number.toString() + val numberText = args.number.toString() } diff --git a/sample/app-common/src/commonMain/kotlin/me/dmdev/premo/sample/stacknavigation/StackNavigationPm.kt b/sample/app-common/src/commonMain/kotlin/me/dmdev/premo/sample/stacknavigation/StackNavigationPm.kt index 19562a86..1cdc6fc6 100644 --- a/sample/app-common/src/commonMain/kotlin/me/dmdev/premo/sample/stacknavigation/StackNavigationPm.kt +++ b/sample/app-common/src/commonMain/kotlin/me/dmdev/premo/sample/stacknavigation/StackNavigationPm.kt @@ -1,7 +1,7 @@ /* * The MIT License (MIT) * - * Copyright (c) 2020-2023 Dmitriy Gorbunov (dmitriy.goto@gmail.com) + * Copyright (c) 2020-2024 Dmitriy Gorbunov (dmitriy.goto@gmail.com) * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -26,8 +26,7 @@ package me.dmdev.premo.sample.stacknavigation import kotlinx.coroutines.flow.map import kotlinx.serialization.Serializable -import me.dmdev.premo.PmDescription -import me.dmdev.premo.PmParams +import me.dmdev.premo.PmArgs import me.dmdev.premo.PresentationModel import me.dmdev.premo.getSaved import me.dmdev.premo.handle @@ -42,10 +41,10 @@ import me.dmdev.premo.navigation.replaceTop import me.dmdev.premo.sample.StateFlow import me.dmdev.premo.setSaver -class StackNavigationPm(params: PmParams) : PresentationModel(params) { +class StackNavigationPm(args: Args) : PresentationModel(args) { @Serializable - object Description : PmDescription + object Args : PmArgs() private val navigator = StackNavigator() val navigation: StackNavigation = navigator @@ -103,7 +102,7 @@ class StackNavigationPm(params: PmParams) : PresentationModel(params) { private var screenNumber: Int = stateHandler.getSaved(KEY_SCREEN_NUMBER) ?: 0 private fun nextChild(): PresentationModel { val number = screenNumber++ - return Child(SimpleScreenPm.Description(number)) + return Child(SimpleScreenPm.Args(number)) } companion object { diff --git a/sample/app-compose/build.gradle.kts b/sample/app-compose/build.gradle.kts index afcd7d40..c33e84fb 100644 --- a/sample/app-compose/build.gradle.kts +++ b/sample/app-compose/build.gradle.kts @@ -50,6 +50,7 @@ kotlin { js(IR) { browser() + binaries.executable() } sourceSets { diff --git a/sample/app-compose/src/androidMain/kotlin/me/dmdev/premo/sample/MainActivity.kt b/sample/app-compose/src/androidMain/kotlin/me/dmdev/premo/sample/MainActivity.kt index 098983d0..65790d06 100644 --- a/sample/app-compose/src/androidMain/kotlin/me/dmdev/premo/sample/MainActivity.kt +++ b/sample/app-compose/src/androidMain/kotlin/me/dmdev/premo/sample/MainActivity.kt @@ -1,7 +1,7 @@ /* * The MIT License (MIT) * - * Copyright (c) 2020-2023 Dmitriy Gorbunov (dmitriy.goto@gmail.com) + * Copyright (c) 2020-2024 Dmitriy Gorbunov (dmitriy.goto@gmail.com) * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -42,7 +42,7 @@ class MainActivity : AppCompatActivity() { private val delegate = AndroidPmDelegate( pmActivity = this, - pmDescription = MainPm.Description, + pmArgs = MainPm.Args, pmFactory = MainPmFactory(), pmStateSaver = JsonBundleStateSaver(Serializers.json) // pmStateSaver = ParcelableBundleStateSaver() diff --git a/sample/app-compose/src/commonMain/kotlin/me/dmdev/premo/sample/screen/BottomNavigationScreen.kt b/sample/app-compose/src/commonMain/kotlin/me/dmdev/premo/sample/screen/BottomNavigationScreen.kt index 9d903234..a27f8336 100644 --- a/sample/app-compose/src/commonMain/kotlin/me/dmdev/premo/sample/screen/BottomNavigationScreen.kt +++ b/sample/app-compose/src/commonMain/kotlin/me/dmdev/premo/sample/screen/BottomNavigationScreen.kt @@ -1,7 +1,7 @@ /* * The MIT License (MIT) * - * Copyright (c) 2020-2023 Dmitriy Gorbunov (dmitriy.goto@gmail.com) + * Copyright (c) 2020-2024 Dmitriy Gorbunov (dmitriy.goto@gmail.com) * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -61,7 +61,7 @@ fun BottomNavigationScreen( bottomBar = { BottomNavigation { pm.navigation.values.forEachIndexed { index, tabPm -> - val title = (tabPm as? TabPm)?.tabTitle ?: "" + val title = (tabPm as? TabPm)?.title ?: "" BottomNavigationItem( selected = tabPm == currentTabPm, onClick = { pm.navigation.onChangeCurrent(index) }, @@ -105,7 +105,7 @@ fun ItemScreen(pmTab: TabItemPm = Stubs.tabItemPm) { ) { Text( fontSize = 24.sp, - text = pmTab.screenTitle + text = pmTab.title ) Spacer(modifier = Modifier.height(32.dp)) Row { diff --git a/sample/app-compose/src/commonMain/kotlin/me/dmdev/premo/sample/screen/DialogNavigationScreen.kt b/sample/app-compose/src/commonMain/kotlin/me/dmdev/premo/sample/screen/DialogNavigationScreen.kt index 7e18748b..0338da06 100644 --- a/sample/app-compose/src/commonMain/kotlin/me/dmdev/premo/sample/screen/DialogNavigationScreen.kt +++ b/sample/app-compose/src/commonMain/kotlin/me/dmdev/premo/sample/screen/DialogNavigationScreen.kt @@ -1,7 +1,7 @@ /* * The MIT License (MIT) * - * Copyright (c) 2020-2023 Dmitriy Gorbunov (dmitriy.goto@gmail.com) + * Copyright (c) 2020-2024 Dmitriy Gorbunov (dmitriy.goto@gmail.com) * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -65,11 +65,11 @@ fun DialogNavigationScreen( val dialogPm = dialogs.lastOrNull() if (dialogPm is SimpleDialogPm) { AlertDialog( - title = { Text(dialogPm.title) }, - text = { Text(dialogPm.message) }, + title = { Text(dialogPm.args.title) }, + text = { Text(dialogPm.args.message) }, buttons = { - val okButtonText = dialogPm.okButtonText - val cancelButtonText = dialogPm.cancelButtonText + val okButtonText = dialogPm.args.okButtonText + val cancelButtonText = dialogPm.args.cancelButtonText Row( modifier = Modifier.fillMaxWidth().padding(8.dp), diff --git a/sample/app-compose/src/jsMain/kotlin/me/dmdev/premo/sample/Main.kt b/sample/app-compose/src/jsMain/kotlin/me/dmdev/premo/sample/Main.kt index d0f23b3f..0eee95fe 100644 --- a/sample/app-compose/src/jsMain/kotlin/me/dmdev/premo/sample/Main.kt +++ b/sample/app-compose/src/jsMain/kotlin/me/dmdev/premo/sample/Main.kt @@ -1,7 +1,7 @@ /* * The MIT License (MIT) * - * Copyright (c) 2020-2023 Dmitriy Gorbunov (dmitriy.goto@gmail.com) + * Copyright (c) 2020-2024 Dmitriy Gorbunov (dmitriy.goto@gmail.com) * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -33,7 +33,7 @@ import org.jetbrains.skiko.wasm.onWasmReady fun main() { val pmDelegate = JsPmDelegate( - pmDescription = MainPm.Description, + pmArgs = MainPm.Args, pmFactory = MainPmFactory(), pmStateSaver = JsonStateSaver(Serializers.json) ) diff --git a/sample/app-compose/src/jvmMain/kotlin/me/dmdev/premo/sample/Main.kt b/sample/app-compose/src/jvmMain/kotlin/me/dmdev/premo/sample/Main.kt index 2321ff33..75c67f6c 100644 --- a/sample/app-compose/src/jvmMain/kotlin/me/dmdev/premo/sample/Main.kt +++ b/sample/app-compose/src/jvmMain/kotlin/me/dmdev/premo/sample/Main.kt @@ -34,7 +34,7 @@ import me.dmdev.premo.saver.JsonFileStateSaver @Preview fun main() { val pmDelegate = JvmPmDelegate( - pmDescription = MainPm.Description, + pmArgs = MainPm.Args, pmFactory = MainPmFactory(), pmStateSaver = JsonFileStateSaver(Serializers.json) ) diff --git a/sample/app-ios-swiftui/app-ios-swiftui/AppDelegate.swift b/sample/app-ios-swiftui/app-ios-swiftui/AppDelegate.swift index 15236c44..6a9d3c2e 100644 --- a/sample/app-ios-swiftui/app-ios-swiftui/AppDelegate.swift +++ b/sample/app-ios-swiftui/app-ios-swiftui/AppDelegate.swift @@ -29,7 +29,7 @@ import Common class AppDelegate: NSObject, UIApplicationDelegate { let pmDelegate: IosPmDelegate = IosPmDelegate( - pmDescription: MainPm.Description(), + pmArgs: MainPm.Args(), pmFactory: MainPmFactory(), pmStateSaver: JsonNSCoderStateSaver(json: Serializers.shared.json) ) diff --git a/sample/app-ios-swiftui/app-ios-swiftui/DialogNavigationView.swift b/sample/app-ios-swiftui/app-ios-swiftui/DialogNavigationView.swift index 69d8846e..0d650e7f 100644 --- a/sample/app-ios-swiftui/app-ios-swiftui/DialogNavigationView.swift +++ b/sample/app-ios-swiftui/app-ios-swiftui/DialogNavigationView.swift @@ -69,13 +69,13 @@ struct DialogNavigationView: View { .alert(isPresented: alertIsShowingBinding) { let dialogPm = dialogs.value?.lastObject as? SimpleDialogPm return Alert( - title: Text(dialogPm?.title ?? ""), - message: Text(dialogPm?.message ?? ""), - primaryButton: .default(Text(dialogPm?.cancelButtonText ?? ""), action: { + title: Text(dialogPm?.args.title ?? ""), + message: Text(dialogPm?.args.message ?? ""), + primaryButton: .default(Text(dialogPm?.args.cancelButtonText ?? ""), action: { dialogPm?.onCancelClick() }), - secondaryButton: .default(Text(dialogPm?.okButtonText ?? ""), action: { + secondaryButton: .default(Text(dialogPm?.args.okButtonText ?? ""), action: { dialogPm?.onOkClick() }) ) diff --git a/sample/app-web-html/src/jsMain/kotlin/me.dmdev.premo.sample/Main.kt b/sample/app-web-html/src/jsMain/kotlin/me.dmdev.premo.sample/Main.kt index 62312371..646b29ea 100644 --- a/sample/app-web-html/src/jsMain/kotlin/me.dmdev.premo.sample/Main.kt +++ b/sample/app-web-html/src/jsMain/kotlin/me.dmdev.premo.sample/Main.kt @@ -1,7 +1,7 @@ /* * The MIT License (MIT) * - * Copyright (c) 2020-2023 Dmitriy Gorbunov (dmitriy.goto@gmail.com) + * Copyright (c) 2020-2024 Dmitriy Gorbunov (dmitriy.goto@gmail.com) * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -32,7 +32,7 @@ import org.jetbrains.compose.web.* fun main() { val pmDelegate = JsPmDelegate( - pmDescription = MainPm.Description, + pmArgs = MainPm.Args, pmFactory = MainPmFactory(), pmStateSaver = JsonStateSaver(Serializers.json) ) diff --git a/sample/app-web-react/src/jsMain/kotlin/me.dmdev.premo.sample/Main.kt b/sample/app-web-react/src/jsMain/kotlin/me.dmdev.premo.sample/Main.kt index d1101f1d..29476964 100644 --- a/sample/app-web-react/src/jsMain/kotlin/me.dmdev.premo.sample/Main.kt +++ b/sample/app-web-react/src/jsMain/kotlin/me.dmdev.premo.sample/Main.kt @@ -1,7 +1,7 @@ /* * The MIT License (MIT) * - * Copyright (c) 2020-2023 Dmitriy Gorbunov (dmitriy.goto@gmail.com) + * Copyright (c) 2020-2024 Dmitriy Gorbunov (dmitriy.goto@gmail.com) * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -34,7 +34,7 @@ import web.dom.document fun main() { val pmDelegate = JsPmDelegate( - pmDescription = MainPm.Description, + pmArgs = MainPm.Args, pmFactory = MainPmFactory(), pmStateSaver = JsonStateSaver(Serializers.json) ) diff --git a/sample/app-web-react/src/jsMain/kotlin/me.dmdev.premo.sample/component/DialogNavigationComponent.kt b/sample/app-web-react/src/jsMain/kotlin/me.dmdev.premo.sample/component/DialogNavigationComponent.kt index f4b84931..c0bd97d6 100644 --- a/sample/app-web-react/src/jsMain/kotlin/me.dmdev.premo.sample/component/DialogNavigationComponent.kt +++ b/sample/app-web-react/src/jsMain/kotlin/me.dmdev.premo.sample/component/DialogNavigationComponent.kt @@ -1,7 +1,7 @@ /* * The MIT License (MIT) * - * Copyright (c) 2020-2023 Dmitriy Gorbunov (dmitriy.goto@gmail.com) + * Copyright (c) 2020-2024 Dmitriy Gorbunov (dmitriy.goto@gmail.com) * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -88,20 +88,20 @@ val DialogNavigationComponent = FC { props -> pm.dialogGroupNavigation.onDismissRequest() } - if (dialogPm.title.isNotEmpty()) { + if (dialogPm.args.title.isNotEmpty()) { DialogTitle { - +dialogPm.title + +dialogPm.args.title } } - if (dialogPm.message.isNotEmpty()) { + if (dialogPm.args.message.isNotEmpty()) { DialogContent { - +dialogPm.message + +dialogPm.args.message } } DialogActions { - if (dialogPm.cancelButtonText.isNotEmpty()) { + if (dialogPm.args.cancelButtonText.isNotEmpty()) { Button { onClick = { dialogPm.onCancelClick() @@ -110,7 +110,7 @@ val DialogNavigationComponent = FC { props -> +"Cancel" } } - if (dialogPm.okButtonText.isNotEmpty()) { + if (dialogPm.args.okButtonText.isNotEmpty()) { Button { onClick = { dialogPm.onOkClick() diff --git a/settings.gradle.kts b/settings.gradle.kts index 5ddc6ea2..6ebc5250 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -1,7 +1,7 @@ /* * The MIT License (MIT) * - * Copyright (c) 2020-2023 Dmitriy Gorbunov (dmitriy.goto@gmail.com) + * Copyright (c) 2020-2024 Dmitriy Gorbunov (dmitriy.goto@gmail.com) * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -24,6 +24,7 @@ pluginManagement { repositories { + mavenLocal() google() gradlePluginPortal() mavenCentral() @@ -33,6 +34,7 @@ pluginManagement { dependencyResolutionManagement { repositories { + mavenLocal() mavenCentral() maven("https://maven.pkg.jetbrains.space/public/p/compose/dev") google()