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?

Sevenate
  • 6,221
  • 3
  • 49
  • 75
MobDev
  • 163
  • 2
  • 11

3 Answers3

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:

Sevenate
  • 6,221
  • 3
  • 49
  • 75
1

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.

Richard Banks
  • 12,456
  • 3
  • 46
  • 62
0

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

Alex Shirshov
  • 635
  • 3
  • 8