Skip to content

Instantly share code, notes, and snippets.

@worldbeater
Last active August 1, 2023 21:51
Show Gist options
  • Save worldbeater/ecfdda6960e90eecef20e878251e835c to your computer and use it in GitHub Desktop.
Save worldbeater/ecfdda6960e90eecef20e878251e835c to your computer and use it in GitHub Desktop.
Boilerplate Code Encapsulation. Reactive Property. See: https://medium.com/@worldbeater/reactive-mvvm-for-net-platform-175dc69cfc82
public class ReactivePropertyViewModel
{
public ReadOnlyReactiveProperty<string> Greeting { get; }
public ReactiveProperty<string> Name { get; }
public ReactiveCommand Clear { get; }
public ReactivePropertyViewModel()
{
Clear = new ReactiveCommand();
Clear.Subscribe(() => Name.Value = string.Empty);
Name = new ReactiveProperty<string>(string.Empty);
Greeting = Name
.Select(name => $"Hello, {name}!")
.ToReadOnlyReactiveProperty();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment