Created
August 7, 2022 13:25
-
-
Save motorro/5e9f09281d210ddda89ea745209985b6 to your computer and use it in GitHub Desktop.
Login state factory implementation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@LoginScope | |
class LoginStateFactoryImpl @Inject constructor( | |
host: WelcomeFeatureHost, // External interface | |
renderer: LoginRenderer, // Renderer | |
private val createCredentialsCheck: CredentialsCheckState.Factory // Concrete state factory | |
) : LoginStateFactory { | |
// Dependencies common for each state provided through the context | |
private val context: LoginContext = object : LoginContext { | |
override val factory: LoginStateFactory = this@Impl | |
override val host: WelcomeFeatureHost = host | |
override val renderer: LoginRenderer = renderer | |
} | |
override fun passwordEntry(data: LoginDataState): LoginState { | |
// Create explicitly | |
return PasswordEntryState(context, data) | |
} | |
override fun checking(data: LoginDataState): LoginState { | |
// Use provided state-factory | |
return createCredentialsCheck(context, data) | |
} | |
override fun error(data: LoginDataState, error: Throwable): LoginState { | |
// Create explicitly | |
return ErrorState(context, data, error) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment