Closed russhwolf closed 3 years ago
Datastore is now in alpha
@russhwolf, since DataStore is based on Flow
, will it break the current API? Or will you add a Flow
APIs too?
I wouldn't want break the existing API. Probably I'd add an alternate interface based on suspend funs or flows, and a wrapper to convert existing implementations to that interface so you can control both from common. Another option is wrapping everything in runBlocking
, but that's much more likely to result in someone accidentally misusing stuff and blocking their main thread.
I'd love to hear what other ideas people have.
Supporting a flow API which emit after each "insertion" is great (I used DataStore for this). This behavior is used by a lot of libraries (room, dataStore, sqldelight, etc).
I think it shouldn't use runblocking, if anyone need this flow so, they can wrap the flow with runblocking (indeed I used this with dataStore too).
Flow would be nice (there's a prototype in #37 of wrapping flows around the existing listeners) but I'm leaning toward suspend fun by default so that commonality with non-observable implementations (in particular, JS) is easier. Still need to do more thinking and prototyping though.
Maybe this can be interesting
https://twitter.com/ianhlake/status/1326598994408038400?s=19
My current thinking is to have both FlowSettings
and SuspendSettings
interfaces, and converters between them and the standard Settings
and ObservableSettings
. Any Settings
implementation can be wrapped to SuspendSettings
pretty easily, but FlowSettings
can only wrap around ObservableSettings
because you need to set a listener to be able to get new updates in its Flow
s. There would be DataStore
implementations of both, so you could use the one that fits your use-case better depending on what other implementations you need interop with.
I want to have a version of this ready in the near future as part of 0.7
This has been released in 0.7
The Android team is quietly working on a SharedPreferences replacement called datastore. It'd be nice to have a module that wraps that, once it's ready. An interesting wrinkle is that it has fully coroutine-based APIs so it's going to be non-trivial to wrap with the existing
Settings
interface.