dotnet / dotnet/aspnetcore

add source generator for creating/binding to events of a IJSInProcessObjectReference/IJSObjectReference

Open
#68,094 1 comment 1 reaction 0 assignees View on GitHub
area-blazor
Dominant language
C#
Stars
38.4k
Forks
10.9k
Avg merge
2d 10h
Merged PRs (30d)
281

Description

### Is there an existing issue for this?

- [x] I have searched the existing issues

### Is your feature request related to a problem? Please describe the problem.

I would like to listen to events of a IJSInProcessObjectReference/IJSObjectReference without the need for handcrafting or managing the registration of the javascript EventListener and/or callback.

### Describe the solution you'd like

a source generator that allows the creation and/management of event listeners and dotnet callbacks that hook into .NET EventHandler

```
public event EventHandle EventName;

IJSInProcessRuntime _runtime;
IJSInProcessObjectReference _instanceHandle = _runtime.InvokeConstructor("objectType", ...);

// source generator would detect and generate the c# and javascript interop to create,
// manage and release the _instanceHandle (EventTarget) EventListener including the disposing.
_instanceHandle.Bind("event-name", EventName);
```

### Additional context

It seem logic to have this added to the blazor interop functionality to make use of the same event listern management/tracking system that is used by blazor for components and html elements and given the base javascript EventTarget class is used for both html and non-html element and to provide the event listern bindings/release/dispatch.

Contributor guide

Open the contributing guide

Research direction

Start by reviewing Blazor's existing event listener management and tracking for components and HTML elements, then compare it with IJSInProcessObjectReference and IJSObjectReference usage. Define the source generator's scope for creating, binding, tracking, dispatching, and disposing event listeners and .NET callbacks; the issue names no files or tests.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp, javascript
Domain
frontend, web-dev
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Quiet
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.