csharpc-sharpdotnetxamlavaloniauicross-platformcross-platform-xamlavaloniaguimulti-platformuser-interfacedotnetcore
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
48 lines
1.7 KiB
48 lines
1.7 KiB
// -----------------------------------------------------------------------
|
|
// <copyright file="PerspexObservable.cs" company="Steven Kirk">
|
|
// Copyright 2015 MIT Licence. See licence.md for more information.
|
|
// </copyright>
|
|
// -----------------------------------------------------------------------
|
|
|
|
namespace Perspex.Reactive
|
|
{
|
|
using System;
|
|
using System.Reactive;
|
|
using System.Reactive.Disposables;
|
|
|
|
/// <summary>
|
|
/// An <see cref="IObservable{T}"/> with an additional description.
|
|
/// </summary>
|
|
/// <typeparam name="T">The type of the elements in the sequence.</typeparam>
|
|
public sealed class PerspexObservable<T> : ObservableBase<T>, IDescription
|
|
{
|
|
private readonly Func<IObserver<T>, IDisposable> subscribe;
|
|
|
|
/// <summary>
|
|
/// Initializes a new instance of the <see cref="PerspexObservable{T}"/> class.
|
|
/// </summary>
|
|
/// <param name="subscribe">The subscribe function.</param>
|
|
/// <param name="description">The description of the observable.</param>
|
|
public PerspexObservable(Func<IObserver<T>, IDisposable> subscribe, string description)
|
|
{
|
|
if (subscribe == null)
|
|
{
|
|
throw new ArgumentNullException("subscribe");
|
|
}
|
|
|
|
this.subscribe = subscribe;
|
|
this.Description = description;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Gets the description of the observable.
|
|
/// </summary>
|
|
public string Description { get; }
|
|
|
|
/// <inheritdoc/>
|
|
protected override IDisposable SubscribeCore(IObserver<T> observer)
|
|
{
|
|
return this.subscribe(observer) ?? Disposable.Empty;
|
|
}
|
|
}
|
|
}
|