Add Cascading flag to Parameter (#1564)

... so that components that pass through an arbitrary set of parameters can choose to filter out cascading ones if they want.
This commit is contained in:
Steve Sanderson 2018-10-18 09:37:46 +01:00 committed by GitHub
parent dd807a6d70
commit 4a6f471d12
3 changed files with 19 additions and 11 deletions

View File

@ -19,10 +19,17 @@ namespace Microsoft.AspNetCore.Blazor.Components
/// </summary> /// </summary>
public object Value { get; } public object Value { get; }
internal Parameter(string name, object value) /// <summary>
/// Gets a value to indicate whether the parameter is cascading, meaning that it
/// was supplied by a <see cref="CascadingValue{T}"/>.
/// </summary>
public bool Cascading { get; }
internal Parameter(string name, object value, bool cascading)
{ {
Name = name; Name = name;
Value = value; Value = value;
Cascading = cascading;
} }
} }
} }

View File

@ -89,7 +89,7 @@ namespace Microsoft.AspNetCore.Blazor.Components
_currentIndex = nextIndex; _currentIndex = nextIndex;
ref var frame = ref _frames[_currentIndex]; ref var frame = ref _frames[_currentIndex];
_current = new Parameter(frame.AttributeName, frame.AttributeValue); _current = new Parameter(frame.AttributeName, frame.AttributeValue, false);
return true; return true;
} }
@ -124,7 +124,7 @@ namespace Microsoft.AspNetCore.Blazor.Components
_currentIndex = nextIndex; _currentIndex = nextIndex;
var state = _cascadingParameters[_currentIndex]; var state = _cascadingParameters[_currentIndex];
_current = new Parameter(state.LocalValueName, state.ValueSupplier.CurrentValue); _current = new Parameter(state.LocalValueName, state.ValueSupplier.CurrentValue, true);
return true; return true;
} }
else else

View File

@ -60,8 +60,8 @@ namespace Microsoft.AspNetCore.Blazor.Test
// Assert // Assert
Assert.Collection(ToEnumerable(parameterCollection), Assert.Collection(ToEnumerable(parameterCollection),
AssertParameter("attribute 1", attribute1Value), AssertParameter("attribute 1", attribute1Value, false),
AssertParameter("attribute 2", attribute2Value)); AssertParameter("attribute 2", attribute2Value, false));
} }
[Fact] [Fact]
@ -82,8 +82,8 @@ namespace Microsoft.AspNetCore.Blazor.Test
// Assert // Assert
Assert.Collection(ToEnumerable(parameterCollection), Assert.Collection(ToEnumerable(parameterCollection),
AssertParameter("attribute 1", attribute1Value), AssertParameter("attribute 1", attribute1Value, false),
AssertParameter("attribute 2", attribute2Value)); AssertParameter("attribute 2", attribute2Value, false));
} }
[Fact] [Fact]
@ -105,9 +105,9 @@ namespace Microsoft.AspNetCore.Blazor.Test
// Assert // Assert
Assert.Collection(ToEnumerable(parameterCollection), Assert.Collection(ToEnumerable(parameterCollection),
AssertParameter("attribute 1", attribute1Value), AssertParameter("attribute 1", attribute1Value, false),
AssertParameter("attribute 2", attribute2Value), AssertParameter("attribute 2", attribute2Value, true),
AssertParameter("attribute 3", attribute3Value)); AssertParameter("attribute 3", attribute3Value, true));
} }
[Fact] [Fact]
@ -291,12 +291,13 @@ namespace Microsoft.AspNetCore.Blazor.Test
Assert.Same(myEntryValue, result); Assert.Same(myEntryValue, result);
} }
private Action<Parameter> AssertParameter(string expectedName, object expectedValue) private Action<Parameter> AssertParameter(string expectedName, object expectedValue, bool expectedIsCascading)
{ {
return parameter => return parameter =>
{ {
Assert.Equal(expectedName, parameter.Name); Assert.Equal(expectedName, parameter.Name);
Assert.Same(expectedValue, parameter.Value); Assert.Same(expectedValue, parameter.Value);
Assert.Equal(expectedIsCascading, parameter.Cascading);
}; };
} }