I have been using NgRx for a while and trying to understand the functional language feature or design pattern being used to create selectors as described on this NgRx documentation page. Coming from a Object Oriented Programming background, seeing numerous functions instead of a simple call which takes a bunch of attributes has confused me.
What functional language feature or design pattern being used to create NgRx selectors?
I guess the best explanation would be, that this solution is there to enforce one thing: Single source of truth.
If you had the possibility to provide a
stateto the selector, or to providepartial selectorsin case of the combined ones, how would you be sure that none of them were modified prior to selecting?Imagine a situation like this:
As I said, I always took it as a form of enforcing the single source of truth. This is achieved by currying the selectors, not giving you the ability to provide modified state or slice while selecting desired slice of the state.
And if you think of selectors with props - nowadays Factory Selectors, they still only allow you to send a parameter to modify the selection, but they still rely on curried functions, not allowing you to provide the state itself.