TimLariviere/Fabulous-new

[Architecture] Add lifecycle events to widget (mount, dismount, create, destroy)

TimLariviere opened this issue · 5 comments

[Architecture] Add lifecycle events to widget (mount, dismount, create, destroy)

In which order should this happen?

Create -> Mount -> Dismount -> Destroy ?

Yes. I think that's the good order.
Just after dismount, the widget can be re-mounted.

An example is ListView with virtualization

Yes that sounds correct.
Do you have an idea or a preference how to act on them?

e.g. like a extensionmethod ?

StackLayout().onCreate(fun _ => printfn "OnCreate")
twop commented

I think instead of lambda we want it to accept a concrete message, or a function that creates a concrete message (in case we need to pass data in).

like so

StackLayout().onCreate(StackCreated)

// if we need to pass args
StackLayout().onCreate(fun args -> StackCreated args)

@SergejDK Yes, an extension method is good. That lambda should return a 'msg type like @twop said.
I think we can start without parameters.

Contrary to what we do in v1 (create lets you access the XF control), I think we will only notify that the control has been created.
Then with ViewRef, developers will be able to access the XF control itself.

type Msg =
    | LabelCreated

let labelRef = ViewRef<_>()

let update msg model =
    match msg with
    | LabelCreated ->
        labelRef.Value.BackgroundColor <- Color.Blue

let view model =
    StackLayout() {
        Label("Text")
            .reference(labelRef)
            .onCreate(LabelCreated)
    }