James Burke (2014-01-28T01:13:04.000Z)
domenic at domenicdenicola.com (2014-01-31T14:47:09.585Z)
On Mon, Jan 27, 2014 at 3:14 PM, John Barton <johnjbarton at google.com> wrote: > Guy Bedford, based on experiences within the requirejs and commonjs worlds, > has a much better solution for these scenarios. (It's also similar to how > npm works). > > Your jQuery should depend upon the name X, but you Loader should map the > name X when loaded by jQuery to the new version in Loader.normalize(). The > table of name mappings can be configured at run time. > > For example, if some other code depends on X at 1.6 and jQuery needs X at 1.7, > they each load exactly the version they need because the normalized module > names embed the version number. In the AMD world, [map config][1] has been sufficient for these needs. As a point of reference, requirejs only lets the first module registration win, any subsequent registrations for the same module ID are ignored. “ignore" was chosen over “error" because with multiple module bundles, the same module ID/definition could show up in two different bundles (think multi-page apps that have a “common” and page-specific bundles). I do not believe that case should trigger an error. It is just inefficient, and tooling for bundles could offer to enforce finding these inefficiencies vs the browser stopping the app from working by throwing an error. It is true that the errors introduced by “ignore” could be harder to detect given that things may mostly work. The general guide in this case for requirejs was to be flexible in the same spirit of HTML parsing. Redefinition seems to allow breaking the expectation that the module value for a given normalized ID is always the same. When the developer wants to explicitly orchestrate different module values for specific module ID sets, something like AMD’s map config is a good solution as it is a more declarative statement of intent vs code in a module body deciding to redefine. Also, code in module bodies do not have enough information to properly redefine for a set of module IDs like map config can. Map config has been really useful for supporting two different versions of a module in an app, and for providing mocks to certain modules for unit testing. Given what has been said so far for use cases, I would prefer either “ignore” or “error” over redefinition, with a preference of “ignore” over “error" based on the above. [1]: https://github.com/amdjs/amdjs-api/wiki/Common-Config#wiki-map