-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Shared: Send step viewed request after feature destroying (#1098)
^ALTAPPS-1297
- Loading branch information
1 parent
54c0160
commit 5b64552
Showing
3 changed files
with
39 additions
and
2 deletions.
There are no files selected for viewing
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
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
37 changes: 37 additions & 0 deletions
37
...ed/src/commonMain/kotlin/org/hyperskill/app/step/presentation/ViewStepActionDispatcher.kt
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package org.hyperskill.app.step.presentation | ||
|
||
import kotlinx.coroutines.CompletableJob | ||
import kotlinx.coroutines.CoroutineScope | ||
import kotlinx.coroutines.Dispatchers | ||
import kotlinx.coroutines.Job | ||
import kotlinx.coroutines.SupervisorJob | ||
import kotlinx.coroutines.launch | ||
import org.hyperskill.app.step.domain.interactor.StepInteractor | ||
import ru.nobird.app.presentation.redux.dispatcher.ActionDispatcher | ||
|
||
internal class ViewStepActionDispatcher( | ||
private val stepInteractor: StepInteractor | ||
) : ActionDispatcher<StepFeature.Action, StepFeature.Message> { | ||
|
||
private val coroutineScope: CoroutineScope = | ||
CoroutineScope(SupervisorJob() + Dispatchers.Main.immediate) | ||
|
||
private var isCancelled: Boolean = false | ||
|
||
override fun handleAction(action: StepFeature.Action) { | ||
if (!isCancelled && action is StepFeature.InternalAction.ViewStep) { | ||
coroutineScope.launch { | ||
stepInteractor.viewStep(action.stepId, action.stepContext) | ||
} | ||
} | ||
} | ||
|
||
override fun setListener(listener: (message: StepFeature.Message) -> Unit) { | ||
// no op | ||
} | ||
|
||
override fun cancel() { | ||
isCancelled = true | ||
(coroutineScope.coroutineContext[Job] as? CompletableJob)?.complete() | ||
} | ||
} |