Skip to content
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

[🚀] Add Koin Integration #62

Open
5 tasks
Nek-12 opened this issue Apr 25, 2024 · 3 comments
Open
5 tasks

[🚀] Add Koin Integration #62

Nek-12 opened this issue Apr 25, 2024 · 3 comments
Assignees
Labels
feature New feature or request
Milestone

Comments

@Nek-12
Copy link
Member

Nek-12 commented Apr 25, 2024

Description (required)

  • Koin scopes tied to the store's lifecycle
  • Automatically closing scopes
  • Koin Containers
  • Koin Scopes for stores (take from the sample app?)
  • StoreViewModel injection from the sample app - can also make it multiplatform?
@Nek-12 Nek-12 added the feature New feature or request label Apr 25, 2024
@Nek-12 Nek-12 added this to the 3.0 milestone Apr 25, 2024
@Nek-12 Nek-12 self-assigned this Apr 25, 2024
@Nek-12 Nek-12 modified the milestones: 3.0, 3.1 May 25, 2024
@y9vad9
Copy link

y9vad9 commented May 26, 2024

it would be perfect, sometimes I don't want to provide anything explicitly, but still use it, for example, in the plugin with dependency that provided somewhere at the top.

In brief, my case is the following:
I want to handle authorization exception and navigate users to login page, when UnauthorizedException is happened. I use Koin for the DI and it would perfectly match my need. I can handle exceptions within plugin system and another integration with Koin will help a lot.

@Nek-12
Copy link
Member Author

Nek-12 commented May 26, 2024

Thanks for the feedback, unfortunately koin did not make it to 3.0, but yeah, I'm thinking of exactly the same use-case. It's going to be worked on next after I add some more docs.

But your use-case is already possible with existing tools.

You could grab the setup from docs or the sample app and create a plugin:

fun <S: MVIState, I: MVIIntent, A: MVIAction> authOnErrorPlugin(
    onSignInNeeded: suspend () -> Unit
) = plugin<S, I, A> {
    onException { e -> 
       if (e !is UnauthorizedException) return@onException e
       onSignInNeeded()
       null
    }
}

In onSignInNeeded, you can send an event to a container that will handle navigation events, something like AppEventContainer, call your navigator callback, or just request another user (it depends on your stack). I personally like the approach with a separate container for events like this.

An even better approach would be to observe the current user object in whileSubscribed and redirect if the user is null for example.

@y9vad9
Copy link

y9vad9 commented May 26, 2024

Your way seems reasonable, but I just don't like singletons (and at the same time, I don't want to provide to every screen component this handler). For now I think about some way around Decompose to provide such handler from the top (but a bit busy with university at the moment).

@Nek-12 Nek-12 moved this from Backlog to In Progress in FlowMVI Roadmap Jul 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request
Projects
Status: In Progress
Development

No branches or pull requests

2 participants