question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

DOM API Bindings and Blazor support

See original GitHub issue

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: 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:open
  • Created 3 years ago
  • Reactions:22
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

10reactions
IvanJosipoviccommented, Mar 16, 2021

@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

4reactions
msftbot[bot]commented, Nov 2, 2021

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

ASP.NET Core Blazor data binding
Learn about data binding features for Razor components and DOM ... Components support two-way data binding by defining a pair of parameters:.
Read more >
ASP.NET Core Blazor
The Blazor WebAssembly runtime uses JavaScript interop to handle Document Object Model (DOM) manipulation and browser API calls. The size of the ...
Read more >
Mastering Blazor - Part 1: DOM Integration
Blazor adds component-first support to ASP.NET by introducing "Razor components". With Razor components Blazor is capable of providing a ...
Read more >
Blazor WASM with REST API - Step by Step
This app will then connect to the webAPI to fetch and manipulate data. Now lets create our first blazor application and its supporting...
Read more >
Blazor Hybrid Web Apps with .NET MAUI
NET API support for service workers, all functionalities must be done in JavaScript. ... 's DOM are handled by the Blazor framework though...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found