Comments (11)
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.
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.
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.
Yes, this is fine.
from reswift.
Sorry, mistakenly closed and submitted my comment prematurely. Subscribing and dispatching in viewDidLoad sounds fine, yes.
from reswift.
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?
from reswift.
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.
@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.
thank you very much,guys
from reswift.
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.
@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)
- Concurrency - protected reads HOT 2
- How to subscribe/unsubscribe store in a UIView like in UITableViewCell, CollectionViewCell etc ? HOT 1
- What's a good way to cast results of a subscription in SwiftUI to a desired output type? HOT 3
- Managing ReSwift app state inside FileDocument HOT 1
- Remove Travis from all ReSwift repos? / How to set up GH Actions
- ReSwift 7 Roadmap HOT 20
- Docs: Update outdated and vulnerable jQuery version HOT 3
- Array as a State HOT 1
- Clarification on Single Store object for an application. HOT 1
- Change visibility of Store from 'open' to 'public final'? HOT 2
- SIGSEGV on state.didSet HOT 4
- Using Inject with ReSwift HOT 1
- Testing: Waiting for store.dispatch() to complete HOT 2
- Huge CPU gap between ReSwift Store vs just SwiftUI ObservableObject HOT 1
- Crash when dispatching actions from inside StoreSubscriber.newState() HOT 2
- How to use a state on recursive screens? HOT 4
- Filter on updates not working HOT 3
- When do you upgrade ReSwiftRouter ? Now,ReSwiftRouter just depends ReSwift 5.0.0, but lasted ReSwift is 6.1.1 HOT 2
- Privacy Manifest HOT 2
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 reswift.