-
Notifications
You must be signed in to change notification settings - Fork 90
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
Feature to Feature binding #103
Comments
Hi @LinKR. class BootstrapperImpl(
private val feature1: Feature1
) : Bootstrapper<Wish> {
override fun invoke(): Observable<Wish> =
Observable.wrap(feature1.news).map { SomeWishOfFeature2 }
} |
Also I would rather use |
@zsoltk I have an issue related to feature-to-feature binding that I'm having difficulty finding a good solution, maybe you'd have a different suggestion to get around this issue though. Hopefully this example will explain my problem enough... There are two features; a GalleryFeature and CameraFeature each of which have their own Fragments. The GalleryFragment receives an observable list of media items to display and the CameraFragment allows the user to add more media items to their gallery. When the user takes a photo/video in the CameraFragment, the CameraFeature sends the file path for the new media item to the GalleryFeature so the new media item will appear in the GalleryFragment after the CameraFragment pops off the backstack. The GalleryFeature does a little bit of extra processing on the new media item as well so I'd like to start that without having to wait for the GalleryFragment to resume. My issue is binding these features since there is a bit of a forward referencing problem. What I tried doing was using DI (I'm using Koin) to inject the CameraFeature into the GalleryFeature Bootstrapper as suggested above and then the same CameraFeature instance would be injected into the CameraFragment. This all works fine but... The issue with this approach is that the CameraFeature instance will always be the same, so if I have two GalleryFragments on the backstack each with their own GalleryFeature instance, those GalleryFeatures will have the same CameraFeature instance injected by Koin. Now when the CameraFeature sends the new media item through the NewsPublisher, it will go both GalleryFeatures when I only wanted the feature of the GalleryFragment that's at the top of the stack to receive the new media item. How do I avoid this situation? I'm not sure what's the best approach for passing data back to the "calling" feature, which in this example is the GalleryFeature. Without running into the issue of publishing a news update to all the GalleryFeatures, if there are multiple GalleryFragment instances on backstack. As a workaround for now, I ended up forking the repo and adding the concept of a FeatureSet as way to group related Features that work together during some portion of the flow in the app. Similar concept to the NavGraph Scoped ViewModels that were recently introduced in the Jetpack Navigation Component. Each FeatureSet would have its own instances of the Features thus avoiding the scenario above, it would be similar to a ViewModelStore. My solution is quite rough at the moment so maybe I'll refine it further if there isn't a better way to get around my issue. Any suggestions would be appreciated, thanks! |
Hey @VGJohn We have NOTE: lifecycle event does not necessary mean Android lifecycle, it can be anything custom (see For your case, I would try to connect features from the outside rather than in the bootstrapper (in the class GalleryFragment {
val cameraFeature by inject()
val galleryFeature = GalleryFeature()
override fun onCreate(state: Bundle?) {
lifecycle.resumePause {
cameraFeature.news to galleryFeature using CameraToGallery
}
}
} Check out binder section for more details :) We have tried to implement something similar to described |
@ShikaSD I tried using the Binder with the fragments lifecycle but it blocks the GalleryFeature from starting processing the new media item until the fragment lifecycle is resumed. I'll play around with making a custom lifecycle though, sounds like that would be a better solution. Thanks for the help! |
@VGJohn I definitely suggest I didn't understand why you need lifecycle to be resumed? You can use extension methods for wider scopes. I suggest looking at On the other hand, I should definitely update the docs to not suggest injecting |
Hi.
In best practices you wrote next code
But i can't understand best way to do this map , because news is ObservableSource and don't have map function.
Maybe you have some ktx extensions for this?
Now i do this.
The text was updated successfully, but these errors were encountered: