This file contains hidden or 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
interface GenericBlackBoxComponent : Consumer<Input>, ObservableSource<Output> { | |
sealed class Input | |
sealed class Output | |
} |
This file contains hidden or 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
// will automatically dispose of the created rx subscriptions when the lifecycle ends: | |
val binder = Binder(lifecycle) | |
// connect some observable sources to some consumers with element transformation: | |
binder.bind(outputA to inputB using transformer1) | |
binder.bind(outputB to inputA using transformer2) |
This file contains hidden or 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
bind(feature to view using stateToViewModelTransformer) | |
bind(view to feature using uiEventToWishTransformer) |
This file contains hidden or 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 object AnalyticsTracker : Consumer<AnalyticsTracker.Event> { | |
sealed class Event { | |
object ProfileImageClicked: Event() | |
object EditButtonClicked : Event() | |
} | |
override fun accept(event: AnalyticsTracker.Event) { | |
// TODO Implement actual tracking | |
} | |
} |
This file contains hidden or 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
bind(feature to view using stateToViewModelTransformer) | |
bind(view to feature using uiEventToWishTransformer) | |
// +1 line, nothing else changed: | |
bind(view to analyticsTracker using uiEventToAnalyticsEventTransformer) |
This file contains hidden or 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 is wherever you put your bindings, depending on your architecture | |
class BindingEnvironment( | |
private val component1: Component1, | |
private val component2: Component2 | |
) { | |
fun createBindings(lifecycle: Lifecycle) { | |
val binder = Binder(lifecycle) | |
binder.bind(component1 to component2 using Transformer()) | |
} | |
} |
This file contains hidden or 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
@Test | |
fun testCase1() { | |
val transformer = Transformer() | |
val testInput = TODO() | |
val actualOutput = transformer.invoke(testInput) | |
val expectedOutput = TODO() | |
assertEquals(expectedOutput, actualOutput) | |
} |
This file contains hidden or 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
class BindingEnvironmentTest { | |
lateinit var component1: ObservableSource<Component1.Output> | |
lateinit var component2: Consumer<Component2.Input> | |
lateinit var bindings: BindingEnvironment | |
@Before | |
fun setUp() { | |
val component1 = PublishRelay.create() | |
val component2 = mock() | |
val bindings = BindingEnvironment(component1, component2) |
This file contains hidden or 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
/** | |
* Class defining the screens we have in the app: home, article details and interests | |
*/ | |
sealed class Screen { | |
object Home : Screen() | |
data class Article(val postId: String) : Screen() | |
object Interests : Screen() | |
} |
This file contains hidden or 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
@Composable | |
private fun AppContent(openDrawer: () -> Unit) { | |
Crossfade(JetnewsStatus.currentScreen) { screen -> | |
Surface(color = (+MaterialTheme.colors()).background) { | |
when (screen) { | |
is Screen.Home -> HomeScreen { openDrawer() } | |
is Screen.Interests -> InterestsScreen { openDrawer() } | |
is Screen.Article -> ArticleScreen(postId = screen.postId) | |
} | |
} |