Is there any state management library for KMP with...
# multiplatform
v
Is there any state management library for KMP with flow and PagingData support?
j
A little bit uncertain what refer to as state management library, but if refer to only paging and Flows there is androidx paging compose 🙂 Just check to use version https://developer.android.com/jetpack/androidx/releases/paging#3.3.0-alpha02 or later to get proper KMP support 🙂
v
@Joel Denke the thing is As of now i am using SQLDelight for managing state, so for example if i like a post in one screen I can see it liked in all other screens, thanks to state management But this DB is getting quite heavy and overkill for my use case, i dont want to persist data, just need in-memory state management
j
Not entirely sure what you want to have, but sounds to me want to introduce cache/repositories then 🙂 Maybe https://square.github.io/workflow/ is suitable for your case.
v
I'll check this out Basically what i want is Redux toolkit but for KMP with Flows and PagingData support
j
fritz2 has nice state management based on flows.
j
Maybe I am totally wrong here, but feels like you want to checkout UDF if this is a compose multiplatform ui? See https://developer.android.com/jetpack/compose/architecture#udf Sorry if I am mistaken, maybe not using Compose. But if using that, I think its what you looking for.
v
Yes @Joel Denke i am using compose and following udf too, android docs suggest using a db which is fine, but what if I dont need a persistent storage but just an in memory one Room allows it if im not wrong not sure about SQLDelight
j
You can use SQLDelight with a database driver configured for in-memory. But if you're not actually doing any data querying or persistence, I agree you probably don't need such a library. Can you not just use
MutableStateFlow
directly? Paging in-memory data isn't really necessary, since it's already present in memory. The purpose of paging is to only load a subset of total data into memory at once.
By the way, my JSON database KMP library, Kotbase, also supports flows and paging, but it's also primarily for data persistence.
v
I do query data My setup uses Paging3, I have a Remote Mediator and ui is using
LazyPaginItems
How would "not using `PagingData`" work? By "using
MutableStateFlow
" do you mean keeping a mutable state flow in the singleton repository class and emitting in it after an API call and all ViewModels collecting from that?
Thanks, I'll also take a look at Kotbase
j
You could use a
MutableStateFlow
in a repository for a reactive in-memory data store, yes. What sort of data is it that you don't need to persist? And what type of queries are you doing? Is this data coming from a backend and you're just caching it locally in memory?
v
Example of query
Copy code
SELECT * FROM PostEntity
WHERE creatorId = :creatorId
ORDER BY createdAt DESC
LIMIT :limit OFFSET :offset;
My main use-case of having a db is to observe changes in data in all screens, persistence is not needed, I clear db on app start Data comes from a backend, and I save it in SQL Delight DB to observe changes everywhere in app Example, if I like a post, i make api call then update it in DB, so everywhere its shown as liked