-
Notifications
You must be signed in to change notification settings - Fork 242
Interactions between JS objects and 'dynamic' #531
Comments
I'm not sure, if we really need support clear JS interop (current implementation) through dynamic.
We may add operation overload to this list. At the same time, it is good idea to preserve working with JS through dynamic - but it will be details of Microsoft.CSharp.RuntimeBinder.Binder (and same binders for other languages) on JS side. |
Being able to use a DOM or JS API like this: It may be necessary, though. :-( |
Thinking about this a bit more, we could probably lean on the same tricks packed arrays use. You can annotate a given That'd probably cover most of these use cases, and then if necessary we can provide a DLR binder that does the rest. |
It is only my opinion, but I really see no difference with code that you pointed on:
And code, that will use JsObject API:
|
The latter is more verbose and means you can't easily refactor by replacing C# methods with JS methods, etc. It's gross. The 'dynamic' thing also means that if a user wants static type information they can add it incrementally by replacing a given value with a statically typed one (then all the methods show up, etc). With the GL.Call thing, you'd again have to jump through a ton of hoops - you have to go through and find all the .Calls and replace them with appropriate uses of your static methods, and maybe those static methods have to do Call under the hood, and it's just a mess. If for some reason we can't make anything else work other than GL.Call etc, well then I guess that's that. But it's pretty terrible :-) |
I can argue with you about refactoring, that you can introduce const sting with name of Js field, so you still be able to rename it easy - on other hand, you never can't easy refactor dynamic code. Yes, it is a little bit more verbose. On other hand, if it will be introduced, as you suggested, new attribute, with syntax similar to |
And with any decision about dynamic support, @kg, what do you think about introducing JsObject? I've thought about it already when I've written some JS API wrappers :) |
I'd be fine with introducing that. |
In fact, file a bug about it. Ideally we can introduce a robust JsObject api, and then the 'dynamic' support for JS objects can be a transform that generates JsObject interactions for you. That way there aren't any behavioral differences between the two approaches, it's just a code simplicity thing. |
I wonder if it would be possible to leverage the definitely typed typescript type definitions to elimitate the busy work? e.g. https://github.com/borisyankov/DefinitelyTyped/blob/master/jquery/jquery.d.ts It would be a simple matter of creating a typescript to IL compiler... :-) |
It's a shame F# type providers aren't available in C#, because you could totally do that with those... |
Really I also thought about creating some utility that will generate statically-typed wrappers for JS-objects from ".d.ts". Also it would be great if we will be able generate ".d.ts" from translated .Net source, as it will greatly improve integration scenarios. |
The new emitter infrastructure ilwasm uses could probably be adapted to generate .d.ts files, worth thinking about. I don't know TypeScript very well. |
Is there any update on this discussion or any new advice? Otherwise I'm about to start building my own statically-typed bindings for jQuery! |
@Bablakeluke planned to start implementation of #532. Right now there is no more news/advices. Looks like nobody plan to work on static wrapper based on .d.ts right now. |
Right now
dynamic
is a back door that essentially lets you use JS objects directly. If we implement proper DLR support, that means this back door goes away and becomes a pain to use JS objects.In theory we could make DLR machinery properly interact with JS objects, but the generated code will still be riddled with callsite objects and such. Ideally we want a way to preserve the codegen for existing uses of
dynamic
on JS objects while still handling all the appropriate DLR use cases.I'm not sure how to balance these two objectives. Opt-in/opt-out for full DLR support or for JS object support, so that the code generator knows what kind of JS to generate? Some sort of per-value annotation like packed structs, where a 'dynamic'/'object' value is tagged as being a 'JS Object' and any operations on it bypass the DLR? Not really sure. Thoughts and suggestions appreciated.
The text was updated successfully, but these errors were encountered: