Skip to content

Commit

Permalink
update kdocs and microutils
Browse files Browse the repository at this point in the history
  • Loading branch information
InsanusMokrassar committed Mar 26, 2023
1 parent f974111 commit 0db3b2b
Show file tree
Hide file tree
Showing 10 changed files with 258 additions and 153 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## 0.0.16

* `Versions`:
* `MicroUtils`: `0.17.5`
* `NavigationChain` got its own optional id
* `NavigationChain` and `NavigationNode` got `findChain` extension
* `NavigationChain` and `NavigationNode` got `findNode` extension
Expand Down
30 changes: 30 additions & 0 deletions core/src/commonMain/kotlin/extensions/Chain.kt
Original file line number Diff line number Diff line change
Expand Up @@ -40,47 +40,77 @@ fun <Base> NavigationChain<Base>.findChain(id: NavigationChainId): NavigationCha

// Drop/replace/push by node id

/**
* Shortcut for method [dev.inmo.navigation.core.ChainOrNodeEither].[dropInSubTree]
*/
fun <Base> NavigationChain<Base>.dropInSubTree(
id: NavigationNodeId
): Boolean = chainOrNodeEither().dropInSubTree(id)

/**
* Shortcut for method [dev.inmo.navigation.core.ChainOrNodeEither].[dropNodeInSubTree]
*/
fun <Base> NavigationChain<Base>.dropNodeInSubTree(id: String) = chainOrNodeEither().dropNodeInSubTree(id)

/**
* Shortcut for method [dev.inmo.navigation.core.ChainOrNodeEither].[replaceInSubTree]
*/
fun <Base> NavigationChain<Base>.replaceInSubTree(
id: NavigationNodeId,
config: Base,
): Boolean = chainOrNodeEither().replaceInSubTree(id, config)

/**
* Shortcut for method [dev.inmo.navigation.core.ChainOrNodeEither].[replaceInSubTree]
*/
fun <Base> NavigationChain<Base>.replaceInSubTree(
id: String,
config: Base
) = chainOrNodeEither().replaceInSubTree(id, config)

/**
* Shortcut for method [dev.inmo.navigation.core.ChainOrNodeEither].[pushInSubTree]
*/
fun <Base> NavigationChain<Base>.pushInSubTree(
inChainWith: NavigationNodeId,
config: Base
): Boolean = chainOrNodeEither().pushInSubTree(inChainWith, config)

/**
* Shortcut for method [dev.inmo.navigation.core.ChainOrNodeEither].[pushInSubTreeByNodeId]
*/
fun <Base> NavigationChain<Base>.pushInSubTreeByNodeId(
inChainWithNodeId: String,
config: Base
) = chainOrNodeEither().pushInSubTreeByNodeId(inChainWithNodeId, config)

// Drop/push by chain id

/**
* Shortcut for method [dev.inmo.navigation.core.ChainOrNodeEither].[dropInSubTree]
*/
fun <Base> NavigationChain<Base>.dropInSubTree(
id: NavigationChainId
) = chainOrNodeEither().dropInSubTree(id)

/**
* Shortcut for method [dev.inmo.navigation.core.ChainOrNodeEither].[dropChainInSubTree]
*/
fun <Base> NavigationChain<Base>.dropChainInSubTree(
id: String
) = chainOrNodeEither().dropChainInSubTree(id)

/**
* Shortcut for method [dev.inmo.navigation.core.ChainOrNodeEither].[pushInSubTree]
*/
fun <Base> NavigationChain<Base>.pushInSubTree(
inChainWithNodeId: NavigationChainId,
config: Base
) = chainOrNodeEither().pushInSubTree(inChainWithNodeId, config)

