Skip to content
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

Fix ViewModel key generation + Fix ViewModel scope handling #1809

Merged
merged 6 commits into from Mar 4, 2024

Conversation

arnaudgiuliani
Copy link
Member

  • ViewModel key is calculated against Key and/or Qualifier
  • ViewModel is only created against root Scope to avoid any leaking (leaking Activity or Fragment ...). This fix the visibility problem, where ViewModel could have access to incompatible scopes.
  • ScopeViewModel to help work on ViewModel scope like follow:
module {
    viewModelOf(::MyScopeViewModel)
    scope<MyScopeViewModel> {
        scopedOf(::Session)
    }    
}

class MyScopeViewModel : ScopeViewModel() {

    // on onCleared, scope is closed
    
    // injected from current MyScopeViewModel's scope
    val session by scope.inject<Session>()

}

Fix #1750

…y limited to root scope to avoid leaking from any Activity/Fragment context. ScopeViewModel allow to work on ViewModel scope space.
@arnaudgiuliani arnaudgiuliani added this to the android-3.5.4 milestone Mar 4, 2024
@arnaudgiuliani arnaudgiuliani merged commit 765c311 into 3.5.4 Mar 4, 2024
8 checks passed
@arnaudgiuliani arnaudgiuliani deleted the fix/viewmodel_key_scope branch March 4, 2024 17:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant