DEV Community

Cover image for Rise of the Reducer

Rise of the Reducer

Matt Eland on December 28, 2019

In recent years I’ve observed a strong trend towards using reducers in software architectures. While this is not a new pattern, its recent prominen...
Collapse
 
shimmer profile image
Brian Berns • Edited

Just want to mention that this comes from the concept of a fold/reduce in functional programming. For example, in F#, you could process a stream of messages using fold:

let msgs = [ NextTurn; NextTurn; Restart; NextTurn; NextTurn ]
let initialModel = init ()
let finalModel =
    Seq.fold
        (fun model msg -> update msg model)
        initialModel
        msgs
printfn "%A" finalModel
Enter fullscreen mode Exit fullscreen mode
Collapse
 
integerman profile image
Matt Eland

Love it. I think you can put fs after the triple apostrophes to get F# syntax highlighting there.

And yes, I'm doing a ton of F# programming recently, which inspired the post on reducers at large.

Collapse
 
shimmer profile image
Brian Berns

Thanks. I actually had to use “fsharp” to trigger syntax highlighting.

Collapse
 
simme profile image
Simme • Edited

Nice article! I’ve used both redux and ngrx extensively and must say that while I appreciate the effort of the ngrx team it feels so unintuitive compared to the pure redux implementation.

A colleague once told me to only use redux for state that needs to be accessible elsewhere or fetches data and keep all the rest as local state. While not necessary I really like how this simplifies debugging and keeps the reducers from growing out of control.

Collapse
 
integerman profile image
Matt Eland

That's a good tip, though it does get rid of some of the centralized aspects.

There are some lighter weight Angular state management libraries out there that may be more of a happy medium as well, but I've not looked into them yet.