MobileNativeFoundation / MobileNativeFoundation/Store
[BUG] store.clear does not trigger a refetch in the collected stream (not sure if this is a bug or expected behavior)
Nobody has claimed this yet.
- Dominant language
- Kotlin
- Stars
- 3.4k
- Forks
- 217
- Avg merge
- 18m
- Merged PRs (30d)
- 4
Description
Describe the bug
In our application we have instances of the Store that use cache5 in the source of truth.
In some cases we need to invalidate the content of the store and we use store.clear(), but even if the cache is cleared (because deleteAll is invoked), no new values are emitted from the store.stream(..) ).
To Reproduce
Steps to reproduce the behavior:
Let's suppose we have a:
class Store5Cache:
Cache<MyKey, MyValue> by CacheBuilder<MyKey, MyValue>().build()
and the store:
internal class Store5Store(
store5Cache: Store5Cache,
myService: MyService
) : Store<MyKey, MyValue> by storeBuilderFromFetcherAndSourceOfTruth(
fetcher = Fetcher.of { myKey: MyKey ->
myService.getMyValue(myKey)
},
sourceOfTruth = SourceOfTruth.of(
nonFlowReader = { myKey -> store5Cache.getIfPresent(myKey) },
writer = { myKey, myValue -> store5Cache.put(myKey, myValue) },
delete = { myKey -> store5Cache.invalidate(myKey) },
deleteAll = { store5Cache.invalidateAll() },
)
).build()
and a collector
fun stateStream() = store5Store.stream(StoreReadRequest.cached(defaultKey, refresh = true))
.map {
when (it) {
is StoreReadResponse.Data -> it.dataOrNull()?.let { data -> Loaded(data) } ?: LoadedWithNoData
is StoreReadResponse.Error.Exception -> Error
is StoreReadResponse.Error.Message -> Error
is StoreReadResponse.Loading -> Loading
is StoreReadResponse.NoNewData -> NoNewData
}
}
After the emission of the first Loaded(data), if we call store5Store.clear() no values are emitted after the first.
Expected behavior
We expect that once the store is cleared, a new value will be fetched, but nothing happens.
Smartphone (please complete the following information):
- Store Version [5.0.0]
Additional context
Store5Test.zip
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the Store5Test.zip reproduction and the Store 5.0.0 behavior around store.clear() and store.stream(StoreReadRequest.cached(..., refresh = true)). Observe whether clear invokes deleteAll and whether the collected stream emits afterward. Done means the expected post-clear fetch behavior is established and covered by a reproducible test.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- kotlin
- Domain
- data
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100