What is View.map about? #1060
-
I can't piece it together from the tests and (sadly like many other concepts), I can't find it documented anywhere. |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 3 replies
-
/// Map the widget's message type to the parent's message type to allow for view composition
let inline map (fn: 'oldMsg -> 'newMsg) (x: WidgetBuilder<'oldMsg, 'marker>) : WidgetBuilder<'newMsg, 'marker> = To illustrate why and when Because of MVU, all the pages need to return the same Msg type but they all have their own. module Sample =
type Model = ...
type Msg =
| PageAMsg of PageA.Msg // Here PageA has its own Msg
| PageBMsg of PageB.Msg // Same here
| PageCMsg of PageC.Msg // Same here
let init () = ...
let update msg model = ...
let view model =
ContentPage(
Grid() {
(match model.CurrentStep with
// Here View.map will map/wrap any Msg has been defined in PageA into the parent/root PageAMsg so it can used in the main MVU loop
| Step.PageA -> View.map PageAMsg (PageA.view model.PageAModel)
| Step.PageB -> View.map PageBMsg (PageB.view model.PageBModel)
| Step.PageC -> View.map PageCMsg (PageC.view model.PageCModel))
}
) You can see the |
Beta Was this translation helpful? Give feedback.
-
Using the approach recommended by @edgarfgp, I wrote a documentation page on how to use View.map: https://docs.fabulous.dev/advanced/composing-independent-mvu-states-into-a-single-app |
Beta Was this translation helpful? Give feedback.
-
I agree, it is - and that's really curbing its potential IMO. The dev experience is frustrating ATM if you stray off the beaten path. But I'm glad that you're aware of it - you are making up for it in responsiveness! |
Beta Was this translation helpful? Give feedback.
-
Thank you - that picks me up where I am! |
Beta Was this translation helpful? Give feedback.
Using the approach recommended by @edgarfgp, I wrote a documentation page on how to use View.map: https://docs.fabulous.dev/advanced/composing-independent-mvu-states-into-a-single-app