Unlimity/jotaro

StateFlow observable preferences

Opened this issue · 2 comments

With StateFlow now available and the .stateIn() operator coming soon, it would be nice to be able to delegate sharedpreferences to a MutableStateFlow so that we can also observe the preference changes.

Interfaces could expose
var observablePref: StateFlow<T>
properties if the consumer is interested in change notifications in addition to the standard
var pref: T

and creating test doubles with these interfaces would just implement with a MutableStateFlow(default = T) builder.

I had started an implementation of this myself before I found that this library already does the first part.
Would you be willing to incorporate such a feature in this library?
Are PRs encouraged or is this something you would want to implement yourself?

Hey there, thanks for reaching out!
I'm always all in for coroutines and it's features and contributions are highly appreciated.
So if you have an implementation ready, please don't hesitate to create PR.

Although I might point out that in case of StateFlow you will have to make the property itself immutable and promote mutable flow:

val myPreference: MutableStateFlow<T>