11 ms·
How Redux Works: A Counter-Example
- ergo14 9y agoIt is interesting how people have the idea that react === Redux/flux. Where in fact Redux is unopinionated and works with other libraries/frameworks just fine.
- leshow 9y agoHow often do you see redux used with anything other than react? Or are you just talking about redux working with react alternatives like preact/inferno, etc? You're not wrong, but practically 99% of people pair it with react.
- robmcm 9y agoIt seems to be quite common in angular, even if used indirectly or via inspired libraries. https://github.com/search?utf8=%E2%9C%93&q=angular+redux&type= https://github.com/search?utf8=%E2%9C%93&q=angular+redux&typ...
- jinder 9y agoThe Redux pattern is used quite widely, even if not via the official library. See NGRX for example, which implements the pattern in TypeScript + Angular. https://github.com/ngrx/platform https://github.com/ngrx/platform
- dimillian 9y agoWe use it in our native mobile applications (iOS / Android) for over a year now. It make a lot of sense, improved the codebase maintainability and reduced the number of bugs.
- acemarke 9y agoRedux is actually used noticeably outside of the React community. Redux can be used with any UI layer, and there's bindings for many frameworks and UI layers besides React [0]. Redux has picked up popularity within the Angular community, both in its original form and the NgRx reimplementation. The ember-redux bindings are also starting to gain a bit of a following. Vue's VueX lib is inspired by Redux, and there's Vue-specific bindings for Redux itself. [0] https://github.com/markerikson/redux-ecosystem-links/blob/master/library-integration.md https://github.com/markerikson/redux-ecosystem-links/blob/ma...
- ergo14 9y agoPeople use it with Polymer (a lot of people in the community use it with polymer-redux package) and Vue. React alternatives that you mentioned are also a thing.
- dceddia 9y agoYeah it really is. I'm not sure where that comes from. Maybe it has something to do with the climate when React rose to popularity, where all the competing alternatives were "frameworks," and so people were in that mindset when they approached React? In any case, it's led to a ton of confusion in the community, especially for newcomers.
- robmcm 9y agoThere is a certain paradox with teaching something like Redux, in that it's designed to make complex systems easy to understand and manageable. Yet when trying to demonstrate with a simple example, it appears hugely over complex and unnecessary. I think a pre-requisite to learning something like Redux (or any micro-architecture) is to first try building something without it. Once you understand the pains of undisciplined, organically designed, spaghetti applications, the cynicism is replaced by excitement over how this will improve your job/life/application.
- dceddia 9y agoThis paradox I think is what turns people off Redux when they first learn it. "All this code... for what benefit?" Of course it's total overkill for something like a counter, or a todo list, but it's tough to teach an introduction to something by starting with "here's a huge enterprise app, let's dive in" :) I tried to call this out in the article to make sure people are aware that improving simple Counter examples is not what Redux is really meant for. I'm considering putting together a larger course/book that does just what you say - build up a React app using plain state until it becomes painful, and then refactor it to add Redux. My question right now is, how far should I go? Do I walk through building the entire app with state (and push through the complexity), or do I give up at the first indication that Redux would make things easier?
- rahimnathwani 9y ago> "here's a huge enterprise app, let's dive in" I'd love to see a complete project that uses redux, and would be horrible without it. Any pointers?? :)
- sailfast 9y agoI appreciate the author's work to explain this, and I like starting without Redux as a demonstration - definitely a good idea to figure out what React does on its own first. That said, I found the reverse approach to Redux to be more confusing than the actual Redux documentation and the tutorials that Dan Abramov has already put together around Redux which explains things quite lucidly. Example: https://egghead.io/lessons/react-redux-the-single-immutable-state-tree https://egghead.io/lessons/react-redux-the-single-immutable-...
- dceddia 9y agoFirst - thanks :) Second - it's interesting you found the reverse approach to be confusing. I've heard from multiple people that loved it and said it made more sense to them that way. Different strokes and all that! How experienced were you as a dev before you read the Redux docs + Dan's tutorials? I ask because I learned with those too, and they made sense to me (Dan's egghead videos were eye-opening), and I've been doing software for > 10 years professionally... but my suspicion is most beginners don't do as well with the top-down approach.
- sailfast 9y agoHi there and thanks for the response. Certainly not a beginner - been working in the field awhile and I'd worked previously with app frameworks like Angular and a written a number of other less "frameworky" apps before that. Could be an indicator as you mention :) The thing I found so compelling about Redux was thinking about state being immutable unless you took the original state {...} and changed with a reducer, which was called depending on the action you want to take. At that point, when something is changed, the whole app is changed - it's the one thing to rule them all. If you want to change something, you need to take action. "How do you change state?" "Take an action." Without understanding that flow up front it was hard to determine _why_ one would need to do things like connect, createStore, etc and how state magically got to be a prop. I think your walk-through does a great job of explaining things step by step starting from the react code (and what Redux replaces) and I can see it working well for a number of learning styles. I also really like the pancake syrup provider imagery.
- 9y ago
- dimillian 9y agoSwitched our entire native app stack to a redux backend (Swift and Kotlin), never been happier. Sure there is more code in the end, but the decoupling and simplicity to use is just too good. Especially on iOS when you know how complex it is to maintain a controller hierarchy with a (now dead) dependency chain.
- prabhasp 9y agoLike the explanation a lot. Even when you've understood redux, and want to use, the amount of upfront boilerplate can be a turn off. I liked this approach of parsing out the boilerplate piece by piece.
- kyberias 9y agoWhat language is that in the examples? Yes, I've dropped out of the Javascript train.
- evan_ 9y agoIt’s ES6 JavaScript, it’s great, and most modern browsers support it out of the box. You can also use Babel to transpire it into something that’s supported everywhere.
- acemarke 9y agoI'm a Redux maintainer, and this is a great introduction to Redux. I love Dave's ability to break things down into easily understandable pieces, and his clear writing style. I also saw a similar "React and Redux: An Introduction" tutorial published just within the last couple days [0]. For anyone who's looking to learn more about Redux, I'd encourage you to check out my React/Redux links list [1], which has sections pointing to more Redux tutorials [2], Redux architecture and best practices [3], and much more. If you've picked up the basics of Redux and want to see how it works at a larger scale, I recommend the "Building a Simple CRUD App with React and Redux" series [4], and my own "Practical Redux" tutorial series [5]. Also, my "Idiomatic Redux" blog series [6] looks at things like the history and intent behind Redux, common usage patterns and why they exist, and why I consider certain patterns to be the "right" way to use Redux. Finally, I am always happy to answer questions about learning and using React and Redux! Please feel free to ping me on Twitter at @acemarke. Also, come by the Reactiflux chat channels on Discord [7]. There's always plenty of people around who can answer questions. I'm usually on there evenings US time. [0] http://jakesidsmith.com/blog/post/2017-11-18-redux-and-react-an-introduction/ http://jakesidsmith.com/blog/post/2017-11-18-redux-and-react... [1] https://github.com/markerikson/react-redux-links https://github.com/markerikson/react-redux-links [2] https://github.com/markerikson/react-redux-links/blob/master/redux-tutorials.md https://github.com/markerikson/react-redux-links/blob/master... [3] https://github.com/markerikson/react-redux-links/blob/master/redux-architecture.md https://github.com/markerikson/react-redux-links/blob/master... [4] http://www.thegreatcodeadventure.com/building-a-simple-crud-app-with-react-redux-part-1/ http://www.thegreatcodeadventure.com/building-a-simple-crud-... [5] http://blog.isquaredsoftware.com/series/practical-redux/ http://blog.isquaredsoftware.com/series/practical-redux/ [6] http://blog.isquaredsoftware.com/series/idiomatic-redux/ http://blog.isquaredsoftware.com/series/idiomatic-redux/ [7] https://www.reactiflux.com https://www.reactiflux.com
- arximboldi 9y agoNice thing about this architecture is that it really is agnostic to your stack and as long as you have some way to build "values" you are good to go. I have recently been working on a Redux for C++ experimental library with time-travel and all. As an example I built a mini-emacs text-editor with it. Should post about it here whenever I flesh out the README and all (or the MeetingCpp talk about it gets published). In the meantime you might want to check these links: The library: https://github.com/arximboldi/lager https://github.com/arximboldi/lager The Counter-Example: https://github.com/arximboldi/lager/tree/master/example/counter https://github.com/arximboldi/lager/tree/master/example/coun... The text editor: https://travis-ci.org/arximboldi/ewig https://travis-ci.org/arximboldi/ewig Show-case of a time-travelling debugger: https://twitter.com/sinusoidalen/status/926382341433577472 https://twitter.com/sinusoidalen/status/926382341433577472
- jordache 9y agothis is a relatively terrible explanation of redux when compared to this: https://code-cartoons.com/a-cartoon-intro-to-redux-3afb775501a6 https://code-cartoons.com/a-cartoon-intro-to-redux-3afb77550...
- acemarke 9y agoLin Clark's cartoons are always excellent, but these articles serve different purposes. "A Cartoon Intro to Redux" is more about the conceptual aspects, while Dave's post is both concepts and actual code usage.
- jordache 9y agoDave's post is targeted at 'demystifying'. For this context, Lin's cartoon explanation excels. If Dave's post was scoped to optimizing redux implementation, detailed code samples would be appropriate.