DOM API Bindings and Blazor support
See original GitHub issueThis 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: https://github.com/mono/mono/issues/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);
}
}
}
Issue Analytics
- State:
- Created 3 years ago
- Reactions:22
- Comments:7 (3 by maintainers)
@SteveSandersonMS, I’m not sure how this task was categorized as “affected-few”. This issue literally affects every single Blazor user. Having these capabilities will avoid us having to use tones of JS wrapper NuGet libraries.
Other languages already have this in the works: https://rustwasm.github.io/wasm-bindgen/examples/dom.html https://github.com/golang/go/wiki/WebAssembly#interacting-with-the-dom
We’ve moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our Triage Process.