Comments (21)
I'm already one step ahead and began poking around last Friday @gpeal. I'll be OOO next week, so probably I'll be able to invest some time into this.
I'll let you know in case I have any questions, but so far the advantages of a healthy, well structured codebase are paying off and the process has been very straightforward (thanks for that guys).
from mavericks.
@mradzinski I'm going to close this to keep the backlog clean but if you want to write a wiki page on how to use MvRx with conductor or need something else specific, feel free to open a new issue!
from mavericks.
@mradzinski I haven't used Conductor so it's hard to say. What do you me by delegation exactly? We use property delegates for some things.
from mavericks.
Hey @gpeal, sorry, I was sleepy AF last night and didn't take enough time to give you some more context 😅 .
To simply put it, Conductor is a library to build View-based Android applications. You don't use Fragments but Controllers (which at the very end are backed up by a Fragment) which have their own specific lifecycle (very similar to the one of Fragment but a bit more predictable/simplified).
My question could be summarized into: If I have a Controller (or any View for what matters) implement MvRxView
, should that suffice for that Controller to become the View of MVVM (or of MvRX in this context)? That's what's basically happening under the hood of a BaseMvRxFragment
for example.
I know there're a bunch of extensions which I would've to change a bit here and there, but I guess the most important part for this to work is to have a Controller implelent MvRxView, right?
Thanks!
from mavericks.
@mradzinski A lot of MvRx just takes a LifecycleOwner as a parameter so if your View implements that, it may just work. Feel free to try it!
from mavericks.
Hey @gpeal, Correct me if I'm wrong, but I'm not entirely sure implementing LifecycleOwner
will be enough mostly because MvRx is prepared to be used with Fragments and Activities but not with an application made out of something entirely different such as Conductor Controller
s. Although I can make a Conductor's Controller (or any View with a life cycle) implement LifecycleOwner
and ViewModelStoreOwner
pretty much easily, my biggest concern comes from the fact that there's a big dependency between MvRx and Fragments.
For example: as far as I know activityViewModel
and fragmentViewModel
will simply not work in other scenarios other than what their names suggest. Passing arguments to the initial state through KEY_ARG
will also not work (check MvRxViewModelStore.restoreViewModels
). MvRxViewModelProvider
also assumes Activities or Fragments. And I guess there's a big etc.
I don't think any View implementing LifecycleOwner
as you mentioned suffice for MvRx to work. I think it takes a bunch more than that to have something working. Again, I might be completely wrong here, so I'm just looking up for a bit of guidance on the internals of MvRx and what would need to be implemented if deviating from the usage of Fragments.
Cheers and thanks again!
from mavericks.
@mradzinski To do this correctly might require you to clone the project and start poking around. I'm happy to answer any questions you have though. Just @gpeal me on replies here so I get a notification for it.
from mavericks.
@mradzinski Any update here?
from mavericks.
We've successfully integrated conductor with viewmodel, primarily utilizing this https://github.com/miquelbeltran/conductor-viewmodel/blob/master/conductor-viewmodel/src/main/java/work/beltran/conductorviewmodel/ControllerLifecycleOwner.java
I'm toying with the idea of forking MvRx and implementing a base Controller class in similar fashion as MvRx but realized that you guys @gpeal are manually saving the viewmodels. Afaik, using the factory with the ViewModelProvider would mean this is done automatically, so I'm wondering what the motivation was behind manually persisting the viewmodels
from mavericks.
@wugeorgeq We do use the normal ViewModelProvider but we extend/intercept it so we can properly handle things like process restoration with @PersistState
https://github.com/airbnb/MvRx/wiki#restoration-in-a-new-process
from mavericks.
@gpeal Sorry, got quite busy with some projects. Haven't lost interest, though I need to find some spare time to toy with this. I'll keep you guys posted.
from mavericks.
Ah my bad! I wasn't aware of difference between config change and process death in ViewModels and incorrectly assumed that the library was doing more than it needed to. Embarrassing D:
from mavericks.
@gpeal I've resumed this attempt and found out its not going to be possible given the current project state. Having ViewModelContext()
sealed (link) prevents creating a new ViewModelContext
which is needed as part of MvRxViewModelProvider.get()
.
Is there a reason why ViewModelContext
needs to be sealed? Just wondering how possible it is to make it open
and hence extensible.
from mavericks.
@mradzinski Can you use ActivityViewModelContext
for conductor?
from mavericks.
@gpeal yes, but that wouldn't mean the VM would be scoped to the Activity instead of the Controller? (which acts as a Fragment)
from mavericks.
I forked MvRx and I'm pretty close to achieve the integration @gpeal, the only problem I have so far is that VM's are not surviving config changes, hence a new instance is being created every time with an initial state. Any idea why that might be happening? I'm happy to push my changes to the forked version (bare in mind it's a proof of concept and not even close to a final implementation).
from mavericks.
@mradzinski ViewModelProviders from Jetpack actually does the retaining so you might want to look into that.
The ViewModelContext is just created to give you context to use for DI/VM creation. The actual scope of your ViewModel depends on the ViewModelProvider you use.
from mavericks.
@gpeal Isn't MvRx using it's own implementation of a ViewModelProvider, ViewModelStore which takes care of restoring the VM state throughout args and its own VM factory?
from mavericks.
So, I managed to make everything work, there was some lifecycle issues on my end. Much to my regret there's no actual way to make this an extension to MvRx. MvRx is currently tied to Activities and Fragments, and I had to modify plenty of internal methods and classes to make this to work.
@gpeal If at any point you guys at Airbnb become interested in Conductor, or simply MvRx evolves allowing some sort of extensibility then ping me here and I'll PR all this.
from mavericks.
@mradzinski it would be great if you shared your hard work as a library
from mavericks.
@manueldidonna Like I said, I'll not be sharing it as a library due to how hard it'll be to keep it up to date with MvRx (it would need to be an exact clone of this repo with a few methods here and there).
You can check my implementation here though: https://github.com/mradzinski/MvRx/tree/matias/conductor-integration
You can check the latest commit on that branch to understand better why this can't be made a module itself.
from mavericks.
Related Issues (20)
- 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?
- java.lang.SecurityException: One of RECEIVER_EXPORTED or RECEIVER_NOT_EXPORTED should be specified
- java.lang.IllegalStateException HOT 1
- Value classes break State class no zero argument constructor usage HOT 1
- Discuss whenStarted function deprecation HOT 7
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.