The expected pattern for handling unknown data sources from React's ssr
rendering library, in this case a data-attribute
value, provides an alternative to event propagation and graceful degradation for error handling.
- is the attribute name safe?
- if no, return
- does the node have the attribute?
- if no, return a value of null unless expected is undefined, in which case, return undefined.
- assign the value of
getAttribute
- is the value equal to an empty string? return expected
- otherwise, return the value
This replaces the fault-tolerant pattern of graceful degradation that expects a false value for ambiguous return values with a development environment-friendly data-mocking parameter without the weight of a default.