Asynchronous Module Definition (**AMD**) question -- map and shim attributes in Amber config object

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Asynchronous Module Definition (**AMD**) question -- map and shim attributes in Amber config object

Hannes Hirzel
Hello

I would like to now more about the map and shim attributes in the
Amber AMD config object?

https://github.com/amber-smalltalk/amber/blob/master/support/amber.js


In particular what do the expressions

   '*': {
                'css': 'amber_lib/requirejs/require-css-0.0.6/css'
            },


and

 shim: {
            'jquery-ui': {
                deps: [ 'jquery' ]
            },
            'amber_lib/bootstrap/js/bootstrap': {
                deps: [ 'css!amber_lib/bootstrap/css/bootstrap' ]
            },
            ....
            },

say?

Thank you for the answer in advance.
-- Hannes



**Background**

These days Amber is loaded through

<script type='text/javascript' src='support/amber.js'></script>
    <script type='text/javascript'
src='support/requirejs/require.min.js'></script>

in the HTML file
(https://github.com/amber-smalltalk/amber/blob/master/index.html  --
copied in below).

It uses the JavaScript Asynchonous Module Definition (AMD) API through
requirejs.

Where can I find documentation which explains the 'map' and 'shim'
attribute in the config object (see below).

**Documents consulted so far**

- https://github.com/amdjs/amdjs-api/wiki/AMD
- http://requirejs.org/docs/api.html
- http://requirejs.org/docs/whyamd.html


**The amber.js file**
https://github.com/amber-smalltalk/amber/blob/master/support/amber.js

/* Amber package loading.
  Load this script as well as require.js (works in any order;
    either defines 'require', thus passing config, if loaded prior require.js;
    or calls require.config, if loaded post require.js).
  Usage example:
    require(['amber/devel'], function(smalltalk) {
        smallralk.initialize();

        smalltalk.Browser._open();
    });
 */

var require;

require = function (require) {
    var scripts = document.getElementsByTagName("script");
    var src = scripts[ scripts.length - 1 ].src;
    var home = resolveViaDOM(src).replace(/\/[^\/]+\/[^\/]+$/, "");

    function resolveViaDOM(url) {
        var a = document.createElement("a");
        a.href = url;
        return a.href;
    }

    var config = {
        paths: {
            'amber': home+'/support',
            'amber_vm': home+'/support',
            'amber_css': home+'/css',
            'amber_lib': home+'/support',
            'amber_core': home+'/js',
            'amber_core/_source': home+'/st',
            'jquery': home+'/support/jQuery/jquery-1.8.2.min',
            'jquery-ui': home+'/support/jQuery/jquery-ui-1.8.16.custom.min'
        },
        map: {
            '*': {
                'css': 'amber_lib/requirejs/require-css-0.0.6/css'
            },
            'amber/helios': {
                'jquery-ui': 'amber_lib/jQuery/jquery-ui-1.8.24.custom.min'
            }
        },
        shim: {
            'jquery-ui': {
                deps: [ 'jquery' ]
            },
            'amber_lib/bootstrap/js/bootstrap': {
                deps: [ 'css!amber_lib/bootstrap/css/bootstrap' ]
            },
            'amber_lib/CodeMirror/codemirror': {
                deps: [ 'css!amber_lib/CodeMirror/codemirror' ]
            },
            'amber_lib/jQuery/jquery.textarea': {
                deps: [ 'jquery', 'jquery-ui' ]
            },
            'amber_lib/CodeMirror/smalltalk': {
                deps: [ './codemirror' ]
            },
            'amber_lib/CodeMirror/addon/hint/show-hint': {
                deps: [ '../../codemirror' ]
            },
            'ensure-console': {
                exports: 'console'
            }
        }
    };

    if (require) {
        require.config(config);
        return require;
    } else {
        return config;
    }
}(require);

--
You received this message because you are subscribed to the Google Groups "amber-lang" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/groups/opt_out.
Reply | Threaded
Open this post in threaded view
|

Re: Asynchronous Module Definition (**AMD**) question -- map and shim attributes in Amber config object

Hannes Hirzel
P.S. on
http://requirejs.org/docs/api.html

there is


<citation>
There is also support for a "*" map value which means "for all modules
loaded, use this map config". If there is a more specific map config,
that one will take precedence over the star config. Example:


requirejs.config({
    map: {
        '*': {
            'foo': 'foo1.2'
        },
        'some/oldmodule': {
            'foo': 'foo1.0'
        }
    }
});

</citation>

So it seems that

'css': 'amber_lib/requirejs/require-css-0.0.6/css'

means everything 'css' (prefix, suffix?) should be taken from

amber_lib/requirejs/require-css-0.0.6/css

?



On 8/31/13, H. Hirzel <[hidden email]> wrote:

> Hello
>
> I would like to now more about the map and shim attributes in the
> Amber AMD config object?
>
> https://github.com/amber-smalltalk/amber/blob/master/support/amber.js
>
>
> In particular what do the expressions
>
>    '*': {
>                 'css': 'amber_lib/requirejs/require-css-0.0.6/css'
>             },
>
>
> and
>
>  shim: {
>             'jquery-ui': {
>                 deps: [ 'jquery' ]
>             },
>             'amber_lib/bootstrap/js/bootstrap': {
>                 deps: [ 'css!amber_lib/bootstrap/css/bootstrap' ]
>             },
>             ....
>             },
>
> say?
>
> Thank you for the answer in advance.
> -- Hannes
>
>
>
> **Background**
>
> These days Amber is loaded through
>
> <script type='text/javascript' src='support/amber.js'></script>
>     <script type='text/javascript'
> src='support/requirejs/require.min.js'></script>
>
> in the HTML file
> (https://github.com/amber-smalltalk/amber/blob/master/index.html  --
> copied in below).
>
> It uses the JavaScript Asynchonous Module Definition (AMD) API through
> requirejs.
>
> Where can I find documentation which explains the 'map' and 'shim'
> attribute in the config object (see below).
>
> **Documents consulted so far**
>
> - https://github.com/amdjs/amdjs-api/wiki/AMD
> - http://requirejs.org/docs/api.html
> - http://requirejs.org/docs/whyamd.html
>
>
> **The amber.js file**
> https://github.com/amber-smalltalk/amber/blob/master/support/amber.js
>
> /* Amber package loading.
>   Load this script as well as require.js (works in any order;
>     either defines 'require', thus passing config, if loaded prior
> require.js;
>     or calls require.config, if loaded post require.js).
>   Usage example:
>     require(['amber/devel'], function(smalltalk) {
>         smallralk.initialize();
>
>         smalltalk.Browser._open();
>     });
>  */
>
> var require;
>
> require = function (require) {
>     var scripts = document.getElementsByTagName("script");
>     var src = scripts[ scripts.length - 1 ].src;
>     var home = resolveViaDOM(src).replace(/\/[^\/]+\/[^\/]+$/, "");
>
>     function resolveViaDOM(url) {
>         var a = document.createElement("a");
>         a.href = url;
>         return a.href;
>     }
>
>     var config = {
>         paths: {
>             'amber': home+'/support',
>             'amber_vm': home+'/support',
>             'amber_css': home+'/css',
>             'amber_lib': home+'/support',
>             'amber_core': home+'/js',
>             'amber_core/_source': home+'/st',
>             'jquery': home+'/support/jQuery/jquery-1.8.2.min',
>             'jquery-ui': home+'/support/jQuery/jquery-ui-1.8.16.custom.min'
>         },
>         map: {
>             '*': {
>                 'css': 'amber_lib/requirejs/require-css-0.0.6/css'
>             },
>             'amber/helios': {
>                 'jquery-ui': 'amber_lib/jQuery/jquery-ui-1.8.24.custom.min'
>             }
>         },
>         shim: {
>             'jquery-ui': {
>                 deps: [ 'jquery' ]
>             },
>             'amber_lib/bootstrap/js/bootstrap': {
>                 deps: [ 'css!amber_lib/bootstrap/css/bootstrap' ]
>             },
>             'amber_lib/CodeMirror/codemirror': {
>                 deps: [ 'css!amber_lib/CodeMirror/codemirror' ]
>             },
>             'amber_lib/jQuery/jquery.textarea': {
>                 deps: [ 'jquery', 'jquery-ui' ]
>             },
>             'amber_lib/CodeMirror/smalltalk': {
>                 deps: [ './codemirror' ]
>             },
>             'amber_lib/CodeMirror/addon/hint/show-hint': {
>                 deps: [ '../../codemirror' ]
>             },
>             'ensure-console': {
>                 exports: 'console'
>             }
>         }
>     };
>
>     if (require) {
>         require.config(config);
>         return require;
>     } else {
>         return config;
>     }
> }(require);
>

--
You received this message because you are subscribed to the Google Groups "amber-lang" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/groups/opt_out.
Reply | Threaded
Open this post in threaded view
|

Re: Asynchronous Module Definition (**AMD**) question -- map and shim attributes in Amber config object

Herby Vojčík
In reply to this post by Hannes Hirzel


H. Hirzel wrote:

> Hello
>
> I would like to now more about the map and shim attributes in the
> Amber AMD config object?
>
> https://github.com/amber-smalltalk/amber/blob/master/support/amber.js
>
>
> In particular what do the expressions
>
> '*': {
> 'css': 'amber_lib/requirejs/require-css-0.0.6/css'
> },

This is a way to map 'css' loader plugin, used in 'css!...' targets.

> and
>
> shim: {
> 'jquery-ui': {
> deps: [ 'jquery' ]
> },
> 'amber_lib/bootstrap/js/bootstrap': {
> deps: [ 'css!amber_lib/bootstrap/css/bootstrap' ]
> },
> ....
> },

These are shimmed dependencies for modules that are not AMD in nature,
so require.js can load their dependencies and execute in right order.

> say?
>
> Thank you for the answer in advance.
> -- Hannes

> - http://requirejs.org/docs/api.html

Here it is all explained. This is only source I remember I had as well.

Herby

--
You received this message because you are subscribed to the Google Groups "amber-lang" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/groups/opt_out.