Skip to content

Instantly share code, notes, and snippets.

@ionoy
Last active November 2, 2015 15:27
Show Gist options
  • Save ionoy/ac037fed47e461f5907e to your computer and use it in GitHub Desktop.
Save ionoy/ac037fed47e461f5907e to your computer and use it in GitHub Desktop.
viewmodel StatusViewModel
{
// Simple property definition, by default public and defines both get/set
string Name;
// Getter only
string Name get;
// Private field is everything prefixed by '_'
string _name;
// '=' symbol marks dependant property (all previous rules apply)
// Right part should always return value
// 'stream' keyword takes IObservable<T> and returns T, kinda like 'await'
string FullName = stream Name + " " + stream LastName;
// this is translated to
this.WhenAnyValue(vm => vm.Name)
.CombineLatest(this.WhenAnyValue(vm => vm.LastName))
.BindTo(FullName);
string ComplexValue = {
var val = stream service.Values;
throttle 1 second;
where val > 5;
var result = selectmany service.GetAsync(val)
return result;
}
// this is translated to
service.Values
.Throttle(TimeSpan.FromSeconds(1))
.Where(val => val > 5)
.SelectMany(val => serviceGetAsync(val))
.BindTo(vm => vm.ComplexValue);
// Simple command
command Notify = {
Debug.WriteLine("Button clicked!");
}
// Async command allows Task<T> and IObservable<T>
command<string> RequestAsync = new WebClient("url").DownloadStringAsync();
// Async command result is used like this
string Content = "Downloaded: " + stream RequestAsync;
// Default constructor definition, assigns 'fullName' to 'FullName' and 'age' to 'Age'
StatusViewModel(string fullName, string age);
// Manual constructor definition
StatusViewModel(string fullName, string age) {
FullName = fullName;
Age = age;
Debug.WriteLine("StatusViewModel constructor called");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment