Coder Social home page Coder Social logo

Comments (11)

mjarvis avatar mjarvis commented on June 4, 2024 1

I would not recommend async'ing all function calls, there are many cases where you want dispatches to happen synchronously (eg user input). You should instead consider each thunk and ensure its asyncing to the main thread itself before dispatch(foo) if needed.

from reswift.

mjarvis avatar mjarvis commented on June 4, 2024

Looking at the left side, it appears this is breaking on a background thread. ReSwift does not support multi-threading and will crash if you dispatch an actions from multiple threads. Take a look at the dispatch you're making an ensure its sent on the thread you're using ReSwift (usually main)

from reswift.

LivenChief avatar LivenChief commented on June 4, 2024

our structure:
viewController contains some featureView, such as featureView1, featureView2, featureView3.
each featureView will subscribe store when viewController viewDidLoad, and will dispatch som action sometimes too.
is it right?

from reswift.

mjarvis avatar mjarvis commented on June 4, 2024

Yes, this is fine.

from reswift.

mjarvis avatar mjarvis commented on June 4, 2024

Sorry, mistakenly closed and submitted my comment prematurely. Subscribing and dispatching in viewDidLoad sounds fine, yes.

from reswift.

LivenChief avatar LivenChief commented on June 4, 2024

It is difficult to avoid dispatching on different threads, because a thunk call api response may be dispatched in one of the featureViews, then we will dispatch response date in network response threads(usually not main)
can i solve in this way?
image

from reswift.

LivenChief avatar LivenChief commented on June 4, 2024

Another thing that block me is when to clear the data on the store? I hope you can give me some advice, thank you very much

from reswift.

DivineDominion avatar DivineDominion commented on June 4, 2024

@LivenChief +1 to what @mjarvis said.

This is still a good rule of thumb:

I start with the ideal assumption that everything will run on the main thread.
https://inessential.com/2014/03/08/api_design_the_main_thread_and_queues

Your goal then would be to make it so that everything that dispatches to a BG queue eventually ensures that the main queue is reached again.

Sprinkle in some assert(Thread.isMainThread) (via https://inessential.com/2020/01/20/on_replacing_operationqueue) and you can detect where your assumption about being on the main thread is violated, and by whom.

from reswift.

LivenChief avatar LivenChief commented on June 4, 2024

thank you very much,guys

from reswift.

LivenChief avatar LivenChief commented on June 4, 2024

Hi @DivineDominion @mjarvis
mine viewController contains many featureView, each featureView will subscribe store, I want to last receive the store data featureView to clear store data nil when i dispatch action change store data, so that i can keep store data more clear not bloated. but i found that subscriptions is an unordered collection Set
How i can know which subscription is the last one receive data?

from reswift.

DivineDominion avatar DivineDominion commented on June 4, 2024

@LivenChief Sorry, I can only 80% follow :)

If you want to make sure that N subviews receive a state update in a specific order, don't subscribe each of these. Instead, subscribe a common ancestor and make it forward the relevant information to its child views. (In technical terms, it's up to you to express the intent of updating views in a specific seauence.)

If I'm getting this wrong, can you share a pseudo code example?

from reswift.

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.