Skip to content

Instantly share code, notes, and snippets.

@rdelrosario
Last active April 28, 2021 16:02
Show Gist options
  • Select an option

  • Save rdelrosario/400aa502699962bfb0de79e892f24239 to your computer and use it in GitHub Desktop.

Select an option

Save rdelrosario/400aa502699962bfb0de79e892f24239 to your computer and use it in GitHub Desktop.
namespace DynamicDataGroupingSample
{
public class NotificationConfigurationViewModel : ReactiveObjectEx
{
public NotificationConfigurationViewModel()
{
...
var smsChannelChangedCommand = ReactiveCommand.CreateFromTask<NotificationConfiguration>(OnSmsChannelChanged);
var emailChannelChangedCommand = ReactiveCommand.CreateFromTask<NotificationConfiguration>(OnEmailChannelChanged);
var pushNotificationChannelChangedCommand = ReactiveCommand.CreateFromTask<NotificationConfiguration>(OnPushNotificationChannelChanged);
var phoneChannelChangedCommand = ReactiveCommand.CreateFromTask<NotificationConfiguration>(OnPhoneChannelChanged);
notificationConfigurationItemChanges
.WhenPropertyChanged(x => x.SmsChannel , notifyOnInitialValue: false)
.Throttle(TimeSpan.FromMilliseconds(SelectionDueMilliseconds), RxApp.TaskpoolScheduler)
.Select(x => x.Sender)
.InvokeCommand(smsChannelChangedCommand)
.DisposeWith(Subscriptions);
notificationConfigurationItemChanges
.WhenPropertyChanged(x => x.EmailChannel, notifyOnInitialValue: false)
.Throttle(TimeSpan.FromMilliseconds(SelectionDueMilliseconds), RxApp.TaskpoolScheduler)
.Select(x => x.Sender)
.InvokeCommand(emailChannelChangedCommand)
.DisposeWith(Subscriptions);
notificationConfigurationItemChanges
.WhenPropertyChanged(x => x.PushNotificationChannel, notifyOnInitialValue: false)
.Throttle(TimeSpan.FromMilliseconds(SelectionDueMilliseconds), RxApp.TaskpoolScheduler)
.Select(x => x.Sender)
.InvokeCommand(pushNotificationChannelChangedCommand)
.DisposeWith(Subscriptions);
notificationConfigurationItemChanges
.WhenPropertyChanged(x => x.PhoneChannel, notifyOnInitialValue: false)
.Throttle(TimeSpan.FromMilliseconds(SelectionDueMilliseconds), RxApp.TaskpoolScheduler)
.Select(x => x.Sender)
.InvokeCommand(phoneChannelChangedCommand)
.DisposeWith(Subscriptions);
}
private Task OnPhoneChannelChanged(NotificationConfiguration notificationConfiguration)
{
System.Diagnostics.Debug.WriteLine($"Phone Channel - Changed - {notificationConfiguration.GroupName}.{notificationConfiguration.Name} - {notificationConfiguration.PhoneChannel}");
return Task.CompletedTask;
}
private Task OnPushNotificationChannelChanged(NotificationConfiguration notificationConfiguration)
{
System.Diagnostics.Debug.WriteLine($"Push Notification Channel - Changed - {notificationConfiguration.GroupName}.{notificationConfiguration.Name} - {notificationConfiguration.PushNotificationChannel}");
return Task.CompletedTask;
}
private Task OnEmailChannelChanged(NotificationConfiguration notificationConfiguration)
{
System.Diagnostics.Debug.WriteLine($"Email Notification Channel - Changed - {notificationConfiguration.GroupName}.{notificationConfiguration.Name} - {notificationConfiguration.EmailChannel}");
return Task.CompletedTask;
}
private Task OnSmsChannelChanged(NotificationConfiguration notificationConfiguration)
{
System.Diagnostics.Debug.WriteLine($"SMS Notification Channel - Changed - {notificationConfiguration.GroupName}.{notificationConfiguration.Name} - {notificationConfiguration.SmsChannel}");
return Task.CompletedTask;
}
private const int SelectionDueMilliseconds = 250;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment