For bind on element, also write the updated attribute name to the render tree builder (dotnet/aspnetcore-tooling#689)

\n\nCommit migrated from 6e5490049d
This commit is contained in:
Steve Sanderson 2019-06-20 09:54:06 +02:00 committed by GitHub
parent 060ff0d878
commit 64f56b7607
29 changed files with 43 additions and 12 deletions

View File

@ -369,6 +369,8 @@ namespace Microsoft.AspNetCore.Razor.Language.Components
Prefix = changeAttributeName + "=\"", Prefix = changeAttributeName + "=\"",
Suffix = "\"", Suffix = "\"",
EventUpdatesAttributeName = valueNode.AttributeName,
}; };
changeNode.Children.Add(new CSharpExpressionAttributeValueIntermediateNode()); changeNode.Children.Add(new CSharpExpressionAttributeValueIntermediateNode());

View File

@ -228,6 +228,14 @@ namespace Microsoft.AspNetCore.Razor.Language.Components
WriteAttribute(context, node.AttributeName, _currentAttributeValues); WriteAttribute(context, node.AttributeName, _currentAttributeValues);
_currentAttributeValues.Clear(); _currentAttributeValues.Clear();
if (!string.IsNullOrEmpty(node.EventUpdatesAttributeName))
{
context.CodeWriter
.WriteStartMethodInvocation($"{_scopeStack.BuilderVarName}.{ComponentsApi.RenderTreeBuilder.SetUpdatesAttributeName}")
.WriteStringLiteral(node.EventUpdatesAttributeName)
.WriteEndMethodInvocation();
}
} }
public override void WriteHtmlAttributeValue(CodeRenderingContext context, HtmlAttributeValueIntermediateNode node) public override void WriteHtmlAttributeValue(CodeRenderingContext context, HtmlAttributeValueIntermediateNode node)

View File

@ -89,6 +89,8 @@ namespace Microsoft.AspNetCore.Razor.Language.Components
public static readonly string ChildContent = nameof(ChildContent); public static readonly string ChildContent = nameof(ChildContent);
public static readonly string SetKey = nameof(SetKey); public static readonly string SetKey = nameof(SetKey);
public static readonly string SetUpdatesAttributeName = nameof(SetUpdatesAttributeName);
} }
public static class RuntimeHelpers public static class RuntimeHelpers

View File

@ -15,6 +15,8 @@ namespace Microsoft.AspNetCore.Razor.Language.Intermediate
public string Suffix { get; set; } public string Suffix { get; set; }
public string EventUpdatesAttributeName { get; set; }
public override void Accept(IntermediateNodeVisitor visitor) public override void Accept(IntermediateNodeVisitor visitor)
{ {
if (visitor == null) if (visitor == null)
@ -32,6 +34,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Intermediate
formatter.WriteProperty(nameof(AttributeName), AttributeName); formatter.WriteProperty(nameof(AttributeName), AttributeName);
formatter.WriteProperty(nameof(Prefix), Prefix); formatter.WriteProperty(nameof(Prefix), Prefix);
formatter.WriteProperty(nameof(Suffix), Suffix); formatter.WriteProperty(nameof(Suffix), Suffix);
formatter.WriteProperty(nameof(EventUpdatesAttributeName), EventUpdatesAttributeName);
} }
} }
} }

View File

@ -25,6 +25,7 @@ namespace Test
#nullable disable #nullable disable
, "MM/dd")); , "MM/dd"));
builder.AddAttribute(3, "onchange", Microsoft.AspNetCore.Components.EventCallback.Factory.CreateBinder(this, __value => CurrentDate = __value, CurrentDate, "MM/dd")); builder.AddAttribute(3, "onchange", Microsoft.AspNetCore.Components.EventCallback.Factory.CreateBinder(this, __value => CurrentDate = __value, CurrentDate, "MM/dd"));
builder.SetUpdatesAttributeName("value");
builder.CloseElement(); builder.CloseElement();
} }
#pragma warning restore 1998 #pragma warning restore 1998

View File

@ -2,7 +2,7 @@ Source Location: (113:1,7 [77] x:\dir\subdir\Test\TestComponent.cshtml)
| |
public DateTime CurrentDate { get; set; } = new DateTime(2018, 1, 1); public DateTime CurrentDate { get; set; } = new DateTime(2018, 1, 1);
| |
Generated Location: (1240:32,7 [77] ) Generated Location: (1295:33,7 [77] )
| |
public DateTime CurrentDate { get; set; } = new DateTime(2018, 1, 1); public DateTime CurrentDate { get; set; } = new DateTime(2018, 1, 1);
| |

View File

@ -25,6 +25,7 @@ namespace Test
#nullable disable #nullable disable
)); ));
builder.AddAttribute(3, "onchange", Microsoft.AspNetCore.Components.EventCallback.Factory.CreateBinder(this, __value => ParentValue = __value, ParentValue)); builder.AddAttribute(3, "onchange", Microsoft.AspNetCore.Components.EventCallback.Factory.CreateBinder(this, __value => ParentValue = __value, ParentValue));
builder.SetUpdatesAttributeName("value");
builder.CloseElement(); builder.CloseElement();
} }
#pragma warning restore 1998 #pragma warning restore 1998

View File

@ -2,7 +2,7 @@ Source Location: (86:1,7 [50] x:\dir\subdir\Test\TestComponent.cshtml)
| |
public int ParentValue { get; set; } = 42; public int ParentValue { get; set; } = 42;
| |
Generated Location: (1222:32,7 [50] ) Generated Location: (1277:33,7 [50] )
| |
public int ParentValue { get; set; } = 42; public int ParentValue { get; set; } = 42;
| |

View File

@ -24,6 +24,7 @@ namespace Test
#nullable disable #nullable disable
)); ));
builder.AddAttribute(2, "myevent", Microsoft.AspNetCore.Components.EventCallback.Factory.CreateBinder(this, __value => ParentValue = __value, ParentValue)); builder.AddAttribute(2, "myevent", Microsoft.AspNetCore.Components.EventCallback.Factory.CreateBinder(this, __value => ParentValue = __value, ParentValue));
builder.SetUpdatesAttributeName("myvalue");
builder.CloseElement(); builder.CloseElement();
} }
#pragma warning restore 1998 #pragma warning restore 1998

View File

@ -2,7 +2,7 @@ Source Location: (43:1,7 [55] x:\dir\subdir\Test\TestComponent.cshtml)
| |
public string ParentValue { get; set; } = "hi"; public string ParentValue { get; set; } = "hi";
| |
Generated Location: (1153:31,7 [55] ) Generated Location: (1210:32,7 [55] )
| |
public string ParentValue { get; set; } = "hi"; public string ParentValue { get; set; } = "hi";
| |

View File

@ -24,6 +24,7 @@ namespace Test
#nullable disable #nullable disable
)); ));
builder.AddAttribute(2, "myevent", Microsoft.AspNetCore.Components.EventCallback.Factory.CreateBinder(this, __value => ParentValue = __value, ParentValue)); builder.AddAttribute(2, "myevent", Microsoft.AspNetCore.Components.EventCallback.Factory.CreateBinder(this, __value => ParentValue = __value, ParentValue));
builder.SetUpdatesAttributeName("myvalue");
builder.CloseElement(); builder.CloseElement();
} }
#pragma warning restore 1998 #pragma warning restore 1998

View File

@ -2,7 +2,7 @@ Source Location: (42:1,7 [55] x:\dir\subdir\Test\TestComponent.cshtml)
| |
public string ParentValue { get; set; } = "hi"; public string ParentValue { get; set; } = "hi";
| |
Generated Location: (1152:31,7 [55] ) Generated Location: (1209:32,7 [55] )
| |
public string ParentValue { get; set; } = "hi"; public string ParentValue { get; set; } = "hi";
| |

View File

@ -24,6 +24,7 @@ namespace Test
#nullable disable #nullable disable
)); ));
builder.AddAttribute(2, "myevent", Microsoft.AspNetCore.Components.EventCallback.Factory.CreateBinder(this, __value => ParentValue = __value, ParentValue)); builder.AddAttribute(2, "myevent", Microsoft.AspNetCore.Components.EventCallback.Factory.CreateBinder(this, __value => ParentValue = __value, ParentValue));
builder.SetUpdatesAttributeName("myvalue");
builder.CloseElement(); builder.CloseElement();
} }
#pragma warning restore 1998 #pragma warning restore 1998

View File

@ -2,7 +2,7 @@ Source Location: (37:1,7 [55] x:\dir\subdir\Test\TestComponent.cshtml)
| |
public string ParentValue { get; set; } = "hi"; public string ParentValue { get; set; } = "hi";
| |
Generated Location: (1147:31,7 [55] ) Generated Location: (1204:32,7 [55] )
| |
public string ParentValue { get; set; } = "hi"; public string ParentValue { get; set; } = "hi";
| |

View File

@ -25,6 +25,7 @@ namespace Test
#nullable disable #nullable disable
)); ));
builder.AddAttribute(3, "onchange", Microsoft.AspNetCore.Components.EventCallback.Factory.CreateBinder(this, __value => Enabled = __value, Enabled)); builder.AddAttribute(3, "onchange", Microsoft.AspNetCore.Components.EventCallback.Factory.CreateBinder(this, __value => Enabled = __value, Enabled));
builder.SetUpdatesAttributeName("checked");
builder.CloseElement(); builder.CloseElement();
} }
#pragma warning restore 1998 #pragma warning restore 1998

View File

@ -2,7 +2,7 @@ Source Location: (51:1,7 [41] x:\dir\subdir\Test\TestComponent.cshtml)
| |
public bool Enabled { get; set; } public bool Enabled { get; set; }
| |
Generated Location: (1214:32,7 [41] ) Generated Location: (1271:33,7 [41] )
| |
public bool Enabled { get; set; } public bool Enabled { get; set; }
| |

View File

@ -33,6 +33,7 @@ namespace Test
#nullable disable #nullable disable
)); ));
builder.AddAttribute(3, "onchange", Microsoft.AspNetCore.Components.EventCallback.Factory.CreateBinder(this, __value => CurrentDate = __value, CurrentDate, Format)); builder.AddAttribute(3, "onchange", Microsoft.AspNetCore.Components.EventCallback.Factory.CreateBinder(this, __value => CurrentDate = __value, CurrentDate, Format));
builder.SetUpdatesAttributeName("value");
builder.CloseElement(); builder.CloseElement();
} }
#pragma warning restore 1998 #pragma warning restore 1998

View File

@ -4,7 +4,7 @@ Source Location: (73:1,7 [135] x:\dir\subdir\Test\TestComponent.cshtml)
public string Format { get; set; } = "MM/dd/yyyy"; public string Format { get; set; } = "MM/dd/yyyy";
| |
Generated Location: (1423:40,7 [135] ) Generated Location: (1478:41,7 [135] )
| |
public DateTime CurrentDate { get; set; } = new DateTime(2018, 1, 1); public DateTime CurrentDate { get; set; } = new DateTime(2018, 1, 1);

View File

@ -25,6 +25,7 @@ namespace Test
#nullable disable #nullable disable
, "MM/dd/yyyy")); , "MM/dd/yyyy"));
builder.AddAttribute(3, "onchange", Microsoft.AspNetCore.Components.EventCallback.Factory.CreateBinder(this, __value => CurrentDate = __value, CurrentDate, "MM/dd/yyyy")); builder.AddAttribute(3, "onchange", Microsoft.AspNetCore.Components.EventCallback.Factory.CreateBinder(this, __value => CurrentDate = __value, CurrentDate, "MM/dd/yyyy"));
builder.SetUpdatesAttributeName("value");
builder.CloseElement(); builder.CloseElement();
} }
#pragma warning restore 1998 #pragma warning restore 1998

View File

@ -2,7 +2,7 @@ Source Location: (76:1,7 [77] x:\dir\subdir\Test\TestComponent.cshtml)
| |
public DateTime CurrentDate { get; set; } = new DateTime(2018, 1, 1); public DateTime CurrentDate { get; set; } = new DateTime(2018, 1, 1);
| |
Generated Location: (1244:32,7 [77] ) Generated Location: (1299:33,7 [77] )
| |
public DateTime CurrentDate { get; set; } = new DateTime(2018, 1, 1); public DateTime CurrentDate { get; set; } = new DateTime(2018, 1, 1);
| |

View File

@ -25,6 +25,7 @@ namespace Test
#nullable disable #nullable disable
)); ));
builder.AddAttribute(3, "onchange", Microsoft.AspNetCore.Components.EventCallback.Factory.CreateBinder(this, __value => ParentValue = __value, ParentValue)); builder.AddAttribute(3, "onchange", Microsoft.AspNetCore.Components.EventCallback.Factory.CreateBinder(this, __value => ParentValue = __value, ParentValue));
builder.SetUpdatesAttributeName("value");
builder.CloseElement(); builder.CloseElement();
} }
#pragma warning restore 1998 #pragma warning restore 1998

View File

@ -2,7 +2,7 @@ Source Location: (51:1,7 [50] x:\dir\subdir\Test\TestComponent.cshtml)
| |
public int ParentValue { get; set; } = 42; public int ParentValue { get; set; } = 42;
| |
Generated Location: (1216:32,7 [50] ) Generated Location: (1271:33,7 [50] )
| |
public int ParentValue { get; set; } = 42; public int ParentValue { get; set; } = 42;
| |

View File

@ -24,6 +24,7 @@ namespace Test
#nullable disable #nullable disable
)); ));
builder.AddAttribute(2, "onchange", Microsoft.AspNetCore.Components.EventCallback.Factory.CreateBinder(this, __value => ParentValue = __value, ParentValue)); builder.AddAttribute(2, "onchange", Microsoft.AspNetCore.Components.EventCallback.Factory.CreateBinder(this, __value => ParentValue = __value, ParentValue));
builder.SetUpdatesAttributeName("value");
builder.CloseElement(); builder.CloseElement();
} }
#pragma warning restore 1998 #pragma warning restore 1998

View File

@ -2,7 +2,7 @@ Source Location: (39:1,7 [50] x:\dir\subdir\Test\TestComponent.cshtml)
| |
public int ParentValue { get; set; } = 42; public int ParentValue { get; set; } = 42;
| |
Generated Location: (1150:31,7 [50] ) Generated Location: (1205:32,7 [50] )
| |
public int ParentValue { get; set; } = 42; public int ParentValue { get; set; } = 42;
| |

View File

@ -36,6 +36,7 @@ namespace Test
#nullable disable #nullable disable
)); ));
builder.AddAttribute(6, "oninput", Microsoft.AspNetCore.Components.EventCallback.Factory.CreateBinder(this, __value => text = __value, text)); builder.AddAttribute(6, "oninput", Microsoft.AspNetCore.Components.EventCallback.Factory.CreateBinder(this, __value => text = __value, text));
builder.SetUpdatesAttributeName("value");
builder.CloseElement(); builder.CloseElement();
builder.AddMarkupContent(7, "\r\n"); builder.AddMarkupContent(7, "\r\n");
builder.CloseElement(); builder.CloseElement();

View File

@ -2,7 +2,7 @@ Source Location: (129:3,12 [35] x:\dir\subdir\Test\TestComponent.cshtml)
| |
private string text = "hi"; private string text = "hi";
| |
Generated Location: (1785:45,12 [35] ) Generated Location: (1840:46,12 [35] )
| |
private string text = "hi"; private string text = "hi";
| |

View File

@ -28,6 +28,7 @@ namespace Test
#nullable disable #nullable disable
)); ));
builder.AddAttribute(6, "onchange", Microsoft.AspNetCore.Components.EventCallback.Factory.CreateBinder(this, __value => text = __value, text)); builder.AddAttribute(6, "onchange", Microsoft.AspNetCore.Components.EventCallback.Factory.CreateBinder(this, __value => text = __value, text));
builder.SetUpdatesAttributeName("value");
builder.CloseElement(); builder.CloseElement();
builder.AddMarkupContent(7, "\r\n"); builder.AddMarkupContent(7, "\r\n");
builder.CloseElement(); builder.CloseElement();

View File

@ -2,7 +2,7 @@ Source Location: (83:3,12 [35] x:\dir\subdir\Test\TestComponent.cshtml)
| |
private string text = "hi"; private string text = "hi";
| |
Generated Location: (1449:37,12 [35] ) Generated Location: (1504:38,12 [35] )
| |
private string text = "hi"; private string text = "hi";
| |

View File

@ -107,5 +107,9 @@ namespace Microsoft.AspNetCore.Components.RenderTree
public void SetKey(object key) public void SetKey(object key)
{ {
} }
public void SetUpdatesAttributeName(string updatesAttributeName)
{
}
} }
} }