Comments (3)
There are 2 main benefits to stream
over a single value:
- As you say, you can get values from disk/cache/fetcher, which is useful if you want to first display a cached value while waiting for the fetcher to get a
fresh
value (this is the main use case covered by thefresh
extension function). - Stream allows you to continue receiving updates to the data as it changes. If you use the data coming out of store to show a UI for example, by using stream you'll be able to always show the newest data. New data will be emitted if changes were made to the sourceOfTruth or if another request caused store to refetch the item you are streaming.
For your 2nd question:
Every call to stream
(or fresh
) will cause a new cold flow to be created (which will not cause any coroutine or other non-builder action to be performed). The action starts when you collect the flow (the equivalent of subscribe
if you're coming from Rx world). Store, under the hood will coalesce all the fresh calls into a single fetcher call. Generally, store's stream
should never be stopped by store, only by the user (though maybe there are some error conditions that we'll cause it to stop? if so we might want to fix those to make it clear store will emit until you're the collection is stopped by the user).
from store.
So what I'm hearing is that we can call StoreRequest.fresh() as much times as we want and when the collector is active it will start a new flow but we don't have to worry about deleting previous flow objects that were created from function calls.
How does it work if we open both a fresh and cache stream? Calling fresh will also update the cache, which means that cache streams will also receive a new emission, which could introduce possible duplication of the displaying of the data to the UI.
from store.
So what I'm hearing is that we can call StoreRequest.fresh() as much times as we want and when the collector is active it will start a new flow but we don't have to worry about deleting previous flow objects that were created from function calls.
Yes. You can collect for as long as you care about the results. The collection will be automatically cancelled when the collecting coroutine (or coroutine scope) is completed/cancelled.
How does it work if we open both a fresh and cache stream? Calling fresh will also update the cache, which means that cache streams will also receive a new emission, which could introduce possible duplication of the displaying of the data to the UI.
Fresh and cached refer to the initial results - is it ok to get a cached value? Should we avoid calling the fetcher? Etc. That does not affect subsequent update. If you asked to stream the data, that mean you will get all the updated that store knows about to the data your collecting until you stop the collection
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.