russhwolf / multiplatform-settings

A Kotlin Multiplatform library for saving simple key-value data
Apache License 2.0
1.7k stars 67 forks source link

Request: FlowSettings for JS #139

Closed sproctor closed 6 months ago

sproctor commented 1 year ago

I'm willing to take a first stab at this. My idea is to have an internal state to observe when a value changes. This wouldn't notice modification from an external source, but works for my use-case. Maybe an event listen can be used to watch for external changes, but I'm not familiar with that.

russhwolf commented 1 year ago

I've been reluctant to go with a solution that holds internal state at the Settings level, because it makes interop unintuitive, If you're interacting with your storage both from shared code and from the JS layer, you'd get inconsistent behavior.

Ideally it would be possible to use the event listener that exists for storage changes, but unfortunately it doesn't fire for events that are triggered from the same window. So it hasn't been clear to me what the best path forward is.

sproctor commented 1 year ago

Makes sense. It's pretty simple to implement locally and then the behavior is obvious.

To implement in the library, maybe install a listener and require an annotation warning about it not observing changes to the storage object from a different context on the same page? I don't know if it's worthwhile, this is just an idea.

russhwolf commented 6 months ago

I'm going to close this because your proposed solution will be covered by #155