-
Notifications
You must be signed in to change notification settings - Fork 658
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[FC] Moves Activities and some Panes out of Mavericks #8125
[FC] Moves Activities and some Panes out of Mavericks #8125
Conversation
Diffuse output:
APK
MANIFEST
DEX
ARSC
|
onSuccess: (T) -> Unit = {}, | ||
onFail: (Throwable) -> Unit = {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added some side effect callbacks that should replace the onAsync
behavior (IMO code is easier to follow if side effects follow the operation execution)
f5bc4d0
to
ce3643e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Love the direction that this is going ❤️
initialState: S | ||
) : ViewModel() { | ||
|
||
val stateFlow: MutableStateFlow<S> = MutableStateFlow(initialState) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should keep this private and expose a non-mutable StateFlow
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.../src/main/java/com/stripe/android/financialconnections/core/FinancialConnectionsViewModel.kt
Outdated
Show resolved
Hide resolved
} | ||
|
||
protected fun setState(reducer: S.() -> S) { | ||
stateFlow.update { state -> state.reducer() } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another super nit!
stateFlow.update { state -> state.reducer() } | |
stateFlow.update(reducer) |
} | ||
} | ||
|
||
internal sealed class Result<out T>( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It’s not technically a result. Should we call this AsyncState
or something more along those lines?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what about we just call it Async? Feels simple and short : )
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* retained component) to the factory to facilitate its creation via dependency injection. | ||
*/ | ||
@Composable | ||
internal inline fun <reified T : FinancialConnectionsViewModel<S>, S> paneViewModel( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice!
fun factory(parentComponent: FinancialConnectionsSheetNativeComponent): ViewModelProvider.Factory = | ||
viewModelFactory { | ||
initializer { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Smooth 👌
.map { it.viewEffect } | ||
.distinctUntilChanged() | ||
.collect { viewEffect -> | ||
if (viewEffect == null) return@collect |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about a filterNotNull
above?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -161,7 +182,7 @@ internal class FinancialConnectionsSheetNativeViewModel @Inject constructor( | |||
*/ | |||
fun onResume() = viewModelScope.launch { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we still need the coroutine scope now?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yep! still needed for the mutex
.map { it.viewEffect } | ||
.distinctUntilChanged() | ||
.collect { viewEffect -> | ||
if (viewEffect == null) return@collect |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same filterNotNull
suggestion.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -281,7 +281,7 @@ class FinancialConnectionsSheetViewModelTest { | |||
viewModel.handleOnNewIntent(errorIntent) | |||
|
|||
// Then | |||
withState(viewModel) { | |||
viewModel.stateFlow.value.let { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we can add some FinancialConnectionsViewModel
specific test extensions like Mavericks had. What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good idea! noted for future PRs : )
…alconnections/core/FinancialConnectionsViewModel.kt Co-authored-by: Till Hellmund <tillh@stripe.com>
import kotlinx.coroutines.flow.update | ||
import kotlinx.coroutines.launch | ||
|
||
internal abstract class FinancialConnectionsViewModel<S>( | ||
initialState: S | ||
) : ViewModel() { | ||
|
||
val stateFlow: MutableStateFlow<S> = MutableStateFlow(initialState) | ||
private val _stateFlow: MutableStateFlow<S> = MutableStateFlow(initialState) | ||
val stateFlow: StateFlow<S> = _stateFlow |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
val stateFlow: StateFlow<S> = _stateFlow | |
val stateFlow: StateFlow<S> = _stateFlow.asStateFlow() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -5,7 +5,7 @@ import kotlin.test.Test | |||
import kotlin.test.assertEquals | |||
import kotlin.test.assertNull | |||
|
|||
class GooglePayResultTest { | |||
class GooglePayAsyncTest { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👀 🙈
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
8b8043c
into
carlosmuvi/i/remove-mavericks
* [FC] Moves Activities and some Panes out of Mavericks (#8125) * Removes mackericks references on Consent screen. * Updates files. * Uses viewmodel factory builder. * Updates functions. * Updates execute. * Updates compose util. * Adds missing side effects. * Simplifies code. * Renames viewmodel. * Updates async. * Removes mavericks from institution picker. * Reverts rename. * Updates baseline. * Adds setState and persists state. * Renames result error to fail. * Migrates Initial activity out of mavericks. * Removes persist state. * Updates tests. * Regenerates API. * filterNotNull. * Nits. * Updates async. * use suspend block. * Update financial-connections/src/main/java/com/stripe/android/financialconnections/core/FinancialConnectionsViewModel.kt Co-authored-by: Till Hellmund <tillh@stripe.com> * Tries onAsync. * Moves activity to stripe ui core. * PR feedback. * Regenerates deps. --------- Co-authored-by: Till Hellmund <tillh@stripe.com> * [FC] Removes mavericks from repositories and more panes. (#8154) * Migrates more screens out of mavs. * Migrates partner auth. * Removes active auth session field. * Updates tests. * Updates attach payment viewmodel. * PR feedback. * Api dump. * [FC] Removes mavericks from all viewmodels and tests (#8155) * Migrates more screens out of mavs. * Migrates partner auth. * Removes active auth session field. * Updates tests. * Updates attach payment viewmodel. * PR feedback. * Api dump. * Migrates missing viewmodels. * Updates dependencies. * PR feedback. * Merge master. * [FC] Removes mavericks dependency (#8160) * Migrates more screens out of mavs. * Migrates partner auth. * Removes active auth session field. * Updates tests. * Updates attach payment viewmodel. * PR feedback. * Api dump. * Migrates missing viewmodels. * Updates dependencies. * Removes mavericks dependency. * Merge with integration. * Uses collect. * Updates dependencies * Updates Changelog. * Update CHANGELOG.md Co-authored-by: Till Hellmund <tillh@stripe.com> --------- Co-authored-by: Till Hellmund <tillh@stripe.com>
Summary
First PR removing Mavericks on both parent activities, as well as Consent and Institution Picker (Composable-based panes).
Result
(replacesAsync
).SavedStateHandle
to save and retrieve fields on process death (replacing @PersistState)MavericksViewModelFactory
helps retrieving the parent activity with itsViewModelContext
We use that to retrieve the activity viewmodel, that exposes the parent Dagger Component to build screen SubComponents. Replaced by a helper function that retrieves the parent component directly.Motivation
Testing
@PersistState
.