Browse Source

Removed LevelPrecedenceMode.

You should use direct properties if you want Latest mode.
pull/494/merge
Steven Kirk 11 years ago
parent
commit
87fa632707
  1. 22
      src/Perspex.Base/PriorityLevel.cs
  2. 3
      src/Perspex.Base/PriorityValue.cs
  3. 18
      tests/Perspex.Base.UnitTests/PriorityValueTests.cs

22
src/Perspex.Base/PriorityLevel.cs

@ -7,22 +7,6 @@ using System.Reactive.Disposables;
namespace Perspex
{
/// <summary>
/// Determines how the current binding is selected for a <see cref="PriorityLevel"/>.
/// </summary>
internal enum LevelPrecedenceMode
{
/// <summary>
/// The latest fired binding is used as the current value.
/// </summary>
Latest,
/// <summary>
/// The latest added binding is used as the current value.
/// </summary>
Newest,
}
/// <summary>
/// Stores bindings for a priority level in a <see cref="PriorityValue"/>.
/// </summary>
@ -62,8 +46,6 @@ namespace Perspex
/// </summary>
private int _nextIndex;
private readonly LevelPrecedenceMode _mode;
/// <summary>
/// Initializes a new instance of the <see cref="PriorityLevel"/> class.
/// </summary>
@ -72,12 +54,10 @@ namespace Perspex
/// <param name="changed">A method to be called when the current value changes.</param>
public PriorityLevel(
int priority,
LevelPrecedenceMode mode,
Action<PriorityLevel> changed)
{
Contract.Requires<ArgumentNullException>(changed != null);
_mode = mode;
_changed = changed;
Priority = priority;
Value = _directValue = PerspexProperty.UnsetValue;
@ -155,7 +135,7 @@ namespace Perspex
/// <param name="entry">The entry that changed.</param>
private void Changed(PriorityBindingEntry entry)
{
if (_mode == LevelPrecedenceMode.Latest || entry.Index >= ActiveBindingIndex)
if (entry.Index >= ActiveBindingIndex)
{
if (entry.Value != PerspexProperty.UnsetValue)
{

3
src/Perspex.Base/PriorityValue.cs

@ -209,8 +209,7 @@ namespace Perspex
if (!_levels.TryGetValue(priority, out result))
{
var mode = (LevelPrecedenceMode)(priority % 2);
result = new PriorityLevel(priority, mode, ValueChanged);
result = new PriorityLevel(priority, ValueChanged);
_levels.Add(priority, result);
}

18
tests/Perspex.Base.UnitTests/PriorityValueTests.cs

@ -67,23 +67,7 @@ namespace Perspex.Base.UnitTests
}
[Fact]
public void Earlier_Binding_Firing_Should_Override_Later_Priority_0()
{
var target = new PriorityValue(null, "Test", typeof(string));
var nonActive = new BehaviorSubject<object>("na");
var source = new BehaviorSubject<object>("initial");
target.Add(nonActive, 0);
target.Add(source, 0);
Assert.Equal("initial", target.Value);
target.SetValue("first", 0);
Assert.Equal("first", target.Value);
nonActive.OnNext("second");
Assert.Equal("second", target.Value);
}
[Fact]
public void Earlier_Binding_Firing_Should_Not_Override_Later_Priority_1()
public void Earlier_Binding_Firing_Should_Not_Override_Later()
{
var target = new PriorityValue(null, "Test", typeof(string));
var nonActive = new BehaviorSubject<object>("na");

Loading…
Cancel
Save