// -----------------------------------------------------------------------
//
// Copyright 2014 MIT Licence. See licence.md for more information.
//
// -----------------------------------------------------------------------
namespace Perspex
{
using System;
using System.Collections.Generic;
using System.Reactive.Disposables;
using System.Reactive.Subjects;
///
/// Maintains a list of prioritised bindings together with a current value.
///
///
/// Bindings, in the form of s are added to the object using
/// the method. With the observable is passed a priority, where lower values
/// represent higher priorites. The current is selected from the highest
/// priority binding that doesn't return . Where there
/// are multiple bindings registered with the same priority, the most recently added binding
/// has a higher priority. Each time the value changes to a distinct new value, the
/// observable is fired with the old and new values.
///
public class PriorityValue
{
///
/// The currently registered binding entries.
///
private LinkedList bindings = new LinkedList();
///
/// The changed observable.
///
private Subject> changed = new Subject>();
///
/// The current value.
///
private object value;
///
/// The priority of the binding that is currently active.
///
private int valuePriority = int.MaxValue;
///
/// Initializes a new instance of the class.
///
public PriorityValue()
{
this.value = PerspexProperty.UnsetValue;
}
///
/// Fired whenever the current changes to a new distinct value.
///
public IObservable> Changed
{
get { return this.changed; }
}
///
/// Gets the current value.
///
public object Value
{
get { return this.value; }
}
///
/// Adds a new binding.
///
/// The binding.
/// The binding priority.
///
/// A disposable that will remove the binding.
///
public IDisposable Add(IObservable