Thanks for getting this in! Notes inline:
On Fri, Mar 15, 2013 at 12:32 PM, Jakob Heuser <
ja...@felocity.com> wrote:
> First off, a huge thanks to the Richard Backhouse. We have lsjs working in
> the new test suite, and we've uncovered a questions around the spec I feel
> might be worth getting solid answers on.
>
> 1. config() must be ran before the initial go() invocation.
> Some lsjs tests were timing out due to the config() call occuring after the
> first go() invocation. As highlighted in another thread in the forum, not
> all AMD loaders rely on location.href as a fallback.
>
> AMD JS Implication: the global require(Array, cb) should NOT run if the
> framework is not configured yet, and should throw a helpful error for the
> developer. This may just be an update to the specification.
This seems to be a per-loader choice (have enough defaults that
require() will run before a config call or not), not sure we need to
say anything about it in the spec. For the tests, it seems fine to
allow for running a config() call first.
> 2. nesting require statements - allowed?
> Should people consider the following code "valid"
> go(["require", "foo"], function(require, foo) {
> require(["require", "bar"], function(require, bar) {
> require(["require", "baz"], function(require, baz) {
> // etc...
> });
> });
> });
>
> AMD JS Implication: we don't really have many tests that exercise this use
> case. For now, we've made _reporter a top level module. The basic_require
> test exercises this somewhat, but circular dependencies are more than likely
> a missed use case at the moment. For that matter, I'm not even sure this is
> a pattern we want to be endorsing.
Nested require calls seem fine to allow. In some cases, it can be
useful -- doing a built layer load, doing some other env check, then
doing another layer load. Asking for "require" in the nested require
calls seems excessive -- the user could get by without them, but I
would not expect it to cause harm.
> 3. One does not simply nest global requires...
> go(["foo"], function(foo) {
> go(["bar"], function(bar) {
> // this is bad
> });
> });
>
> AMD JS Implication: The AMD spec is pretty vague about how the global
> require() should work if its exposed. We may want to note that someone
> implementing code for multiple loaders should only call the global entry
> point once. Again, I'm not even sure this is a pattern we want to endorse.
This pattern has shown up in the real world, even used it for an
example project:
https://github.com/requirejs/example-multipage/blob/master/www/js/page1.js
I think there is better performance by parallelizing the load, but
that requires careful crafting of layers for it to work before and
after a build, where the nested call is usually easier to understand
and get right.
I am curious to know other people's opinion on those patterns though.
James