Coder Social home page Coder Social logo

Comments (3)

eyalgu avatar eyalgu commented on May 30, 2024

There are 2 main benefits to stream over a single value:

  1. 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 the fresh extension function).
  2. 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.

 avatar commented on May 30, 2024

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.

eyalgu avatar eyalgu commented on May 30, 2024

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)

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.