I have two tips for you:
- Normalize your store.
- Do not save search results in reduction.
Normalization
This is well documented, so I won’t go into it here. Suffice it to say that the normalization of your store will be flexible and help you justify your application. Think of your store as a server-side database, and it will be more reusable than if you adapted each section of the state to your views.
One way to do this for your application:
{ books: { bookId: { bookDetails, reviews: [ reviewId ], ownedBy: [ userId ], wishlistedBy: [ userId ], recommendations: [ recommendationId ] } }, users: { userId: { userDetails, reviews: [ reviewId ], wishlist: [ bookId ], ownedBooks: [ bookId ], friends: [ userId ], sentRecommendations: [ recommendationId ], receivedRecommendations: [ recommendationId ] } }, reviews: { reviewId: { bookId, userId, reviewDetails } }, recommendations: { recommendationId: { sender: userId, recipient: userId, bookId, recommendationDetails } } }
You may not need all of these relationships, so don’t feel that you need to realize all this. But starting with a database like this, adding functions later will be much easier.
Resources
Where to post your search results
Search results are more detailed than data. You may need to keep a historical record of searches, in which case you can add a reducer for searches:
{ searches: [ { searchTerm, searchDetails } ] }
But even so, I don’t think I’ll save the search results. Saving results will limit functionality in a few cases.
- When the user performs a search, a new book is added, you will not be able to find a new book in a subsequent search, if you do not restart the search (which denies the usefulness of storing the results).
- The search should be quick, and storing results only speeds up repeated searches (which is likely to be less common).
So, I look at the results in the form of a detail - or, as James K. Nelson calls it, a “Control State” (read: 5 types of React Application State ). Your question does not indicate which view library (if any) you are using, but the concepts here should apply regardless of whether you use React or not.
Search results should be calculated by presentation. The view will receive user input, potentially extract the data (which will be added to the repository), run some filter function in the Redux state and display the results.