Permalink
Browse files

Renamed some collection methods.

Added IsEmpty normal property.
  • Loading branch information...
jlaanstra committed Feb 1, 2013
1 parent 05c6043 commit 353ae7de86651e4e62a218db11fdfae86b500538
@@ -69,7 +69,7 @@ void setupRx()
if (rxObjectsSetup) return;
NavigateBack = new ReactiveCommand(
- NavigationStack.CollectionCountChanged.StartWith(_NavigationStack.Count).Select(x => x > 1));
+ NavigationStack.CountChanged.StartWith(_NavigationStack.Count).Select(x => x > 1));
NavigateBack.Subscribe(_ =>
NavigationStack.RemoveAt(NavigationStack.Count - 1));
@@ -129,7 +129,7 @@ public static IRoutableViewModel GetCurrentViewModel(this IRoutingState This)
/// </summary>
public static IObservable<IRoutableViewModel> ViewModelObservable(this IRoutingState This)
{
- return This.NavigationStack.CollectionCountChanged
+ return This.NavigationStack.CountChanged
.Select(_ => This.GetCurrentViewModel())
.StartWith(This.GetCurrentViewModel());
}
@@ -125,7 +125,7 @@ public static IDisposable WhenNavigatedTo(this IRoutableViewModel This, Func<IDi
IDisposable inner = null;
var router = This.HostScreen.Router;
- return router.NavigationStack.CollectionCountChanged.Subscribe(_ => {
+ return router.NavigationStack.CountChanged.Subscribe(_ => {
if (router.GetCurrentViewModel() == This) {
if (inner != null) inner.Dispose();
inner = onNavigatedTo();
@@ -24,8 +24,8 @@ public void CollectionCountChangedTest()
var before_output = new List<int>();
var output = new List<int>();
- fixture.CollectionCountChanging.Subscribe(before_output.Add);
- fixture.CollectionCountChanged.Subscribe(output.Add);
+ fixture.CountChanging.Subscribe(before_output.Add);
+ fixture.CountChanged.Subscribe(output.Add);
fixture.Add(10);
fixture.Add(20);
@@ -47,7 +47,7 @@ public void CollectionCountChangedFiresWhenClearing()
{
var items = new ReactiveCollection<object>(new []{new object()});
bool countChanged = false;
- items.CollectionCountChanged.Subscribe(_ => {countChanged = true;});
+ items.CountChanged.Subscribe(_ => {countChanged = true;});
items.Clear();
View
@@ -148,18 +148,18 @@ public interface IReactiveCollection : IEnumerable, INotifyCollectionChanged
/// Fires whenever the number of items in a collection has changed,
/// providing the new Count.
/// </summary>
- IObservable<int> CollectionCountChanged { get; }
+ IObservable<int> CountChanged { get; }
/// <summary>
/// Fires before a collection is about to change, providing the previous
/// Count.
/// </summary>
- IObservable<int> CollectionCountChanging { get; }
+ IObservable<int> CountChanging { get; }
/// <summary>
/// Fires when a collection becomes or stops being empty.
/// </summary>
- IObservable<bool> IsEmpty { get; }
+ IObservable<bool> IsEmptyChanged { get; }
//
// Change Tracking
@@ -97,14 +97,19 @@ void setupRx(IEnumerable<T> initialContents = null, IScheduler scheduler = null,
// NB: ObservableCollection has a Secret Handshake with WPF where
// they fire an INPC notification with the token "Item[]". Emulate
// it here
- CollectionCountChanging.Subscribe(_ => {
+ CountChanging.Subscribe(_ => {
if (PropertyChanging != null) PropertyChanging(this, new PropertyChangingEventArgs("Count"));
});
- CollectionCountChanged.Subscribe(_ => {
+ CountChanged.Subscribe(_ => {
if (PropertyChanged != null) PropertyChanged(this, new PropertyChangedEventArgs("Count"));
});
+ IsEmptyChanged.Subscribe(_ =>
+ {
+ if (PropertyChanged != null) PropertyChanged(this, new PropertyChangedEventArgs("IsEmpty"));
+ });
+
Changing.Subscribe(_ => {
if (PropertyChanging != null) PropertyChanging(this, new PropertyChangingEventArgs("Item[]"));
});
@@ -116,6 +121,11 @@ void setupRx(IEnumerable<T> initialContents = null, IScheduler scheduler = null,
rxObjectsSetup = true;
}
+ public bool IsEmpty
+ {
+ get { return this.Count == 0; }
+ }
+
/*
* Collection<T> core methods
@@ -374,15 +384,15 @@ public IDisposable SuppressChangeNotifications()
}
}
- public IObservable<int> CollectionCountChanging {
+ public IObservable<int> CountChanging {
get { return _changing.Select(_ => _inner.Count).DistinctUntilChanged(); }
}
- public IObservable<int> CollectionCountChanged {
+ public IObservable<int> CountChanged {
get { return _changed.Select(_ => _inner.Count).DistinctUntilChanged(); }
}
- public IObservable<bool> IsEmpty {
+ public IObservable<bool> IsEmptyChanged {
get { return _changed.Select(_ => _inner.Count == 0).DistinctUntilChanged(); }
}

0 comments on commit 353ae7d

Please sign in to comment.