Skip to content

Commit

Permalink
Renamed some collection methods.
Browse files Browse the repository at this point in the history
Added IsEmpty normal property.
  • Loading branch information
jlaanstra committed Mar 19, 2013
1 parent 05c6043 commit 353ae7d
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 14 deletions.
4 changes: 2 additions & 2 deletions ReactiveUI.Routing/RoutingState.cs
Expand Up @@ -69,7 +69,7 @@ void setupRx()
if (rxObjectsSetup) return; if (rxObjectsSetup) return;


NavigateBack = new ReactiveCommand( NavigateBack = new ReactiveCommand(
NavigationStack.CollectionCountChanged.StartWith(_NavigationStack.Count).Select(x => x > 1)); NavigationStack.CountChanged.StartWith(_NavigationStack.Count).Select(x => x > 1));
NavigateBack.Subscribe(_ => NavigateBack.Subscribe(_ =>
NavigationStack.RemoveAt(NavigationStack.Count - 1)); NavigationStack.RemoveAt(NavigationStack.Count - 1));


Expand Down Expand Up @@ -129,7 +129,7 @@ public static IRoutableViewModel GetCurrentViewModel(this IRoutingState This)
/// </summary> /// </summary>
public static IObservable<IRoutableViewModel> ViewModelObservable(this IRoutingState This) public static IObservable<IRoutableViewModel> ViewModelObservable(this IRoutingState This)
{ {
return This.NavigationStack.CollectionCountChanged return This.NavigationStack.CountChanged
.Select(_ => This.GetCurrentViewModel()) .Select(_ => This.GetCurrentViewModel())
.StartWith(This.GetCurrentViewModel()); .StartWith(This.GetCurrentViewModel());
} }
Expand Down
2 changes: 1 addition & 1 deletion ReactiveUI.Routing/RxRouting.cs
Expand Up @@ -125,7 +125,7 @@ public static IDisposable WhenNavigatedTo(this IRoutableViewModel This, Func<IDi
IDisposable inner = null; IDisposable inner = null;


var router = This.HostScreen.Router; var router = This.HostScreen.Router;
return router.NavigationStack.CollectionCountChanged.Subscribe(_ => { return router.NavigationStack.CountChanged.Subscribe(_ => {
if (router.GetCurrentViewModel() == This) { if (router.GetCurrentViewModel() == This) {
if (inner != null) inner.Dispose(); if (inner != null) inner.Dispose();
inner = onNavigatedTo(); inner = onNavigatedTo();
Expand Down
6 changes: 3 additions & 3 deletions ReactiveUI.Tests/ReactiveCollectionTest.cs
Expand Up @@ -24,8 +24,8 @@ public void CollectionCountChangedTest()
var before_output = new List<int>(); var before_output = new List<int>();
var output = new List<int>(); var output = new List<int>();


fixture.CollectionCountChanging.Subscribe(before_output.Add); fixture.CountChanging.Subscribe(before_output.Add);
fixture.CollectionCountChanged.Subscribe(output.Add); fixture.CountChanged.Subscribe(output.Add);


fixture.Add(10); fixture.Add(10);
fixture.Add(20); fixture.Add(20);
Expand All @@ -47,7 +47,7 @@ public void CollectionCountChangedFiresWhenClearing()
{ {
var items = new ReactiveCollection<object>(new []{new object()}); var items = new ReactiveCollection<object>(new []{new object()});
bool countChanged = false; bool countChanged = false;
items.CollectionCountChanged.Subscribe(_ => {countChanged = true;}); items.CountChanged.Subscribe(_ => {countChanged = true;});


items.Clear(); items.Clear();


Expand Down
6 changes: 3 additions & 3 deletions ReactiveUI/Interfaces.cs
Expand Up @@ -148,18 +148,18 @@ public interface IReactiveCollection : IEnumerable, INotifyCollectionChanged
/// Fires whenever the number of items in a collection has changed, /// Fires whenever the number of items in a collection has changed,
/// providing the new Count. /// providing the new Count.
/// </summary> /// </summary>
IObservable<int> CollectionCountChanged { get; } IObservable<int> CountChanged { get; }


/// <summary> /// <summary>
/// Fires before a collection is about to change, providing the previous /// Fires before a collection is about to change, providing the previous
/// Count. /// Count.
/// </summary> /// </summary>
IObservable<int> CollectionCountChanging { get; } IObservable<int> CountChanging { get; }


/// <summary> /// <summary>
/// Fires when a collection becomes or stops being empty. /// Fires when a collection becomes or stops being empty.
/// </summary> /// </summary>
IObservable<bool> IsEmpty { get; } IObservable<bool> IsEmptyChanged { get; }


// //
// Change Tracking // Change Tracking
Expand Down
20 changes: 15 additions & 5 deletions ReactiveUI/ReactiveCollection.cs
Expand Up @@ -97,14 +97,19 @@ void setupRx(IEnumerable<T> initialContents = null, IScheduler scheduler = null,
// NB: ObservableCollection has a Secret Handshake with WPF where // NB: ObservableCollection has a Secret Handshake with WPF where
// they fire an INPC notification with the token "Item[]". Emulate // they fire an INPC notification with the token "Item[]". Emulate
// it here // it here
CollectionCountChanging.Subscribe(_ => { CountChanging.Subscribe(_ => {
if (PropertyChanging != null) PropertyChanging(this, new PropertyChangingEventArgs("Count")); if (PropertyChanging != null) PropertyChanging(this, new PropertyChangingEventArgs("Count"));
}); });


CollectionCountChanged.Subscribe(_ => { CountChanged.Subscribe(_ => {
if (PropertyChanged != null) PropertyChanged(this, new PropertyChangedEventArgs("Count")); if (PropertyChanged != null) PropertyChanged(this, new PropertyChangedEventArgs("Count"));
}); });


IsEmptyChanged.Subscribe(_ =>
{
if (PropertyChanged != null) PropertyChanged(this, new PropertyChangedEventArgs("IsEmpty"));
});

Changing.Subscribe(_ => { Changing.Subscribe(_ => {
if (PropertyChanging != null) PropertyChanging(this, new PropertyChangingEventArgs("Item[]")); if (PropertyChanging != null) PropertyChanging(this, new PropertyChangingEventArgs("Item[]"));
}); });
Expand All @@ -116,6 +121,11 @@ void setupRx(IEnumerable<T> initialContents = null, IScheduler scheduler = null,
rxObjectsSetup = true; rxObjectsSetup = true;
} }


public bool IsEmpty
{
get { return this.Count == 0; }
}



/* /*
* Collection<T> core methods * Collection<T> core methods
Expand Down Expand Up @@ -374,15 +384,15 @@ public IDisposable SuppressChangeNotifications()
} }
} }


public IObservable<int> CollectionCountChanging { public IObservable<int> CountChanging {
get { return _changing.Select(_ => _inner.Count).DistinctUntilChanged(); } get { return _changing.Select(_ => _inner.Count).DistinctUntilChanged(); }
} }


public IObservable<int> CollectionCountChanged { public IObservable<int> CountChanged {
get { return _changed.Select(_ => _inner.Count).DistinctUntilChanged(); } get { return _changed.Select(_ => _inner.Count).DistinctUntilChanged(); }
} }


public IObservable<bool> IsEmpty { public IObservable<bool> IsEmptyChanged {
get { return _changed.Select(_ => _inner.Count == 0).DistinctUntilChanged(); } get { return _changed.Select(_ => _inner.Count == 0).DistinctUntilChanged(); }
} }


Expand Down

0 comments on commit 353ae7d

Please sign in to comment.