Code Monkey home page Code Monkey logo

Comments (4)

Ben-G avatar Ben-G commented on May 30, 2024

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:

  1. Some of the overloads change the API of dispatch by taking a callback as an additional argument - this cannot be accomplished by middleware
  2. We want to provide some features, such as dispatching ActionCreators or having a way to be notified about the completion of an AsyncActionCreator 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.

HeMet avatar HeMet commented on May 30, 2024

@Ben-G Thanks for your detailed explanation.

from reswift.

HeMet avatar HeMet commented on May 30, 2024

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.

Ben-G avatar Ben-G commented on May 30, 2024

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)

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.