Comments (4)
As far as I understand, all overloads of Store.dispatch that using both Store.ActionCreator and Store.AsyncActionCreator types wrap _defaultDispatch actually. It seems like a job for middlewares, isn't it?
Generally this would be a job for middleware. However, there are two specific reasons we have chosen to implement them as separate methods on the store:
- Some of the overloads change the API of
dispatch
by taking a callback as an additional argument - this cannot be accomplished by middleware - We want to provide some features, such as dispatching
ActionCreator
s or having a way to be notified about the completion of anAsyncActionCreator
by default. We don't want that developers need to add middleware for these essential features. That means this library will be more opinionated than Redux, but that was a conscious decision on our end.
An additional note on 2., we are looking for a better default way for async in ReSwift
and we'll have the discussion under #64. AsyncActionCreators
work for now but we are hoping to find a better solution.
Lastly:
BTW, why does Middleware take references to dispatch and getState separately? Maybe it is worth to extract both from StoreType to some StoreCoreAPIType and pass it by weak reference.
I think in this case it's not worth introducing a new type. We are borrowing the middleware API from Redux (which makes it easier for some folks to understand the mechanism) and I would only want to deviate from it if we can add significant value. I don't think that's the case for this suggestion.
Thanks a lot for contributing your questions & ideas 👍
from reswift.
@Ben-G Thanks for your detailed explanation.
from reswift.
Some of the overloads change the API of dispatch by taking a callback as an additional argument - this cannot be accomplished by middleware
Actually I have a question about this too :) I perfectly understand the value of that callback for asynchronous version of dispatch
and don't see any profit to use it on synchronous ones. It leads to pyramid of doom
. Is it all about consistency of dispatch
overloads?
from reswift.
I agree on the latest comment. The callbacks on the synchronous dispatch methods don't make a lot of sense. They were added for consistency but don't add a lot of value. We should likely remove them soon! You are right that they encourage to use the library in an undesirable way.
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: sometimes will crash at this point, what can i do to find the root cause HOT 11
- 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.