ObserversGroup (was: AutoCommandBinding)
Opened this issue · 2 comments
From @fabiocbr75 on September 15, 2015 19:15
With AutoCommandBinding the viewmodel is very clean but I don't found how is possibile convert following code in AutoCommandBinding way.
XXXCommand = DelegateCommand.Create()
.OnExecute(o => MyFunc())
.OnCanExecute(o => CanRun)
.AddMonitor(PropertyObserver.For(this).Observe(v => v.prp1))
.AddMonitor(PropertyObserver.For(this).Observe(v => v.prp2))
.AddMonitor(NotifyCollectionChangedMonitor.For(this.MyObservableCollection));
Is it possible?
Thanks
Copied from original issue: RadicalFx/Radical#190
@fabiocbr75 there is actually no way to do that, AutoCommandBinding
was designed with simplicity in mind. Given that AutoCommandBinding
relies only on the CanRun
changed notification to re-evaluate the state of the command we could introduce something like:
ObserverGroup.Create()
.AddMonitor(PropertyObserver.For(this).Observe(v => v.prp1))
.AddMonitor(PropertyObserver.For(this).Observe(v => v.prp2))
.AddMonitor(NotifyCollectionChangedMonitor.For(this.MyObservableCollection))
.OnChanged( () => this.OnPropertyChanged( () => CanRun ) );
The above will allow to achieve the same goal.
Thoughts?
/cc @micdenny
@mauroservienti IMHO I think we risk to over-engineer it, AutoCommandBinding
was a nice feature for fast prototyping and some easy peasy view-model, but when you need more control over it I think it's better to push people to use the full commanding api.
Told this, developing a decoupled api to manage AutoCommandBinding
could be a cool feature, I'm just asking ourselves if we really want to support also that piece of code for something we can achieve just using the normal commanding api, in the end the resulting to have a dedicated api or using the commanding one, is just a couple of rows:
XXXCommand = DelegateCommand.Create()
.OnExecute(o => MyFunc())
.OnCanExecute(o => CanRun)
.AddMonitor(PropertyObserver.For(this).Observe(v => v.prp1))
.AddMonitor(PropertyObserver.For(this).Observe(v => v.prp2))
.AddMonitor(NotifyCollectionChangedMonitor.For(this.MyObservableCollection));
VS
ObserverGroup.Create()
.AddMonitor(PropertyObserver.For(this).Observe(v => v.prp1))
.AddMonitor(PropertyObserver.For(this).Observe(v => v.prp2))
.AddMonitor(NotifyCollectionChangedMonitor.For(this.MyObservableCollection))
.OnChanged( () => this.OnPropertyChanged( () => CanRun ) );