Comments (13)
No, I don't think so, as the subscriptions would be disposed in onDestroyView
so they can be safely recreated in onCreateView
.
from mavericks.
@BenSchwab Yeah, makes sense. Want to take a stab at it?
from mavericks.
Sometimes having all subscriptions in onCreate
is really annoying since views have not been created here which means everything used in the callback need to be a member of the fragment instead of a local variable. And it's also error prone cuz this is not guaranteed by any compile-time checking .
Why not try using getViewLifecycleOwner
instead of this
for a fragment? This only requires upgrading support library version to 28.
from mavericks.
@justsosoxd That should be okay because the subscription will only get called when the fragment is in the STARTED
lifecycle.
from mavericks.
@BenSchwab What is actionable here?
from mavericks.
@justsosoxd wouldn't using getViewLifecycleOwner()
possibly make things even worse? The view lifecycle can be even shorter in case of detached Fragments than the one of the Fragment itself as per the documentation.
from mavericks.
@gpeal We could start logging a warning (or crash) if you subscribe after onCreate
? Or maybe we could keep a list of active subscribers references and no-op if one already exists? (I would need to look into how references work on lambdas, not sure if this is possible.)
from mavericks.
@ubuntudroid If I get it right, the problem we need to solve here is duplicated subscription when fragments are added to backstack then resumed. view lifecycle can avoid this problem as the subscription will be canceled when fragment is added to backstack. why would it make things worse?
from mavericks.
@justsosoxd uh, I think I got the problem statement wrong. After rereading I think you are actually right. Sorry for the confusion!
from mavericks.
@BenSchwab True, we could check lifecycle state and make sure that it equals CREATED.
from mavericks.
@BenSchwab What do we want to do here?
from mavericks.
I think we can change subscriptions made after onCreate to use getViewLifecycleOwner
.
Need to add tests, but this is what it would look like: b76d71b
from mavericks.
@BenSchwab How would using the view lifecycle owner solve this? Wouldn't you still have duplicate subscriptions?
from mavericks.
Related Issues (20)
- How to create ViewModels in dynamic feature?
- Is there a way to get the MavericksViewModel to refresh when returning to a Fragment? HOT 4
- Dagger in a single activity compose app (no fragment)
- Build doesn't work on JDK 17: `Unrecognized VM option 'CMSClassUnloadingEnabled'`
- MavericksLauncherMockActivity crashes if there's no App.Theme or if fragments are Hilt fragments HOT 1
- Feature Request: avoid shipping MockableMavericksView with release builds
- Feature Request - Allow retainValue parameter of type S.() -> Async<T> in MavericksRepository HOT 1
- Calling `mavericksActivityViewModel` in fragment, not working properly HOT 1
- Type com.airbnb.mvrx.AndroidStrictModeExtensionsKt is defined multiple times HOT 1
- possible incompatibility with Kotlin coroutines 1.7.0 HOT 2
- Using androidx.lifecycle:lifecycle-runtime-ktx:2.6.1 problems HOT 13
- Fail State call twice and make error HOT 2
- how to use stateflow in MavericksViewModel HOT 2
- How can I use MavericksView in a View or a Layout
- compare with mvc,mvp,mvvm HOT 2
- The viewModel() method may be missing the postInvalidate() logic. HOT 2
- Hilt and ViewModel initialization with Navigation Component arguments HOT 6
- Exploration of the correct way to update state with List<Data> in state HOT 1
- Ensure that your state properties properly implement hashCode. HOT 7
- I wanted to use the latest version of Epoxy, Mavericks, Paging3 (Epoxy Paging3), but couldn't find the Demo. Is it possible to combine all three?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mavericks.