I'm starting to play around with the concept of structuring app this way and I find myself tempting to have domain rules functions inside states so I can reuse them. Even I couldn't find any documentation about it, it does seem weird as states feel as they should only have properties on it. For example, let's say I have a board state exposing a method that is used by a few action creators in order to determine which action to dispatch to the store. Is it ok to have it on the state itself? or should I create a common class for this action creators and put this logic in there? If neither is ok, where is the recommended place to put this logic?
Asked
Active
Viewed 88 times
1 Answers
0
There seems to be some confusion here. Your state should not be involved in determining which action to dispatch to the store. Rather, the nature of the side-effect should determine the action and then your reducer should determine how to change state based on the current state and the action performed.
As for your general question, as long as the functions are referentially transparent, it doesn't matter much exactly where you put them. In other words, the only difference between foo.bar()
and bar(foo)
is syntax so do whatever feels more comfortable to you.

Daniel T.
- 32,821
- 6
- 50
- 72