-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
104 additions
and
96 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
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
53 changes: 53 additions & 0 deletions
53
trace/src/commonMain/kotlin/dev/datlag/aniflow/trace/TraceRepository.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,53 @@ | ||
package dev.datlag.aniflow.trace | ||
|
||
import dev.datlag.aniflow.model.CatchResult | ||
import dev.datlag.aniflow.trace.model.SearchResponse | ||
import kotlinx.coroutines.flow.* | ||
import kotlinx.serialization.Serializable | ||
|
||
class TraceRepository( | ||
private val trace: Trace | ||
) { | ||
|
||
private val byteArray = MutableStateFlow<ByteArray?>(null) | ||
val response: Flow<State> = byteArray.transform { | ||
return@transform if (it == null || it.isEmpty()) { | ||
emit(State.None) | ||
} else { | ||
emit( | ||
State.fromResponse( | ||
CatchResult.repeat(2) { | ||
trace.search(it) | ||
}.asNullableSuccess() | ||
) | ||
) | ||
} | ||
} | ||
|
||
fun clear() = byteArray.update { null } | ||
fun search(array: ByteArray) = byteArray.update { array } | ||
|
||
@Serializable | ||
sealed interface State { | ||
@Serializable | ||
data object None : State | ||
|
||
@Serializable | ||
data class Success( | ||
val response: SearchResponse, | ||
) : State | ||
|
||
@Serializable | ||
data object Error : State | ||
|
||
companion object { | ||
fun fromResponse(response: SearchResponse?): State { | ||
return if (response == null || response.isError) { | ||
Error | ||
} else { | ||
Success(response) | ||
} | ||
} | ||
} | ||
} | ||
} |
89 changes: 0 additions & 89 deletions
89
trace/src/commonMain/kotlin/dev/datlag/aniflow/trace/TraceStateMachine.kt
This file was deleted.
Oops, something went wrong.