Refactor SelectedTab to DeclarativeProperty
This commit is contained in:
@@ -7,16 +7,25 @@ public class CollectionRepeaterProperty<TCollection, TItem> : DeclarativePropert
|
||||
{
|
||||
private TCollection? _currentCollection;
|
||||
|
||||
public CollectionRepeaterProperty(IDeclarativeProperty<TCollection?> from)
|
||||
public CollectionRepeaterProperty(IDeclarativeProperty<TCollection?> from) : base(from.Value)
|
||||
{
|
||||
_currentCollection = from.Value;
|
||||
if (from.Value is { } value)
|
||||
{
|
||||
value.CollectionChanged += HandleCollectionChanged;
|
||||
}
|
||||
|
||||
AddDisposable(from.Subscribe(Handle));
|
||||
}
|
||||
|
||||
public CollectionRepeaterProperty(TCollection? collection) : base(collection)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(collection);
|
||||
|
||||
_currentCollection = collection;
|
||||
collection.CollectionChanged += HandleCollectionChanged;
|
||||
}
|
||||
|
||||
private void HandleCollectionChanged(object? sender, NotifyCollectionChangedEventArgs e)
|
||||
{
|
||||
var t = Task.Run(async () => await NotifySubscribersAsync(Value));
|
||||
@@ -29,7 +38,8 @@ public class CollectionRepeaterProperty<TCollection, TItem> : DeclarativePropert
|
||||
{
|
||||
currentCollection.CollectionChanged -= HandleCollectionChanged;
|
||||
}
|
||||
if (collection is {} newCollection)
|
||||
|
||||
if (collection is { } newCollection)
|
||||
{
|
||||
newCollection.CollectionChanged -= HandleCollectionChanged;
|
||||
newCollection.CollectionChanged += HandleCollectionChanged;
|
||||
|
||||
@@ -69,6 +69,19 @@ public static class DeclarativePropertyExtensions
|
||||
this IDeclarativeProperty<TCollection?> collection)
|
||||
where TCollection : IList<TItem>, INotifyCollectionChanged
|
||||
=> new CollectionRepeaterProperty<TCollection?, TItem>(collection);
|
||||
|
||||
public static IDeclarativeProperty<TCollection?> Watch<TCollection, TItem>(
|
||||
this TCollection collection)
|
||||
where TCollection : IList<TItem>, INotifyCollectionChanged
|
||||
=> new CollectionRepeaterProperty<TCollection?, TItem>(collection);
|
||||
|
||||
public static IDeclarativeProperty<ObservableCollection<TItem>?> Watch<TItem>(
|
||||
this ObservableCollection<TItem> collection)
|
||||
=> new CollectionRepeaterProperty<ObservableCollection<TItem>?, TItem>(collection);
|
||||
|
||||
public static IDeclarativeProperty<ReadOnlyObservableCollection<TItem>?> Watch<TItem>(
|
||||
this ReadOnlyObservableCollection<TItem> collection)
|
||||
=> new CollectionRepeaterProperty<ReadOnlyObservableCollection<TItem>?, TItem>(collection);
|
||||
|
||||
|
||||
public static IDeclarativeProperty<TResult?> CombineLatest<T1, T2, TResult>(
|
||||
|
||||
Reference in New Issue
Block a user