Description
Improve the DX by logging an error/warning for unexpected @rx-angular/state operators behavior when passing undefined values
As a developer I'd like to see a warning or an error when I'm passing undefined
value to a RxState#select or RxState#selectSlice operators. I stumbled into these issues myself and also heard about them from my colleagues when they started using RxState
library on their projects.
What passing an undefined
value actually causes is that the part of the template bound to e.g. *rxLet directive won't render at all. This is quite easy to spot if you are only using single prop binding but if you are using the ViewModel approach with lots of properties inside of a selectSlice
operator, this can be difficult to discover if it is not a known issue for the developer.
Solution
Throw an error when undefined
value is passed to the operator and show additional message to the developer that he/she should
- either make sure that the source of the property that is state connected to never emits
undefined
values - or initialize state with default values (e.g.
null
)
Note: the latter is a good practice, which should probably be also documented in theRxState
guidelines.
Alternatives Considered
Showing a warning should be also sufficient (but possibly less sufficient for less experienced developers) - should be discussed.