Comments (11)
can you show how you are collecting from the store? Also, if you can produce a simple app that reproduces the issue, that would be very helpful. We have plenty of tests that use fromNonFlow
(https://github.com/dropbox/Store/search?q=fromNonFlow&unscoped_q=fromNonFlow) so having a repro sample would help us understand what is going on.
from store.
Ok we are producing a simple app to replicate it but for now, we are collecting from it like this...
override fun cacheSensorStream(): Flow<StoreResponse<List<Entity.Sensor>>> =
createSensorStream(StoreRequest.cached(StoreKey.SensorsKey(), true))
sensorRepository.cacheSensorStream().collect(flowCollector)
We basically add the things we collect to a live data object we are observing, we keep getting no data from the fetcher.
We also realized we didn't add the store key in the body of nonFlow but that still didn't remedy the issue but it looks like this now...
remoteDataSource.getSensors(it).body()?.map(::sensorMapping)!!
from store.
I've run the app and if you add a log tot he collector, you'll actually see:
val quoteCollector: FlowCollector<StoreResponse<QuoteData>> = object : FlowCollector<StoreResponse<QuoteData>> {
override suspend fun emit(value: StoreResponse<QuoteData>) {
println("received $value") // <<<<<
when(value) {
is StoreResponse.Data -> {
textView_newQuote.text = value.value.quote
}
is StoreResponse.Error -> {
textView_newQuote.text = value.error.message
}
}
}
}
2020-02-03 23:18:17.236 14525-14525/com.versilistyson.storedemo I/System.out: received Loading(origin=Fetcher)
2020-02-03 23:18:18.299 14525-14525/com.versilistyson.storedemo I/System.out: received Error(error=kotlin.KotlinNullPointerException, origin=Fetcher)
the code gets an NPE because of this line in QuoteRepository
:
response.body()!!.map()
which gets forwarded to your collector wrapped in a StoreResponse.Error
.
from store.
Yeah we are fixing that, sorry should've looked into it more, new app we're pushing soon.
from store.
https://github.com/vdtyson/StoreDemo
Same link...not working, api call is successful inside the fetcher.
from store.
that one does not work because you've defined your DAO method as
@Update(onConflict = OnConflictStrategy.REPLACE)
suspend fun saveQuote(quoteToSave: QuoteData)
so it does not insert the data into database hence the read method fails to read it back.
changing it to Insert
fixes your sample.
from store.
Thanks so much. If we lets say wanted to add a different quote to store we'd have to use a new key? Or would writing it using the previous key overwrite it in the dao/cache?
from store.
it depends. right now your query returns the first quote in the database (likely to be the very first inserted, but no guarantee by sqlite).
Can you explain what you are trying to do? Do you want to query w/ a specific quote id and get that quote or get all quotes ?
from store.
We're trying to query for the last quote id returned from the fetcher.
from store.
Also, every time the generate quote button is clicked, we'd like it to return a new value
from store.
so i think what you can do is, write your dao like this:
@Dao
interface QuoteDao {
@Insert(onConflict = OnConflictStrategy.REPLACE)
suspend fun saveQuote(quoteToSave: QuoteData)
@Query("SELECT * FROM quote_table ORDER BY rowId DESC LIMIT 1")
fun readQuote(): Flow<QuoteData>
@Delete
fun deleteQuote(quoteToDelete: QuoteData)
}
Then your read method will always return the last "Edited/inserted" row from the database. Not sure if this is what you want in the long term as it will get invalidated every time a quote enters the database for any reason but this is the best I could think of unless you have to use another field for the quite that is fetched and query by it. That would be something like:
@Dao
interface QuoteDao {
@Transaction
suspend fun saveLatestQuote(quoteToSave: QuoteData) {
unmarkLatestQuote()
insert(quoteToSave.copy { latestQuote = true })
}
@Query("UPDATE QuoteData set latestQuote = 0 WHERE latestQuote = 1")
suspend fun unmarkLatestQuote()
@Insert(onConflict = OnConflictStrategy.REPLACE)
suspend fun saveQuote(quoteToSave: QuoteData)
@Query("SELECT * FROM quote_table WHERE latestQuote = 1 ORDER BY rowId DESC LIMIT 1")
fun readQuote(): Flow<QuoteData>
@Delete
fun deleteQuote(quoteToDelete: QuoteData)
}
from store.
Related Issues (20)
- [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
- [Feature Request] Synchronization HOT 3
- [BUG] State Flow From `launchPagingStore` Does Not Reflect Latest Writes in Mutable Store
- Improve StoreKey API
- Good practices for error handling and propagation HOT 1
- Cache control on source of truth ? 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.