Created
September 14, 2018 12:29
-
-
Save ValeryPonomarenko/2f8a1fe7ba31d1628cd4becee303abfd to your computer and use it in GitHub Desktop.
Lifecycle aware dagger components
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
internal class ComponentsStore { | |
private val componentsForView = mutableMapOf<String, Any>() | |
fun isExist(key: String): Boolean = | |
componentsForView.containsKey(key) | |
fun add(key: String, component: Any) { | |
componentsForView[key] = component | |
} | |
fun get(key: String): Any = | |
componentsForView[key] ?: throw ComponentNotFoundException() | |
fun remove(key: String) { | |
componentsForView.remove(key) | |
} | |
fun findComponent(predicate: (Any) -> Boolean): Any { | |
for ((_, component) in componentsForView) { | |
if (predicate(component)) return component | |
} | |
throw ComponentNotFoundException() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment