Coder Social home page Coder Social logo

Comments (11)

yigit avatar yigit commented on May 30, 2024

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.

 avatar commented on May 30, 2024

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.

yigit avatar yigit commented on May 30, 2024

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.

 avatar commented on May 30, 2024

Yeah we are fixing that, sorry should've looked into it more, new app we're pushing soon.

from store.

 avatar commented on May 30, 2024

https://github.com/vdtyson/StoreDemo

Same link...not working, api call is successful inside the fetcher.

from store.

yigit avatar yigit commented on May 30, 2024

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.

 avatar commented on May 30, 2024

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.

yigit avatar yigit commented on May 30, 2024

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.

vdtyson avatar vdtyson commented on May 30, 2024

We're trying to query for the last quote id returned from the fetcher.

from store.

vdtyson avatar vdtyson commented on May 30, 2024

Also, every time the generate quote button is clicked, we'd like it to return a new value

from store.

yigit avatar yigit commented on May 30, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.