Chris
Chris

Reputation: 14218

redux vs mvc like models

I have a new project coming up and the PO suggested to use Redux for state management.

I would like to argue against it since I don't see the benefit compared to a model based approach.

I.e. instead of having plain objects in the store, reducers to get computed properties and actions to perform mutations I defined those on models themselves:

class User {
    id = 'ec3d17a2-edee-48e6-b1cd-8f042a9e2a17'
    firstname = 'Jon'
    lastname = 'Doe'
    get fullname() {
        return this.firstname + ' ' + this.lastname
    }
    destroy() {
        axios.delete('/users/'+this.id)
        ...
    }
}

The arguments I read in most Blogposts are:

I think it is much easier to structure code and to find my way with above mentioned structure.

I am really fed up with clients that try to figure out a technology stack and think flux/redux is the only "professional" way after reading about it. I think it has become really hard to convince someone that redux is not necessarily the best choice for projects in their early stages. When I argue that it slows down development without creating much benefits at a small/medium scale I fear that it might get interpreted as laziness rather than ressourcefulness.

Upvotes: 1

Views: 905

Answers (1)

timotgl
timotgl

Reputation: 2925

Your critizism is valid to a certain extent. If devs are familiar and comfortable with MVC, why venture into something unknown when previous projects were successfully architected with MVC.

Where redux pays of is easier reasoning about the behavior of a complex app (which can still be small or medium in scale). Setting breakpoints in the code and reflecting about the flow of execution is simply inferior to having a history of actions visible in your dev tools. Also it encourages you to follow the unidirectional flow in all aspects of your app. A series of pure state transitions is easier to follow than putting together what data is currently stored where in your code, which call was made from which component, etc.. Everything is just more fragmented and random.

It might not make sense for a certain team with a certain scope. It surely has its limits and tradeoffs, as explained by Dan Abramov himself: https://medium.com/@dan_abramov/you-might-not-need-redux-be46360cf367

Upvotes: 3

Related Questions