Nav scoped view models#817
Conversation
|
I've updated the code to survive process death. Would appreciate if you also reviewed this. I've taken your previous feedback into consideration and creating view models on the fly, using extension functions for navigation and moved the For people willing to test this branch (& for my future ref):
|
|
It might be a while till I can go over bigger refactors like this. |
twizmwazin
left a comment
There was a problem hiding this comment.
Would love to get this merged once rebased
54592b3 to
b614511
Compare
b614511 to
d99a123
Compare
|
Note regarding changes made while resolving merge conflicts:
|
I'll gladly do and give it a look tonight. |
…r default sort and listing type.
|
I've opened a new issue for the filters #886. For now, I've pushed a commit to ensure that the filters (in home & community activity) are read form the account variable. Ig we can continue with merging this PR and take up the filters thing separately. Any other issues with this branch, do let me know. |
There was a problem hiding this comment.
I only reviewed the files regarding post creation and editing because I honestly can't wrap around my head about that amount of abstraction you added without investing a serious amount of time which I just don't have atm. (Hence my rather small PRs)
What I reviewed looked correct though and post creation and editing acted as expected.
Thanks a lot for taking the time! Will make the changes you requested. I think that's the hard part, reviewing changes. I'll try to document these changes better. |
Thank you for further describing the changes you've made. I really appreciate your effort to make these changes as understandable as possible. 🙂 |
|
I have question regarding |
|
I was trying to keep the changes small in this PR since it was getting
harder to review. Other than the `initialized` field the view models don't
have any other changes.
Constructor initialization of view models is safer and we should try to do
that.
…On Fri, 1 Sept, 2023, 9:49 am Maarten Vercruysse, ***@***.***> wrote:
I have question regarding initializeRoute, why did you take this approach
over just having the necessary fields passed to the constructor of the
ViewModel. Passing it in the constructor is much more typesafe as we now
don't have to set each field as nullable that we have to check constantly
—
Reply to this email directly, view it on GitHub
<#817 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ANLBAUM4L76V4ATIW32RZGDXYFO5XANCNFSM6AAAAAAZQIAPA4>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
|
Thanks for your quick response, I'll make a issue for that and work on refactoring that |
|
I do have another question, For communityViewmodel you did this val communityViewModel: CommunityViewModel = viewModel(
remember(it) { navController.getBackStackEntry(Route.Graph.COMMUNITY) },
)
I am not sure what this does or why it exists? Why can it not be embedded in CommunityAcitivity? |
|
navController.getBackStackEntry(Route.Graph.COMMUNITY)
This scopes the view model to the route with name Route.Graph.COMMUNITY
The community activity and community sidebar need to utilise the same view
model. I've made both these activities as subroutes of
Route.Graph.COMMUNITY.
So when creating a view model we don't scope it to the route but instead to
it's parent. When you navigate to the sidebar, it ends up using the view
model scoped to the parent.
So both community activity and community sidebar activity aren't embedded.
…On Fri, 1 Sept, 2023, 10:56 pm Maarten Vercruysse, ***@***.***> wrote:
I do have another question,
For communityViewmodel you did this
val communityViewModel: CommunityViewModel = viewModel(
remember(it) { navController.getBackStackEntry(Route.Graph.COMMUNITY) },
)
I am not sure what this does or why it exists?
Why can it not be embedded in CommunityAcitivity?
—
Reply to this email directly, view it on GitHub
<#817 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ANLBAUJ222UYPDL2IPSQXFDXYILERANCNFSM6AAAAAAZQIAPA4>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
|
Hmm I see but I am thinking of simplifying this by just passing the CommunityView into Sidebar using the addReturn. Would a separate community_graph still be needed then? |
|
Interesting. Give it a try. Make sure to put the addReturn lines within the
NavController.toCommunitySidebar() extension method. It should work and the
dependency is also explicit ig.
…On Fri, 1 Sept, 2023, 11:30 pm Maarten Vercruysse, ***@***.***> wrote:
Hmm I see but I am thinking of simplifying this by just passing the
CommunityView into Sidebar using the addReturn. Would a separate
community_graph still be needed then?
—
Reply to this email directly, view it on GitHub
<#817 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ANLBAUM5S4NOAFCKKEAZPHDXYIPDPANCNFSM6AAAAAAZQIAPA4>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
|
Alright got it working, had to make a reverse addReturn/consumeReturn |
Since PR #765 was too big, splitting it up into multiple PR to make it easier to review.
Scoped view models
Closes #704
Closes #402
Closes #774
Closes #835
The following is the existing design where the view models reside in the

MainActivityand are passed to all the activities:The following is the design implemented by the PR:

route = Route.Graph.ROOT. This is created on the fly whenever you see something liketransferPostEditDepsViaRoot = navController.rootChannel<PostEditDeps>().PostEditReturn.POST_VIEW) and then navigate back. On navigating back, the parent will recompose and we check if a value has been set inPostEditReturn.POST_VEWand update the post accordingly.Other Notes:
navController.toPostEdit(Channel<PostView>, PostView). This way it's a compile time error to forget providing the dependencies necessary to initialize an activity.navController.takeDepsFromRoot<PostView>()is called). The updated data on the back stack entry'sSavedStateHandleis also in JSON. Both survive process death.InitializeRouteandConsumeResultwhich are self-explanatory.