Description
This probably falls under runtime but I think it is relevant to the Web framework.
There is a project in the Mono repository for generating bindings to the DOM API through JavaScript interop.
The plan/idea is to generate the C# code bindings from TypeScript. But it seems like the effort is on hold.
See: mono/mono#10775
However: I see an opportunity in combining that effort with Blazor, enabling developers to use these classes directly from Razor. (Just for Blazor Web, of course)
Instead of an ElementReference
you could cast a random HTML element into its corresponding class to perform stuff you otherwise would need manually write JavaScript (if there is not a third-party library for that)
We need this functionality in order to build powerful web apps with just C#.
I have not thought about the server-side scenario, but I guess that you could trigger JavaScript in the browser similar to today.
<canvas @ref="myCanvas" height="200" width="200" />
@code
{
Canvas myCanvas;
Canvas2DContext context;
protected async Task OnAfterRenderAsync(bool firstRender)
{
if(!firstRender)
{
if(context == null)
{
context = await myCanvas.GetContextAsync("2d");
}
var image = new Img();
image.Href = "/foo.png";
await context.DrawImageAsync(image, 25, 25);
}
}
}