1 module mvvm.models.simple; 2 3 import std.stdio; 4 import mvvm.common; 5 6 class SimpleViewModel 7 { 8 private ReactiveProperty!string _title; 9 public inout(ReactiveProperty!string) title() inout @property 10 { 11 return _title; 12 } 13 14 private ReactiveProperty!bool _isActive; 15 public inout(ReactiveProperty!bool) isActive() inout @property 16 { 17 return _isActive; 18 } 19 20 private Command _clearTitleCommand; 21 public inout(Command) clearTitleCommand() inout @property 22 { 23 return _clearTitleCommand; 24 } 25 26 this() 27 { 28 _title = new ReactiveProperty!string(""); 29 _isActive = new ReactiveProperty!bool(false); 30 31 _clearTitleCommand = new DelegateCommand(&clearTitle, isActive); 32 } 33 34 void clearTitle() 35 { 36 if (isActive.value) 37 title.value = ""; 38 } 39 } 40 41 unittest 42 { 43 auto model = new SimpleViewModel; 44 assert(model.isActive.value == false); 45 assert(model.title.value == ""); 46 47 model.title.value = "ABC"; 48 49 assert(model.title.value == "ABC"); 50 model.clearTitle(); 51 assert(model.title.value == "ABC"); 52 53 model.isActive.value = true; 54 model.clearTitle(); 55 assert(model.title.value == ""); 56 }