🕓 5 MIN Hot Design is here, …
State management patterns like MVU and MVVM have long been staples in application development, but both come with trade-offs that can limit scalability and maintainability in complex projects. Model-View-Update eXtended (MVUX) a new pattern in Uno Platform, bridges the gap between these two approaches, offering a more streamlined, asynchronous-friendly alternative. If you’ve ever struggled with the rigidness of MVU or the complexity of MVVM, MVUX could be the solution you’ve been looking for.
Before diving into MVUX, let’s review the pros and cons of MVU and MVVM:
Both share a common drawback: lack of async-friendliness, particularly in command execution and data reading.
MVUX addresses these limitations by combining the strengths of MVU and MVVM:
One core principle of MVUX is immutability. Let’s look at a simple example:
internal partial record Countable(int Count, int Step)
{
public Countable Increment() => this with
{
Count = Count + Step
};
}
Instead of modifying the existing Countable object, we create a new one with updated values. This approach provides a clear history of state changes, which is incredibly helpful during debugging.
MVUX integrates smoothly with XAML or C# markup. Here’s how to connect your UI to your data model:
This simple declaration bridges your entire UI with the underlying model, enabling robust data binding while maintaining immutability.
MVUX encourages a shift in how we think about state updates. Rather than directly modifying properties, we define methods that describe state changes:
public ValueTask IncrementCounter()
=> Countable.UpdateAsync(c => c?.Increment());
This approach leads to more predictable and maintainable code, especially as your application grows in complexity.
The magic of MVUX lies in its approach to model declaration and view model generation:
internal partial record MainModel
{
public IState Countable => State.Value(this, () => new Countable(0, 1));
public ValueTask IncrementCounter()
=> Countable.UpdateAsync(c => c?.Increment());
}
The MVUX engine uses source generators to automatically create a ViewModel with the same API surface as your model. This approach combines MVU’s immutability with MVVM’s familiar data binding while providing built-in support for asynchronous operations.
The following Uno Tech Bite provides a hands-on introduction to MVUX (Model-View-Update-X). It covers the fundamental concepts and walks you through building a simple counter application using MVUX with your choice of C# markup or XAML.
Consider a weather app fetching data from an external API. With MVUX:
MVUX in Uno Platform represents a thoughtful evolution in state management for cross-platform development. Addressing the limitations of MVU and MVVM offers a powerful pattern for building robust, maintainable applications.
Whether you’re from an MVVM background or more familiar with MVU, MVUX provides a familiar yet enhanced development experience. It’s worth considering for your next Uno Platform project, especially for complex, asynchronous operations or to improve overall application architecture.
The Uno Platform documentation is an excellent resource for diving deeper into MVUX and its practical applications.
Happy coding!
Tags: XAML, WPF, Xamarin, UWP, Silverlight, .NET, Windows, C#, XAML
🕓 2 MIN Need a last-minute holiday …
Uno Platform
360 rue Saint-Jacques, suite G101,
Montréal, Québec, Canada
H2Y 1P5
USA/CANADA toll free: +1-877-237-0471
International: +1-514-312-6958
Necessary cookies are absolutely essential for the website to function properly. This category only includes cookies that ensures basic functionalities and security features of the website. These cookies do not store any personal information.
Any cookies that may not be particularly necessary for the website to function and is used specifically to collect user personal data via analytics, ads, other embedded contents are termed as non-necessary cookies. It is mandatory to procure user consent prior to running these cookies on your website.
Uno Platform 5.2 LIVE Webinar – Today at 3 PM EST – Watch