Browse Source
Similar to Rx's AnonymousObservable that is created using Observable.Create, but it also implements IDescription. This description is populated when created by PerspexObject.GetObservable.pull/58/head
2 changed files with 57 additions and 12 deletions
@ -0,0 +1,35 @@ |
|||
// -----------------------------------------------------------------------
|
|||
// <copyright file="PerspexObject.cs" company="Steven Kirk">
|
|||
// Copyright 2014 MIT Licence. See licence.md for more information.
|
|||
// </copyright>
|
|||
// -----------------------------------------------------------------------
|
|||
|
|||
namespace Perspex.Reactive |
|||
{ |
|||
using System; |
|||
using System.Reactive; |
|||
using System.Reactive.Disposables; |
|||
|
|||
public sealed class PerspexObservable<T> : ObservableBase<T>, IDescription |
|||
{ |
|||
private readonly Func<IObserver<T>, IDisposable> subscribe; |
|||
|
|||
public string Description { get; } |
|||
|
|||
public PerspexObservable(Func<IObserver<T>, IDisposable> subscribe, string description) |
|||
{ |
|||
if (subscribe == null) |
|||
{ |
|||
throw new ArgumentNullException("subscribe"); |
|||
} |
|||
|
|||
this.subscribe = subscribe; |
|||
this.Description = description; |
|||
} |
|||
|
|||
protected override IDisposable SubscribeCore(IObserver<T> observer) |
|||
{ |
|||
return this.subscribe(observer) ?? Disposable.Empty; |
|||
} |
|||
} |
|||
} |
|||
Loading…
Reference in new issue