private static IDisposable ObserveItemPropertyChangedCore <TCollection, TItem, TProperty, T>( this TCollection source, IObserver <T> o, Expression <Func <TItem, TProperty> > property, bool signalInitial, Func <TItem, object, PropertyChangedEventArgs, SourceAndValue <INotifyPropertyChanged, TProperty>, T> create) where TCollection : class, IEnumerable <TItem>, INotifyCollectionChanged where TItem : class, INotifyPropertyChanged { var tracker = ItemsTracker.Create( signalInitial ? null : source, NotifyingPath.GetOrCreate(property)); TrackedItemPropertyChangedEventHandler <TItem, TProperty> handler = (item, sender, args, sourceAndValue) => o.OnNext( create( item, sender, args, sourceAndValue)); tracker.TrackedItemChanged += handler; if (signalInitial) { tracker.UpdateSource(source); } return(new CompositeDisposable(2) { Disposable.Create(() => tracker.TrackedItemChanged -= handler), tracker }); }
private static IDisposable ItemPropertyChangedCore <TCollection, TItem, TProperty, T>( this IObservable <TCollection> source, IObserver <T> observer, Expression <Func <TItem, TProperty> > property, Func <TItem, object, PropertyChangedEventArgs, SourceAndValue <INotifyPropertyChanged, TProperty>, T> create) where TCollection : class, IEnumerable <TItem>, INotifyCollectionChanged where TItem : class, INotifyPropertyChanged { var tracker = ItemsTracker.Create((TCollection)null, NotifyingPath.GetOrCreate(property)); tracker.TrackedItemChanged += Handler; var subscription = source.Subscribe(x => tracker.UpdateSource(x)); return(new CompositeDisposable(3) { Disposable.Create(() => tracker.TrackedItemChanged -= Handler), tracker, subscription, }); void Handler(TItem item, object sender, PropertyChangedEventArgs args, SourceAndValue <INotifyPropertyChanged, TProperty> sourceAndValue) { observer.OnNext(create(item, sender, args, sourceAndValue)); } }
private void UpdateDockedVehicles() { _vehiclesSnapshot = new List <Vehicle>(Vehicles); Vehicles.Clear(); ItemsTracker.Clear(); foreach (var dockingBay in DockingBays) { var vehicle = dockingBay.GetDockedVehicle(); if (vehicle != null) { vehicle.modules.onRemoveItem += ModulesOnRemoveItem; var vehicleContainers = DSSHelpers.GetVehicleContainers(vehicle); ItemsTracker.Add(vehicle, GetItems(vehicleContainers)); _trackedContainers.AddRange(vehicleContainers); Vehicles.Add(vehicle); UpdateSubscription(vehicleContainers, true, vehicle); } } if (_prevContainerAmount != _trackedContainers.Count) { _manager.OnContainerUpdate?.Invoke(_manager); } _prevContainerAmount = _trackedContainers.Count; _trackedContainers.Clear(); }