Ignitor fixups (#21198)

* Ignitor fixups

* Do not throw if an ElementReferenceCapture node is encountered.
* Allow configuring the HubConnectionBuilder
* Make useful API public
This commit is contained in:
Pranav K 2020-04-27 13:27:11 -07:00 committed by GitHub
parent b73b2027cc
commit 9cecd089e4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 5 deletions

View File

@ -333,11 +333,12 @@ namespace Ignitor
return null; return null;
} }
public async Task<bool> ConnectAsync(Uri uri, bool connectAutomatically = true) public async Task<bool> ConnectAsync(Uri uri, bool connectAutomatically = true, Action<HubConnectionBuilder, Uri>? configure = null)
{ {
var builder = new HubConnectionBuilder(); var builder = new HubConnectionBuilder();
builder.Services.TryAddEnumerable(ServiceDescriptor.Singleton<IHubProtocol, IgnitorMessagePackHubProtocol>()); builder.Services.TryAddEnumerable(ServiceDescriptor.Singleton<IHubProtocol, IgnitorMessagePackHubProtocol>());
builder.WithUrl(GetHubUrl(uri)); var hubUrl = GetHubUrl(uri);
builder.WithUrl(hubUrl);
builder.ConfigureLogging(l => builder.ConfigureLogging(l =>
{ {
l.SetMinimumLevel(LogLevel.Trace); l.SetMinimumLevel(LogLevel.Trace);
@ -347,6 +348,8 @@ namespace Ignitor
} }
}); });
configure?.Invoke(builder, hubUrl);
_hubConnection = builder.Build(); _hubConnection = builder.Build();
HubConnection.On<int, string>("JS.AttachComponent", OnAttachComponent); HubConnection.On<int, string>("JS.AttachComponent", OnAttachComponent);

View File

@ -264,8 +264,14 @@ namespace Ignitor
case RenderTreeFrameType.ElementReferenceCapture: case RenderTreeFrameType.ElementReferenceCapture:
{ {
// No action for reference captures. if (parent is ElementNode)
break; {
return 0; // A "capture" is a child in the diff, but has no node in the DOM
}
else
{
throw new Exception("Reference capture frames can only be children of element frames.");
}
} }
case RenderTreeFrameType.Markup: case RenderTreeFrameType.Markup:

View File

@ -88,7 +88,7 @@ namespace Ignitor
return DispatchEventCore(connection, Serialize(webEventDescriptor), Serialize(args)); return DispatchEventCore(connection, Serialize(webEventDescriptor), Serialize(args));
} }
internal Task ClickAsync(HubConnection connection) public Task ClickAsync(HubConnection connection)
{ {
if (!Events.TryGetValue("click", out var clickEventDescriptor)) if (!Events.TryGetValue("click", out var clickEventDescriptor))
{ {