score:2
One of the main reasons is that constraining state changes to be done via actions allows you to treat all state changes as depending only on the action and previous state, which simplifies thinking about what is going on in each action. The architecture "traps" any kind of interaction with the "real world" into the action creator functions. Therefore, state changes can be treated as transactions.
In your Theoretical State Container, state changes can happen unpredictably at any time and activate all kinds of side effects, which would make them much harder to reason about, and bugs much harder to find. The Flux architecture forces state changes to be treated as a stream of discrete transactions.
Another reason is to constrain the data flow in the code to happen in only one direction. If we allow arbitrary unconstrained state modifications, we might get state changes causing more state changes causing more state changes... This is why it is an anti-pattern to dispatch actions in a reducer. We want to know where each action is coming from instead of creating cascades of actions.
Flux was created to solve a problem at Facebook: When some interface code was triggered, that could lead to a cascade of nearly unpredictable side-effects each causing each other. The Flux architecture makes this impossible by making every state transition a transaction and data flow one-directional.
But if the boilerplate needed in order to do this bothers you, you might be happy to know that your "Theoretical State Container" more or less exists, although it's a bit more complicated than your example. It's called MobX.
By the way, I think you're being a bit too optimistic with the whole "it's an implementation detail" thing. I think if you tried to actually implement time-travel debugging for your Theoretical State Container, what you would end up with would actually be pretty similar to Redux.
Source: stackoverflow.com
Related Query
- Why we decouple actions and reducers in Flux/Redux architecture?
- Design Redux actions and reducers for a React reusable component
- react redux architecting table actions and reducers
- Use of boilerplate actions and reducers in redux
- Typescript integration with complex redux actions and reducers
- Redux state from actions and reducers does not show in mapStateToProps
- Confused with REDUX actions and reducers
- reuse redux reducers and actions
- Problem using multiple Reducers and Actions Redux
- React / Redux and Multilingual (Internationalization) Apps - Architecture
- How to divide the logic between Redux reducers and action creators?
- What is difference between reducers and extrareducers in redux toolkit?
- How to fire periodic actions using setTimeout and dispatcher in redux
- Integrating React and OpenLayers within a Redux Architecture
- Why do Flux architecture examples use constants for action types instead of strings?
- Why are my props `undefined` when using redux and react.js?
- Redux - relation of reducers to actions
- Make Redux reducers and other non-components hot loadable
- How to setup Ember like computed properties in Immutablejs and Redux and Flux and React
- Reusing actions across multiple reducers in redux
- Redux: organising containers, components, actions and reducers
- Sharing actions and reducers with react/redux
- Why does Redux Promise return unresolved promise if more than type and payload options are specified?
- combineReducers destroys Redux state and also breaks multi ImmutableJs reducers
- How to test redux actions that use 'redux-api-middleware' and [CALL_API]?
- Why I should set redux actions type with an exported constants?
- How action and reducers are connected with each other in react redux
- Passing multiple props and actions in react / redux
- Architecture example for a multi-language application using React, React Redux or React Context, and Material UI
- Using React and Redux Hooks, why is my action not firing?
More Query from same tag
- GET http://localhost:3000/bundle.js net::ERR_ABORTED 404 (Not Found)
- How to change the Date Format in Chart.js?
- Change state onClick React+Redux
- reactJS app with a fetch to an API fails to load with No 'Access-Control-Allow-Origin' header is present on the requested resource
- Cannot display date with react-datepicker with react-hooks-forms on screen
- Handling a timer in React/Flux
- React server rendering - how to use JSX?
- How to request react app over internet with express/node.js
- carousel, let horizontal scrolling end movement when parent element vertical scrolling is moved
- How to change the background color of an ant.design InputNumber?
- How to Add route links to material ui tabs in react typescript
- How to add two buttons with two handlers in reactjs?
- I am passing the props to a functional component via Link (react-router-dom) but it says the state is 'undefined'
- How to change material-ui slider thumb style when it's disabled
- Show an alert to another react component after making an successfull api call from current component
- How to add text on the last element of a map with react
- Is there a way to make phaser game object into a react controlled component?
- How to nest classes in css modules and react?
- Redux: request into success or error flow from Component (using redux-saga)
- How to sort an HTML table in React?
- useEffect - state doesn't update when unmounting
- How can I wrap the Children of a Parent component in a HOC and render them in React?
- Is there a better way to achieve this?
- Using react-router-dom with an input
- How can i render Text inside image background in react native?
- How to loop through localStorage values
- How to show all elements on page load (currently being filtered out) - React
- Set State inside method onClick
- Set default value for input
- Best practices to deploy a React app and an API on Heroku