generated from InsanusMokrassar/KotlinMultiplatformProjectTemplate
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #50 from InsanusMokrassar/0.5.7
0.5.7
- Loading branch information
Showing
9 changed files
with
137 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
core/src/commonMain/kotlin/extensions/ChangesInSubtreeFlow.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package dev.inmo.navigation.core.extensions | ||
|
||
import dev.inmo.micro_utils.common.* | ||
import dev.inmo.navigation.core.NavigationChain | ||
import dev.inmo.navigation.core.NavigationNode | ||
import kotlinx.coroutines.ExperimentalCoroutinesApi | ||
import kotlinx.coroutines.flow.Flow | ||
import kotlinx.coroutines.flow.flatMapLatest | ||
import kotlinx.coroutines.flow.map | ||
import kotlinx.coroutines.flow.merge | ||
|
||
/** | ||
* @return [Flow] which will have one of two data variants: chain where happen changes and its stack list (list will be | ||
* presented only if change happen there); node and its subchaines (subchaines will be presented only if their list | ||
* have been changed) | ||
*/ | ||
@Warning("This API is still experimental. Please, report on any wrong behaviour if any") | ||
@OptIn(ExperimentalCoroutinesApi::class) | ||
fun <Base> Either<NavigationChain<Base>, NavigationNode<out Base, Base>>.changesInSubtreeFlow(): Flow< | ||
Either< | ||
Pair<NavigationChain<Base>, List<NavigationNode<out Base, Base>>>, | ||
Pair<NavigationNode<out Base, Base>, List<NavigationChain<Base>>?>, | ||
> | ||
> { | ||
return merge( | ||
when (this) { | ||
is EitherFirst -> merge( | ||
// chain | ||
this.t1.stackFlow.map { (this.t1 to it).either() }, | ||
this.t1.stackFlow.flatMapLatest { | ||
it.map { | ||
it.either<NavigationChain<Base>, NavigationNode<out Base, Base>>().changesInSubtreeFlow<Base>() | ||
}.merge() | ||
}, | ||
) | ||
|
||
is EitherSecond -> merge( | ||
// node | ||
this.t2.subchainsFlow.map { (this.t2 to it).either() }, | ||
this.t2.subchainsFlow.flatMapLatest { | ||
it.map { | ||
it.either<NavigationChain<Base>, NavigationNode<out Base, Base>>().changesInSubtreeFlow<Base>() | ||
}.merge() | ||
}, | ||
this.t2.stateChangesFlow.map { (this.t2 to null).either() }, | ||
this.t2.configState.map { (this.t2 to null).either() }, | ||
) | ||
}, | ||
) | ||
} | ||
|
||
@Warning("This API is still experimental. Please, report on any wrong behaviour if any") | ||
fun <Base> NavigationChain<Base>.changesInSubTreeFlow() = either<NavigationChain<Base>, NavigationNode<out Base, Base>>().changesInSubtreeFlow() | ||
@Warning("This API is still experimental. Please, report on any wrong behaviour if any") | ||
fun <Base> NavigationNode<out Base, Base>.changesInSubTreeFlow() = either<NavigationChain<Base>, NavigationNode<out Base, Base>>().changesInSubtreeFlow() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package dev.inmo.navigation.core.tmp_utils | ||
|
||
import dev.inmo.micro_utils.common.Diff | ||
import dev.inmo.micro_utils.common.Warning | ||
import dev.inmo.micro_utils.common.diff | ||
import kotlinx.coroutines.flow.Flow | ||
import kotlinx.coroutines.flow.first | ||
import kotlinx.coroutines.flow.flow | ||
import kotlinx.coroutines.flow.map | ||
|
||
@Warning("This feature can be removed in any update without notice") | ||
val <T> Flow<List<T>>.diffFlow: Flow<Diff<T>> | ||
get() = flow { | ||
var currentValue = first() | ||
|
||
map { | ||
val diff = it.diff(currentValue) | ||
|
||
currentValue = it | ||
|
||
emit(diff) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters