Config option for predefined modules #105

Open
gamtiq opened this Issue Jul 17, 2012 · 4 comments

Comments

Projects
None yet
2 participants

gamtiq commented Jul 17, 2012

Hello John,

It would be useful to have some configuration option that allows describing several predefined modules (i.e. named modules/objects that have created before curl loading).
So that instead of

...
<script>
    curl = {baseUrl: ...};
</script>
<script src="path/to/curl.js"></script>
<script>
    define("m1", obj1);
    define("m2", function() { return modDef; });
    define("m1/m2", obj1.obj2);
</script>
...

it could be possible to write something like the following

...
<script>
    curl = {
        predefined: {
            m1: obj1,
            m2: function() { return modDef; },
            "m1/m2": obj1.obj2
        },
        baseUrl: ...
    };
</script>
<script src="path/to/curl.js"></script>
...

Best regards,
Denis

Owner

unscriptable commented Jul 18, 2012

Interesting iea. Where do these modules come from? Can you help me understand some use cases?

This might work (depending on your use case):

<script src="path/to/curl.js"></script>
<script>
    curl({ baseUrl: '...', etc: '...' });
    define("m1", obj1);
    define("m2", function() { return modDef; });
    define("m1/m2", obj1.obj2);
</script>

unscriptable was assigned Jul 18, 2012

gamtiq commented Jul 18, 2012

John,

Actually your code is similar to my snippet 1.
I use curl along with my own framework. The framework’s loader loads some framework files before curl. Those files contain "plain js" (not AMD) organized by namespaces. As a result I have an objects hierarchy. Some objects from this hierarchy I would like to use as modules in an application for convenience purposes. To achieve this now I apply code that is alike to the snippet 1. The proposed config option would allow optimizing a little in such situation.

Owner

unscriptable commented Jul 20, 2012

Heh, this may be all that's needed in the config routine:

var predefined, name = cfg['predefined']
for (name in predefined) _define(name, predefined[name]);

gamtiq commented Jul 21, 2012

It seems the needed code should be a bit more complex. ;-)

var name, predefined;
if (predefined = cfg['predefined']) {
    for (name in predefined) {
        _define(name, predefined[name]);
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment