Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose application configuration #139

Open
lptr opened this issue Sep 17, 2014 · 4 comments
Open

Expose application configuration #139

lptr opened this issue Sep 17, 2014 · 4 comments

Comments

@lptr
Copy link
Contributor

lptr commented Sep 17, 2014

Add it somehow to the generated application.js. Maybe this could be wrapped into a separate "module" (metadata? application?) that modules could require(). This way it could be introduced in a non-breaking way.

@lptr
Copy link
Contributor Author

lptr commented Sep 17, 2014

cc @barsimatyi

@lptr lptr changed the title Expose application version Expose application configuration Sep 17, 2014
@lptr
Copy link
Contributor Author

lptr commented Sep 17, 2014

So this is how it would work:

build.gradle:

task packageApp(type: PackageApplication) {
    parameters param1: "alma", param2: "bela"
}

application.js:

define("application-config", [], function() {
return {
    version: "1.0", // auto-generated from Gradle version
    param1: "alma",
    param2: "bela",
};
});
require(["<main-module>"], function(mainModule) { mainModule.main(); });

The module's JS:

define([..., "application-config"], function(..., applicationConfig) {
    // Weird Spaghetti wrapping that exposes applicationConfig as Spaghetti.getApplicationConfig()
    // ...
    ..., function(Spaghetti) {
        console.log("Config:", Spaghetti.getApplicationConfig());
    });
    // ...
});

Console output:

$ node application.js
Config: {
    version: "1.0",
    param1: "alma",
    param2: "bela",
}

@lptr
Copy link
Contributor Author

lptr commented Sep 17, 2014

Valid point from @gnagy: it's better to not have shared state like this, and only expose this configuration to main(). Here's how that changes the story:

application.js:

define("application-config", [], function() {
return {
    version: "1.0", // auto-generated from Gradle version
    param1: "alma",
    param2: "bela",
};
});
require(["<main-module>", "application-config"], function(mainModule, config) {
    var appConfig = someWrappingOfConfig(config);
    mainModule.main(config);
});

@lptr
Copy link
Contributor Author

lptr commented Sep 17, 2014

We'd need a SpaghettiParameters class to expose the properties via:

extern class SpaghettiParameters {
    function getParameter(name:String):Dynamic;
}

So an application module could declare its main method as such:

module com.example.test

void main(SpaghettiParameters params)

This would allow obfuscation-safe access to the parameters, too.

@lptr lptr added this to the 2.0 milestone Sep 17, 2014
lptr added a commit that referenced this issue Sep 17, 2014
@lptr lptr modified the milestones: 2.0, 2.1 Sep 30, 2014
@lptr lptr modified the milestones: 2.2, 2.1 Nov 6, 2014
@lptr lptr removed this from the 2.1 milestone Feb 5, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant