-
Notifications
You must be signed in to change notification settings - Fork 52
(WIP) refactor: Redux toolkit + TypeScript #551
base: master
Are you sure you want to change the base?
Conversation
Everything so far seems fine with me as I read through it quickly but I'll check things more thoroughly tomorrow 👍 |
3a17d06
to
b51001f
Compare
Another TypeScript improvement.
interface IProps { }
class RuleCollectionChecker extends React.Component<ReturnType<typeof mapStateToProps> & ReturnType<typeof mapDispatchToProps> & IProps> {
// ...
}
const mapStateToProps = (state: ReduxState) => ({
someProp: state.someProps,
});
const mapDispatchToProps = (dispatch: AppDispatch) => ({
someDispatch: () => dispatch(someAction()),
}); |
I am currently trying to figure out the structure of the whole Redux state. You will notice that with the latest commit everything builds, but it is having a hard time listing payments, etc. That's because with Redux Toolkit I have to manually apply serialization before objects can be dispatched. It's currently using the |
Although we could apply the same serialization as the API, I don't think that we should. I have been able to drastically reduce CPU and memory usage by applying a manual serialization strategy for the Redux store. It looks like, together with async and batch dispatching, these are going to be the biggest performance improvements we can achieve in the short term, with little effort. |
8c2d35b
to
3a96a85
Compare
This original plan was a simple refactor to make state management as a whole more scalable, but eventually turned into a much bigger refactor. Therefore, I have pushed a WIP to check if this PR has any chance of getting merged.
bunqDesktop is, without a doubt, a brilliant piece of engineering, but with like many projects of this size, scalability is becoming an issue. I have tried to add extra reducers to Redux but found it difficult not to knock over other functionality. "Luckily," I have seen this problem numerous times before in my own projects. Some helpful tips and toolkits from the creators of Redux and React have helped me solve the problem.
With this pull request, I am trying to add the best parts to the project.
Here is what has helped me tremendously scale React and Redux:
I have tried to apply @manaflair/redux-batch, but it looks like Redux nowadays has native support for batched actions, by leveraging the new (unstable)
unstable_batchedUpdate
API: https://react-redux.js.org/api/batch. Together with Redux saga, we can make components dispatch multiple actions at once and let sagas orchestrate all the side-effects that are subscribed to these actions.~components
is a lot easier. No more guessing where../../../MyComponent
actually is. Intsconfig.json
, you can set the paths. Thewebpacktools.js
file helps the Babel module resolver convert from TypeScript to Babel.react
folder. I have restructured everything that did not belong in the react folder in such a way that you can now easily see what you can expect in a folder. It is just a preference, though. If you don't like it, I can easily revert it. I just thought that it would be a lot clearer like this.Let me know what you think! It's probably a bit overwhelming, but I expect that it's a great way to increase maintainability and improve performance.