Make Node a viewmodel store owner#322
Closed
antonshilov wants to merge 2 commits intobumble-tech:2.xfrom
Closed
Conversation
| return ViewModelProvider(viewModelStoreOwner).get() | ||
| } | ||
| } | ||
| } No newline at end of file |
Check warning
Code scanning / detekt
Checks whether files end with a line separator.
| import kotlinx.coroutines.flow.getAndUpdate | ||
| import kotlinx.coroutines.launch | ||
|
|
||
| class MyViewModel() : ViewModel() { |
Check warning
Code scanning / detekt
Empty block of code detected. As they serve no purpose they should be removed.
| override fun onCleared() { | ||
| super.onCleared() | ||
| } | ||
| } No newline at end of file |
Check warning
Code scanning / detekt
Checks whether files end with a line separator.
2 tasks
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Its a hacky draft showcasing possible way to integrate viewmodel with Appyx.
In this case Node implements ViewmodelStore interface, allowing devs to use the same viewmodel extenstion methods used for Composables, Fragments & Activity.
On the root of the tree in ActivityIntegrationPoint we have a viewmodel that stores all of the viewmodel stores for nodes, where node id is the key in that storage. That viewmodel itself survives configuration change, with its contents.
Node clears it's ViewmodelStore when destroyed. To differentiate DESTROY event when we're recreating activity, and DESTROY when Node is actually destroyed we have to check activtiy.isChanging configuration. ComposeNavigation for example does it a bit different - it associates ViewmodelStore with backstack entry and clears it once removed from backstack. But for Appyx this approach is not suitable since we'll have to have this kind of logic in every navmodel.
Pros: Using same viewmodel() methods from androidx
Cons: Having viewmodel logic in Node
Alternative:
Create custom integration point, eg ViewModelIntegrationPoint and set of extetion functions to the node to create viewmodels inside node. Crash(?) when node.integrationPoint doesn't cast to ViewModelIntegrationPoint.
DI: Yuri already mentioned in #303 but I'm not sure what we can do about that
Check list
CHANGELOG.mdif required.