/**
* Shortcut for method [dev.inmo.navigation.core.ChainOrNodeEither].[pushInSubTreeByChainId]
*/
fun <Base> NavigationChain<Base>.pushInSubTreeByChainId(
inChainWithNodeId: String,
config: Base
Expand Down
51 changes: 46 additions & 5 deletions core/src/commonMain/kotlin/extensions/EitherChainOrNode.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,17 @@ package dev.inmo.navigation.core.extensions
import dev.inmo.navigation.core.ChainOrNodeEither
import dev.inmo.navigation.core.NavigationChainId
import dev.inmo.navigation.core.NavigationNodeId
import dev.inmo.navigation.core.visiter.walk
import dev.inmo.navigation.core.visiter.walkOnChains
import dev.inmo.navigation.core.visiter.walkOnNodes


// Drop/replace/push by chain id

/**
* Will drop all nodes in tree with [dev.inmo.navigation.core.NavigationNode.id] == [id]
*
* **This method will start its work with [this] as a root**
*/
fun <Base> ChainOrNodeEither<Base>.dropInSubTree(
id: NavigationNodeId
): Boolean {
Expand All @@ -22,8 +26,17 @@ fun <Base> ChainOrNodeEither<Base>.dropInSubTree(
return deleted
}

/**
* Shortcut for [dropInSubTree]
*/
fun <Base> ChainOrNodeEither<Base>.dropNodeInSubTree(id: String) = dropInSubTree(NavigationNodeId(id))

/**
* Will [dev.inmo.navigation.core.NavigationChain.replace] all nodes in tree with
* [dev.inmo.navigation.core.NavigationNode.id] == [id] by a new one with [config]
*
* **This method will start its work with [this] as a root**
*/
fun <Base> ChainOrNodeEither<Base>.replaceInSubTree(
id: NavigationNodeId,
config: Base,
Expand All @@ -35,31 +48,48 @@ fun <Base> ChainOrNodeEither<Base>.replaceInSubTree(
return replaced
}

/**
* Shortcut for method [replaceInSubTree]
*/
fun <Base> ChainOrNodeEither<Base>.replaceInSubTree(
id: String,
config: Base
) = replaceInSubTree(NavigationNodeId(id), config)

/**
* Will push on top in all chains with any [dev.inmo.navigation.core.NavigationNode] in
* [dev.inmo.navigation.core.NavigationChain.stack] with [dev.inmo.navigation.core.NavigationNode.id] == [id]
*
* **This method will start its work with [this] as a root**
*/
fun <Base> ChainOrNodeEither<Base>.pushInSubTree(
inChainWith: NavigationNodeId,
id: NavigationNodeId,
config: Base
): Boolean {
var pushed = false
walkOnNodes {
if (it.id == inChainWith) {
if (it.id == id) {
pushed = it.chain.push(config) != null || pushed
}
}
return pushed
}

/**
* Shortcut for method [pushInSubTree]
*/
fun <Base> ChainOrNodeEither<Base>.pushInSubTreeByNodeId(
inChainWithNodeId: String,
config: Base
) = pushInSubTree(NavigationNodeId(inChainWithNodeId), config)

// Drop/push by chain id

/**
* Will drop all chains in tree with [dev.inmo.navigation.core.NavigationChain.id] == [id]
*
* **This method will start its work with [this] as a root**
*/
fun <Base> ChainOrNodeEither<Base>.dropInSubTree(
id: NavigationChainId
): Boolean {
Expand All @@ -73,21 +103,32 @@ fun <Base> ChainOrNodeEither<Base>.dropInSubTree(
return deleted
}

/**
* Shortcut for method [dropInSubTree]
*/
fun <Base> ChainOrNodeEither<Base>.dropChainInSubTree(id: String) = dropInSubTree(NavigationChainId(id))

/**
* Will push on top in all chains with [dev.inmo.navigation.core.NavigationChain.id] == [id]
*
* **This method will start its work with [this] as a root**
*/
fun <Base> ChainOrNodeEither<Base>.pushInSubTree(
inChainWith: NavigationChainId,
id: NavigationChainId,
config: Base
): Boolean {
var pushed = false
walkOnChains {
if (it.id == inChainWith) {
if (it.id == id) {
pushed = it.push(config) != null || pushed
}
}
return pushed
}

/**
* Shortcut for method [pushInSubTree]
*/
fun <Base> ChainOrNodeEither<Base>.pushInSubTreeByChainId(
inChainWithNodeId: String,
config: Base
Expand Down
30 changes: 30 additions & 0 deletions core/src/commonMain/kotlin/extensions/Node.kt
Original file line number Diff line number Diff line change
Expand Up @@ -40,47 +40,77 @@ fun <Base> NavigationNode<*, Base>.findChain(id: NavigationChainId): NavigationC

// Drop/replace/push by node id

/**
* Shortcut for method [dev.inmo.navigation.core.ChainOrNodeEither].[dropInSubTree]
*/
fun <Base> NavigationNode<*, Base>.dropInSubTree(
id: NavigationNodeId
): Boolean = chainOrNodeEither().dropInSubTree(id)

/**
* Shortcut for method [dev.inmo.navigation.core.ChainOrNodeEither].[dropNodeInSubTree]
*/
fun <Base> NavigationNode<*, Base>.dropNodeInSubTree(id: String) = chainOrNodeEither().dropNodeInSubTree(id)

/**
* Shortcut for method [dev.inmo.navigation.core.ChainOrNodeEither].[replaceInSubTree]
*/
fun <Base> NavigationNode<*, Base>.replaceInSubTree(
id: NavigationNodeId,
config: Base,
): Boolean = chainOrNodeEither().replaceInSubTree(id, config)

/**
* Shortcut for method [dev.inmo.navigation.core.ChainOrNodeEither].[replaceInSubTree]
*/
fun <Base> NavigationNode<*, Base>.replaceInSubTree(
id: String,
config: Base
) = chainOrNodeEither().replaceInSubTree(id, config)

/**
* Shortcut for method [dev.inmo.navigation.core.ChainOrNodeEither].[pushInSubTree]
*/
fun <Base> NavigationNode<*, Base>.pushInSubTree(
inChainWith: NavigationNodeId,
config: Base
): Boolean = chainOrNodeEither().pushInSubTree(inChainWith, config)

/**
* Shortcut for method [dev.inmo.navigation.core.ChainOrNodeEither].[pushInSubTreeByNodeId]
*/
fun <Base> NavigationNode<*, Base>.pushInSubTreeByNodeId(
inChainWithNodeId: String,
config: Base
) = chainOrNodeEither().pushInSubTreeByNodeId(inChainWithNodeId, config)

// Drop/push by chain id

/**
* Shortcut for method [dev.inmo.navigation.core.ChainOrNodeEither].[dropInSubTree]
*/
fun <Base> NavigationNode<*, Base>.dropInSubTree(
id: NavigationChainId
) = chainOrNodeEither().dropInSubTree(id)

/**
* Shortcut for method [dev.inmo.navigation.core.ChainOrNodeEither].[dropChainInSubTree]
*/
fun <Base> NavigationNode<*, Base>.dropChainInSubTree(
id: String
) = chainOrNodeEither().dropChainInSubTree(id)

/**
* Shortcut for method [dev.inmo.navigation.core.ChainOrNodeEither].[pushInSubTree]
*/
fun <Base> NavigationNode<*, Base>.pushInSubTree(
inChainWithNodeId: NavigationChainId,
config: Base
) = chainOrNodeEither().pushInSubTree(inChainWithNodeId, config)

/**
* Shortcut for method [dev.inmo.navigation.core.ChainOrNodeEither].[pushInSubTreeByChainId]
*/
fun <Base> NavigationNode<*, Base>.pushInSubTreeByChainId(
inChainWithNodeId: String,
config: Base
Expand Down
Loading

0 comments on commit 0db3b2b

Please sign in to comment.