patrykandpatrick / opto

A lightweight Preferences DataStore wrapper.
Apache License 2.0
4 stars 1 forks source link

Missing APIs, can't migrate from `com.patrykmichalik.opto` #1

Closed Goooler closed 1 year ago

Goooler commented 1 year ago

Can't migrate from

import com.patrykmichalik.opto.core.firstBlocking
import com.patrykmichalik.opto.core.onEach

And the compose module is missing?

patrickmichalik commented 1 year ago

Hello! Along with moving Opto’s source code to this organization and republishing it under a new group ID, I have rewritten the library and slimmed it down. We’d like to keep Opto relatively light, and functions such as firstBlocking or onEach were minimally beneficial (and, to a certain degree, out of the scope of the project). With that said, since they are extension functions, you can restore them by adding them to your code base:

fun <T> Preference<T>.firstBlocking() = runBlocking { get().first() }

fun <T> Preference<T>.onEach(launchIn: CoroutineScope, block: suspend (T) -> Unit) {
    get().onEach(block).launchIn(launchIn)
}

Below is state (from the compose module). This has been removed both for the reason described above and because it’d be architecturally preferable not to expose Preference to composables, mixing UI and business logic.

@Composable
fun <T> Preference<T>.state(initial: T? = null) = get().collectAsState(initial)