Comments (4)
I ran into this requirement today. I couldn't figure out whether there was any way to iterate over all keys in a store.
from store.
@digitalbuddha is this something we want to support? I can send a PR if it is 😃
New Store
API might look like this:
interface Store<Key : Any, Output : Any> {
/**
* Return a flow for the given key
* @param request - see [StoreRequest] for configurations
*/
fun stream(request: StoreRequest<Key>): Flow<StoreResponse<Output>>
/**
* Purge a particular entry from memory and disk cache.
* Persistent storage will only be cleared if a delete function was passed to
* [StoreBuilder.persister] or [StoreBuilder.nonFlowingPersister] when creating the [Store].
*/
suspend fun clear(key: Key)
/**
* Purge all entries from memory and disk cache.
* Persistent storage will only be cleared if a deleteAll function was passed to
* [StoreBuilder.persister] or [StoreBuilder.nonFlowingPersister] when creating the [Store].
*/
suspend fun clearAll()
}
New persister APIs for deleting disk cache:
/**
* Connects a ([kotlinx.coroutines.flow.Flow]) source of truth that is accessed via [reader], [writer] and [delete].
*
* For maximal flexibility, [writer]'s record type ([Output]] and [reader]'s record type
* ([NewOutput]) are not identical. This allows us to read one type of objects from network and
* transform them to another type when placing them in local storage.
*
* A source of truth is usually backed by local storage. It's purpose is to eliminate the need
* for waiting on network update before local modifications are available (via [Store.stream]).
*
* @param reader reads records from the source of truth
* @param writer writes records **coming in from the fetcher (network)** to the source of truth.
* Writing local user updates to the source of truth via [Store] is currently not supported.
* @param delete deletes records in the source of truth for the give key
* @param deleteAll deletes all records in the source of truth
*
*/
fun <NewOutput : Any> persister(
reader: (Key) -> Flow<NewOutput?>,
writer: suspend (Key, Output) -> Unit,
delete: (suspend (Key) -> Unit)? = null,
deleteAll: (suspend () -> Unit)? = null
): StoreBuilder<Key, NewOutput>
/**
* Connects a (non-[Flow]) source of truth that is accessible via [reader], [writer],
* [delete], and [deleteAll].
*
* @see persister
*/
fun <NewOutput : Any> nonFlowingPersister(
reader: suspend (Key) -> NewOutput?,
writer: suspend (Key, Output) -> Unit,
delete: (suspend (Key) -> Unit)? = null,
deleteAll: (suspend () -> Unit)? = null
): StoreBuilder<Key, NewOutput>
from store.
Off the top of my head I can't think of any reason not to have this. Let's give it a go and create a @experimental annotation allowing consumers to know that this is less hardened than other apis.
from store.
Cool. Will give it a go next week.
from store.
Related Issues (20)
- [Feature Request] Add converter to StoreBuilder HOT 7
- [Feature Request] get() and fresh() extensions on MutableStore
- [Feature Request] HOT 1
- Inconsistent SourceOfTruth argument types HOT 2
- [BUG] Fix breaking changes with source of truth HOT 7
- [Documentation] Update Store documentation HOT 1
- Integrate website with CI
- [Feature Request] The stream of StoreResponse<T> should emit Loading(origin = SourceOfTruth) HOT 1
- [Question] Data with nested keys HOT 1
- [BUG] Stop with the breaking API changes in beta HOT 4
- [BUG] 5.0.0-beta02 breaks StoreReadRequest.cached + Validator HOT 2
- [BUG] Cached(refresh = true) will collect SoT reader twice HOT 3
- [Feature Request] fromLocalToOutput converter method went missing
- [BUG] Deadlock during synchronization in MutableStore
- [BUG] Examples on https://mobilenativefoundation.github.io/Store/mutable-store/building/builder/ are wrong
- [Feature Request] Common Testing Utils
- [BUG] Documentation "Edit this page" button 404's HOT 1
- Store Not Fetching or Read/Writing HOT 6
- CLA HOT 1
- [Question] Why should anyone consider using Store if they are already using NetworkBoundResource concept/framework? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from store.