burnoo / compose-remember-setting

Compose Multiplatform library for remembering state persistently (based on Multiplatform Settings)
https://burnoo.github.io/compose-remember-setting/
Apache License 2.0
29 stars 0 forks source link

androidx datastore preferences #38

Closed mahramane closed 1 week ago

mahramane commented 2 months ago

Hi I think datastore-preferences is better than multiplatform-settings. and in config you only get preferences: DataStore<Preferences> and save data on it. check out https://developer.android.com/topic/libraries/architecture/datastore. it support android, ios, jvm

burnoo commented 2 months ago

Hi, I don't think it's better, I chose Multiplatform Settings on purpose.

One of the Compose Multiplatform targets is wasmjs and DataStore does not support it. Using it would make the library not compatible with Compose Web and I wanted to avoid that.

Multiplatform Settings is a very nice abstraction over data storing layer and allows to use DataStore if you need it (docs). Then DataStoreSettings can be used by compose-remember-setting:

@Composable
val dataStore: DataStore // = ...
val settings: ObservableSettings = DataStoreSettings(dataStore)

fun WithSettings(content: @Composable () -> Unit) {
    CompositionLocalProvider(
        LocalComposeRememberSettingConfig provides ComposeRememberSettingConfig(
            observableSettings = settings
        ),
        content = content
    )
}