GithubHelp home page GithubHelp logo

Comments (8)

erik-kallen avatar erik-kallen commented on June 3, 2024

The problem is that the plain Dictionary cannot implement interfaces, because doing so would require extension of Object.prototype which is quite intrusive (and the IDictionary.TryGetValue member cannot be reasonably implemented even if we accept an extension of Object.prototype).

In S# (I think), the IDictionary interface isn't possible to implement in a working fasion due to these issues.

As a replacement for the S# Dictionary(params object[]) constructor, use JsDictionary.GetDictionary(new { param1 = "value1", param2 = 10 }).

I am not too happy about introducing compiler support for the mentioned constructor, as it would require quite a lot of code for this single feature (a new ConstructorScriptSemantics.ImplType, with handling of that, tests, and also the metadata importer). However, your idea of an mscorlib helper method is not bad, neither too much work.

from saltarellecompiler.

volkanceylan avatar volkanceylan commented on June 3, 2024

So, is it ok to add a new constructor to JsDictionary like

[InlineCode("ss.setDictionaryInitialValues({initialValues})]
public JsDictionary(params object[] initialValues)
{
}

One could use this InlineCode with his own imported objects.

I'll work on it if you'll agree.

from saltarellecompiler.

erik-kallen avatar erik-kallen commented on June 3, 2024

Yes, I think that is a good idea (but perhaps with a shorter method name).

I haven't worked with S# in a while, why would one want to use that on his own imported objects? Does S# support adding a constructor with this signature to any object and it will be treated as an object initializer?

from saltarellecompiler.

erik-kallen avatar erik-kallen commented on June 3, 2024

Actually, we could add an if in the ScriptSharpMetadataImporter to apply this InlineCodeAttribute automatically for any .ctor(params object[] args) constructor in an [Imported] type.

from saltarellecompiler.

volkanceylan avatar volkanceylan commented on June 3, 2024

Yes it did and initial jquery plugin templates for ScriptSharp had such constructors for plugin Option objects.

It is even still used in current jQuery.UI implementation of S#

Example:

https://github.com/nikhilk/scriptsharp/blob/master/src/Libraries/jQuery/jQuery.UI/PositionOptions.cs

So this constructor type is not only for Dictionary, but all imported objects.

from saltarellecompiler.

volkanceylan avatar volkanceylan commented on June 3, 2024

Don't take me wrong, i think Saltarelle works great, and such incompabilities is do to some missing/incosistent parts in S#'s side. But, if you care about adoptation rate, porting an existing code from S# should require minimum changes. As, not all users will be as insistent as me. Most will try your compiler, get some errors, think it doesn't work like it should, and move on.

from saltarellecompiler.

erik-kallen avatar erik-kallen commented on June 3, 2024

I agree with you on that, and I think your idea with an mscorlib helper will solve this issue for us (as I said, we can auto-apply this attribute in the metadata importer). I just didn't come up with the idea myself.

from saltarellecompiler.

erik-kallen avatar erik-kallen commented on June 3, 2024

params object[] constructors are implemented and will be supported in 1.2.1

from saltarellecompiler.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.