Skip to content
This repository has been archived by the owner on Feb 16, 2024. It is now read-only.

Add notifyCurrentCount option to ReactiveDictionary.ObserveCountChanged #321

Merged
merged 1 commit into from
Jul 16, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public interface IReadOnlyReactiveDictionary<TKey, TValue> : IEnumerable<KeyValu
bool TryGetValue(TKey key, out TValue value);

IObservable<DictionaryAddEvent<TKey, TValue>> ObserveAdd();
IObservable<int> ObserveCountChanged();
IObservable<int> ObserveCountChanged(bool notifyCurrentCount = false);
IObservable<DictionaryRemoveEvent<TKey, TValue>> ObserveRemove();
IObservable<DictionaryReplaceEvent<TKey, TValue>> ObserveReplace();
IObservable<Unit> ObserveReset();
Expand Down Expand Up @@ -290,10 +290,19 @@ public void Dispose()

[NonSerialized]
Subject<int> countChanged = null;
public IObservable<int> ObserveCountChanged()
public IObservable<int> ObserveCountChanged(bool notifyCurrentCount = false)
{
if (isDisposed) return Observable.Empty<int>();
return countChanged ?? (countChanged = new Subject<int>());

var subject = countChanged ?? (countChanged = new Subject<int>());
if (notifyCurrentCount)
{
return subject.StartWith(() => this.Count);
}
else
{
return subject;
}
}

[NonSerialized]
Expand Down