In my Meteor-React-Redux application, I have a sort of invoice that a user can add items to and change quantities, prices, descriptions, etc.
When a user adds or updates an item to the invoice, an action is created as a redux-thunk. The thunk is simple, it just updates the document in MongoDB corresponding to the invoice with the changes to the item. Then an action is dispatched for the reducer to note the change.
In the reducer other values such as subtotals, totals, taxes, discount percentages, etc are recalculated and the state gets updated. This keeps all of my “business logic” within the reducer. The invoice component simply displays the state of the invoice and is purely presentational.
The problem I run into is that I want to store the computed values that the reducer creates back into my DB. I want this mainly so I can quickly query stats about several invoices at once later on another dashboard, without having to recompute values on demand.
If I make the computations and save them to the DB in the redux thunk, then I would have to deal with having business logic in two separate places if I make this a common practice.
How could I solve this problem without creating side effects in my reducer and maintaining my business logic in a single place?