Skip to content

Commit

Permalink
Update cascading values with IsFixed="true" (#310)
Browse files Browse the repository at this point in the history
* Cascading values optimized per Steve Sanderson's suggestion

See dotnet/aspnetcore#26230

* Further change
  • Loading branch information
simonziegler authored Oct 25, 2020
1 parent 7de7863 commit e6c51fe
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 13 deletions.
2 changes: 1 addition & 1 deletion Material.Blazor/Components/Card/MBCard.razor
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
@inherits ComponentFoundation


<CascadingValue Value="@this">
<CascadingValue Value="@this" IsFixed="true">
<div @attributes="@AttributesToSplat(SplatType.ExcludeEvents)">

@if (Primary != null)
Expand Down
2 changes: 1 addition & 1 deletion Material.Blazor/Components/Dialog/MBDialog.razor
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
@attributes="@MyAttributes"
aria-modal="true">

<CascadingValue Value="@this">
<CascadingValue Value="@this" IsFixed="true">
<div class="mdc-dialog__container">
<div class="mdc-dialog__surface @OverflowClass">
@if (HasTitle)
Expand Down
2 changes: 1 addition & 1 deletion Material.Blazor/Components/Drawer/MBDrawer.razor
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
@attributes="@AttributesToSplat()">

<div class="mdc-drawer__content">
<CascadingValue Value="@this">
<CascadingValue Value="@this" IsFixed="true">
@if (ChildContent != null)
{
@ChildContent
Expand Down
2 changes: 1 addition & 1 deletion Material.Blazor/Components/TabBar/MBTabBar.razor
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
<span class="mdc-tab__content">
@if (Icon != null)
{
<CascadingValue Value="@tabBarIdentifierObject" Name="@TabBarIdentifier">
<CascadingValue Value="@tabBarIdentifierObject" Name="@TabBarIdentifier" IsFixed="true">
@Icon(item)
</CascadingValue>
}
Expand Down
20 changes: 11 additions & 9 deletions Material.Blazor/Foundation/InputComponentFoundation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,13 +101,13 @@ private protected T ComponentValue
get => _componentValue;
set
{
#if Logging
Logger.LogDebug("ComponentValue setter entered");
#if LoggingVerbose
Logger.LogDebug($"ComponentValue setter entered: _componentValue is '{_cachedValue?.ToString() ?? "null"}' and new value is'{value?.ToString() ?? "null"}'");
#endif
if (!EqualityComparer<T>.Default.Equals(value, _componentValue))
{
#if Logging
Logger.LogDebug("ComponentValue setter changing value to '" + value?.ToString() ?? "null" + "'");
Logger.LogDebug($"ComponentValue setter changed _componentValue");
#endif
_componentValue = value;
_ = ValueChanged.InvokeAsync(value);
Expand Down Expand Up @@ -280,7 +280,7 @@ public override async Task SetParametersAsync(ParameterView parameters)
_nullableUnderlyingType = Nullable.GetUnderlyingType(typeof(T));
_hasSetInitialParameters = true;
#if Logging
Logger.LogDebug("SetParametersAsync setting ComponentValue value to '" + Value?.ToString() ?? "null" + "'");
Logger.LogDebug($"SetParametersAsync setting ComponentValue value to '{Value?.ToString() ?? "null"}'");
#endif
_cachedValue = Value;
_componentValue = Value;
Expand All @@ -292,8 +292,7 @@ public override async Task SetParametersAsync(ParameterView parameters)
// We don't support changing EditContext because it's messy to be clearing up state and event
// handlers for the previous one, and there's no strong use case. If a strong use case
// emerges, we can consider changing this.
throw new InvalidOperationException($"{GetType()} does not support changing the " +
$"{nameof(EditContext)} dynamically.");
throw new InvalidOperationException($"{GetType()} does not support changing the {nameof(EditContext)} dynamically.");
}

// For derived components, retain the usual lifecycle with OnInit/OnParametersSet/etc.
Expand All @@ -318,16 +317,19 @@ protected override async Task OnParametersSetAsync()

private void CommonParametersSet()
{
#if LoggingVerbose
Logger.LogDebug($"OnParametersSet setter entered: _cachedValue is '{_cachedValue?.ToString() ?? "null"}' and Value is'{Value?.ToString() ?? "null"}'");
#endif
if (!EqualityComparer<T>.Default.Equals(_cachedValue, Value))
{
_cachedValue = Value;
#if Logging
Logger.LogDebug("OnParametersSet setting CachedValue value to '" + Value?.ToString() ?? "null" + "'");
Logger.LogDebug($"OnParametersSet changed _cachedValue value");
#endif
if (!EqualityComparer<T>.Default.Equals(ComponentValue, Value))
if (!EqualityComparer<T>.Default.Equals(_componentValue, Value))
{
#if Logging
Logger.LogDebug("OnParametersSet setting ComponentValue value to '" + Value?.ToString() ?? "null" + "'");
Logger.LogDebug("OnParametersSet update _componentValue value from '" + _componentValue?.ToString() ?? "null" + "'");
#endif
_componentValue = Value;
if (_hasInstantiated)
Expand Down
5 changes: 5 additions & 0 deletions Material.Blazor/Material.Blazor.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

<PropertyGroup Condition="'$(Configuration)'=='Debug'">
<DefineConstants>Logging</DefineConstants>
<!--<DefineConstants>Logging;LoggingVerbose</DefineConstants>-->
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)'=='Release'">
Expand All @@ -33,6 +34,10 @@
<PropertyGroup>
<DisableFastUpToDateCheck>true</DisableFastUpToDateCheck>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<WarningLevel>5</WarningLevel>
</PropertyGroup>

<ItemGroup>
<Content Remove="package-lock.json" />
Expand Down

0 comments on commit e6c51fe

Please sign in to comment.