Code Monkey home page Code Monkey logo

Comments (2)

BinaryMuse avatar BinaryMuse commented on August 27, 2024

Hey, @lorefnon,

Thanks for the issue—this has come up a couple times, and I should probably include it in the docs. I actually had the same thought when I first started experimenting with flux; they definitely are another layer of indirection, though I'm now not so sure they're superfluous.

You actually can dispatch actions directly if you want via getFlux().dispatcher.dispatch, but that couples the component to:

  • the dispatcher implementation
  • the action type (i.e. the string itself)
  • the format of the payload

In a larger application, the extra indirection will make changes to the action/data layer easier without having to change your application's components. It also allows changes to the Fluxxor dispatcher without needing to change either (1) your components (because they don't know about the dispatcher at all) or (2) your action methods (because this.dispatch is bound to an internal object that handles actually doing the dispatch for you).

Related to the first point above, the actions also give you semantically meaningful method names: flux.actions.addUrl(url) instead of flux.dispatcher.dispatch(Actions.ADD_URL, {url: url}).

See also Creating Semantic Actions on the React site:

As you can see, we really would not need to have the helpers AppDispatcher.handleViewAction() or TodoActions.create(). We could, in theory, call AppDispatcher.dispatch() directly and provide a payload. But as our application grows, having these helpers keeps the code clean and semantic. It's just a lot cleaner to write TodoActions.destroy(id) instead of writing a whole lot of things that our TodoItem shouldn't have to know about.

Hope that helps; this is a really interesting topic to me, so feel free to keep thinking about/discussing it!

from fluxxor.

lorefnon avatar lorefnon commented on August 27, 2024

Thanks for the reply, @BinaryMuse . I see where you are coming from, thank you for taking the time to elaborate.

from fluxxor.

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.