GithubHelp home page GithubHelp logo

Comments (4)

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

Obviously a bug here.

from saltarellecompiler.

rekna1 avatar rekna1 commented on June 3, 2024

Also, this mixin solution has a serious flaw in my opinion, but that's not the fault of saltarelle.
Suppose I want to create a plugin, which needs to accept some options (as many jquery plugins have)
The constructor will take the options as an argument, like
public static jQueryObject MyPlugin( MyPluginOptions options );

There is no way to access these options but from the static constructor... while many jquery plugins have additional methods that may or may not use/set properties from the option object.

This was already a problem I had in script# and I didn't get an good answer how to solve this.

eg. in jquery ui, dialog has a method to set options:
$("#myDialog").dialog( "option" , optionName , [value] )

Where do they store / retrieve the original MyPluginOptions that is passed to the constructor?

Should I model such a method as an overloaded static constructor ?

from saltarellecompiler.

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

First, I'm not sure whether I think it is actually a good idea to write jQuery plugins in Saltarelle (or Script#).

For your question, I guess what you'd do is something like

class MyPluginExtensions {
    [InstanceMethodOnFirstArgument]
    public static jQueryObject MyPlugin(this jQueryObject jq, MyPluginOptions opts) { return null; }

    [InlineCode("{this}.myPlugin('option', 'myOption', {value})")]
    public static jQueryObject MySetPluginOption(this jQueryObject jq, string value) { return null; }
}

[ScriptAlias("$.fn")]
public class MyPluginClass
    public static void MyPlugin(TypeOption<MyPluginOptions, string> opts) {
        if (Script.GetScriptType(opts) == "string" && (string)opts == "option") {
            string optionName = Arguments.GetArgument(1);
            object optionValue = Arguments.GetArgument(2);
            // Set the option
        }
        else {
            // Construct the plugin
        }
    }
}

from saltarellecompiler.

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

Fixed in 1.3.0

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.