mrousavy / Jellyfish

🐟 An incredibly lightweight and type safe MVVM library for .NET WPF, Silverlight, Xamarin and UWP
MIT License
21 stars 4 forks source link

Global message queue #3

Closed mrousavy closed 6 years ago

mrousavy commented 6 years ago

Add a global message queue that will receive and foward messages from (view)-models to (view)-models.

Example:

LoginViewModel.cs

public class MainViewModel : Sender<T>, ...
{
    public void LoginAction()
    {
        // send message of type T to any other VM
        base.Send(new { User = this.User, Status = Status.LoggedIn });
    }
}

MainViewModel.cs

public class MainViewModel : Receiver<T>, ...
{
    public override void Receive(T message)
    {
        // received message of type T from another VM
    }
}

Receiver can optionally also handle whether the message gets removed from the global message queue or stays untouched.

This is especially useful for multi-view applications, where extra updates are needed upon some action.

Use case:

mrousavy commented 6 years ago

Implemented in b2ed0e8ea916ca3fc4f7ba9ec3b006a2b401d07d