Skip to content

Commit

Permalink
Merge pull request #290 from reactiveui/readonly-collections
Browse files Browse the repository at this point in the history
Add read only interfaces for reactive collections
  • Loading branch information
Paul Betts committed May 20, 2013
2 parents e02f78c + 580af48 commit bb39ea3
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
13 changes: 13 additions & 0 deletions ReactiveUI/Interfaces.cs
Expand Up @@ -211,6 +211,18 @@ public interface IReactiveCollection : ICollection, INotifyCollectionChanged, IN
IObservable<Unit> ShouldReset { get; }
}

public interface IReadOnlyReactiveCollection<T> : IReadOnlyCollection<T>, IReactiveCollection
{
}

public interface IReadOnlyReactiveList<T> : IReadOnlyList<T>, IReadOnlyReactiveCollection<T>
{
}

public interface IReactiveDerivedList<T> : IReadOnlyReactiveList<T>, IDisposable
{
}

/// <summary>
/// IReactiveCollection of T is the typed version of IReactiveCollection and
/// adds type-specified versions of Observables
Expand Down Expand Up @@ -254,6 +266,7 @@ public interface IReactiveCollection<T> : ICollection<T>, IReactiveCollection
/// ChangeTrackingEnabled is set to True.
/// </summary>
IObservable<IObservedChange<T, object>> ItemChanged { get; }

}

/// <summary>
Expand Down
14 changes: 7 additions & 7 deletions ReactiveUI/ReactiveCollectionMixins.cs
Expand Up @@ -11,7 +11,7 @@

namespace ReactiveUI
{
public abstract class ReactiveDerivedCollection<TValue> : ReactiveList<TValue>, IDisposable
public abstract class ReactiveDerivedCollection<TValue> : ReactiveList<TValue>, IReactiveDerivedList<TValue>
{
const string readonlyExceptionMessage = "Derived collections cannot be modified.";

Expand Down Expand Up @@ -151,7 +151,7 @@ public void Dispose()
public virtual void Dispose(bool disposing) { }
}

public sealed class ReactiveDerivedCollection<TSource, TValue> : ReactiveDerivedCollection<TValue>, IDisposable
public sealed class ReactiveDerivedCollection<TSource, TValue> : ReactiveDerivedCollection<TValue>
{
readonly IEnumerable<TSource> source;
readonly Func<TSource, TValue> selector;
Expand Down Expand Up @@ -504,7 +504,7 @@ public override void Dispose(bool disposing)
}
}

internal class ReactiveDerivedCollectionFromObservable<T>: ReactiveDerivedCollection<T>
internal class ReactiveDerivedCollectionFromObservable<T> : ReactiveDerivedCollection<T>
{
SingleAssignmentDisposable inner;

Expand Down Expand Up @@ -573,7 +573,7 @@ public static class ReactiveCollectionMixins
/// collection no faster than the delay provided.</param>
/// <returns>A new collection which will be populated with the
/// Observable.</returns>
public static ReactiveDerivedCollection<T> CreateCollection<T>(
public static IReactiveDerivedList<T> CreateCollection<T>(
this IObservable<T> fromObservable,
TimeSpan? withDelay = null,
Action<Exception> onError = null)
Expand All @@ -596,7 +596,7 @@ public static class ReactiveCollectionMixins
/// collection no faster than the delay provided.</param>
/// <returns>A new collection which will be populated with the
/// Observable.</returns>
public static ReactiveDerivedCollection<TRet> CreateCollection<T, TRet>(
public static IReactiveDerivedList<TRet> CreateCollection<T, TRet>(
this IObservable<T> fromObservable,
Func<T, TRet> selector,
TimeSpan? withDelay = null)
Expand Down Expand Up @@ -632,7 +632,7 @@ public static class ObservableCollectionMixin
/// <returns>A new collection whose items are equivalent to
/// Collection.Select().Where().OrderBy() and will mirror changes
/// in the initial collection.</returns>
public static ReactiveDerivedCollection<TNew> CreateDerivedCollection<T, TNew, TDontCare>(
public static IReactiveDerivedList<TNew> CreateDerivedCollection<T, TNew, TDontCare>(
this IEnumerable<T> This,
Func<T, TNew> selector,
Func<T, bool> filter = null,
Expand Down Expand Up @@ -670,7 +670,7 @@ public static class ObservableCollectionMixin
/// <returns>A new collection whose items are equivalent to
/// Collection.Select().Where().OrderBy() and will mirror changes
/// in the initial collection.</returns>
public static ReactiveDerivedCollection<TNew> CreateDerivedCollection<T, TNew>(
public static IReactiveDerivedList<TNew> CreateDerivedCollection<T, TNew>(
this IEnumerable<T> This,
Func<T, TNew> selector,
Func<T, bool> filter = null,
Expand Down

0 comments on commit bb39ea3

Please sign in to comment.