refactor: Make vm prop changed subs more performant
This commit is contained in:
1 parent
9f9113bf9a
commit
ce8eda24fc
1 file changed
+13
-1
@@ -327,7 +327,19 @@ namespace mbts.ui.shell {
|
||||
public DelegateProperty(ViewModelBase owner, string name, Func<T> get_value, T default_value, params string[] invalidating_props)
|
||||
: base(owner, name, default_value) {
|
||||
_get_value = get_value;
|
||||
if (invalidating_props != null && invalidating_props.Length > 0) {
|
||||
if (invalidating_props.is_null_or_empty()) {
|
||||
connect_invalidating_props();
|
||||
}
|
||||
|
||||
void connect_invalidating_props() {
|
||||
if (owner is IPropertyChangedDemuxer demuxer
|
||||
&& owner is IWillLetYouKnowWhenIDispose disposer) {
|
||||
/// IPropertyChangedDemuxer impl aggregates property callbacks, so it handles
|
||||
/// cases where multiple props are invalidated by one or more common props more
|
||||
/// efficiently (assuming owner is of type) <see cref="DisposableViewModelBase"/>
|
||||
disposer.SubscribeDisposed(demuxer.subscribe_many(refresh, invalidating_props));
|
||||
return;
|
||||
}
|
||||
var iprop_set = new HashSet<string>(invalidating_props);
|
||||
owner.PropertyChanged += (s, e) => {
|
||||
if (iprop_set.Contains(e.PropertyName))
|
||||
|
||||
Reference in new issue
Block a user