2

I'm looking into the possibility of implementing an MVU pattern in a Xamarin app using C#. This mostly seems to hinge on the immutability of the model being provided to the view and the Update function that will keep producing a new model whenever the model needs to be changed.

Is it possible in C# to properly achieve this without implementing some sort of deep copy if the model might contain reference types?

I'm aware that frameworks like Fabulous exist for doing this in F# but I'm just trying to understand if C#'s lack of support for immutability means it isn't possibly to implement a pure form of MVU without resorting to implementing some sort of deep copy operation?

3 Answers 3

2

Seems like Microsoft will answer to this questions with its upcoming Multi-platform App UI (MAUI) framework soon:

readonly State<int> count = 0;

[Body]
View body() => new StackLayout
{
    new Label("Welcome to .NET MAUI!"),
    new Button(
        () => $"You clicked {count} times.",
        () => count.Value ++)
    )
};

More info:

Sign up to request clarification or add additional context in comments.

Comments

2

Comet is likely the library you're looking for. It will also be the foundation of the MVU pattern MAUI will support, and that @sevenate was referring to.

Comments

0

There's a library for doing full MVU in C# with Xamarin.Forms: https://github.com/shirshov/laconic (I'm the author)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.