jwstegemann / fritz2

Easily build reactive web-apps in Kotlin based on flows and coroutines.
https://www.fritz2.dev
MIT License
636 stars 25 forks source link

Add `Inspector.mapNull()` method and fix `Store.mapNull()` path #772

Closed haukesomm closed 1 year ago

haukesomm commented 1 year ago

This PR adds an Inspector.mapNull() extension function that works like Store.mapNull(). Just like on a Store, a default value is passed to the method that is used by the resulting store when the parent's value is null.

Additionally, the behavior of Store.mapNull() has been changed so that the path of the derived Store is the same as in the parent Store. This is the correct behavior as a Store created via mapNull() does not technically map to another hierarchical level of the data model. As a result, mapNull() works the same on both Stores and Inspectors, making the validation process more straight-forward. Previously, the Store's id has been appended to the path upon derivation.

This PR might potentially be API breaking as the behavior of Store.mapNull() regarding the resulting path changes.

Closes #769