Aspnetcore: JavaScript Object Class

Created on 16 Oct 2019  路  5Comments  路  Source: dotnet/aspnetcore

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

I am trying to convert a project from Flash to Blazor, and so far - so good, and the things are looking pretty much very promising from the Client side.
Anyway so far a significant delay is caused by the complex structures which I have to maintenance while translating a complex object from C# class to JavaScript class ( enterprise class project ).
These translations which involving constant creating and destroying objects, especially in arrays or more complex structures quite often leads to significant delay while converting the C# structures into a string/json text and send them to be recreated in JavaScript and then injected where they belongs.

Describe the solution you'd like

I believe that if C# offer a class which output is object type which is 1:1 to the object type of JavaScript object instance and this could be directly injected from C# to JavaScript without all of these back and forward conversions they things would be much more accelerated.

P.S: Blazor related

area-blazor blazor-wasm question

All 5 comments

@YordanYanakiev Thanks for contacting us.

Have you considered using a DotNetObjectReference for this? https://docs.microsoft.com/en-us/aspnet/core/blazor/javascript-interop?view=aspnetcore-3.0#instance-method-call

Are you asking to be able to hold a reference to a JS object from the C# side or have some sort of mapping between C# objects and JS objects. This could be achieved with a graph of DotNetObjectReferences and a bit of work on the JS side

The whole point is not to have any kind of work from inside JS side.
My idea is to have a base class in C# which to create just objects with just the same properties, methods and events without need to modify JS code or make any work in there.
Something like creating JS class inside C#, and every instance of this class to be directly transferable and used from inside JS as it is.
( even going deeper - such object to share memory pool with the parent instance in C# - aka the JS object to be just a pointer to the C# created instance of the object )

Ok,

So if I understood correctly you want some sort of JS proxy for a C# object so that any library that needs something in the JS world, can use your "JS" proxy object to talk to the C# object directly. Am I understanding this correctly or is it the other way around? (You want a C# proxy to talk to a JS object directly)

( even going deeper - such object to share memory pool with the parent instance in C# - aka the JS object to be just a pointer to the C# created instance of the object )

This is not doable today in the wasm world as the JS GC and the .NET GC would have to cooperate for that. I believe there are some specs for this in the wasm world.

I see. Well, probably it is too early yet for this quite ambitious request..

I'm closing this as there's no further action for us to take here at the moment. We might revisit this in the future if things change in the web assembly space.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

bgribaudo picture bgribaudo  路  3Comments

rbanks54 picture rbanks54  路  3Comments

farhadibehnam picture farhadibehnam  路  3Comments

markrendle picture markrendle  路  3Comments

aurokk picture aurokk  路  3Comments