make AMD declaration anonymous #1778
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Thanks for adding AMD support to Leaflet! At some point, I'd like to follow up on the discussion in #1364 about using AMD for Leaflet's internal modules as well - but for now I have a simple request: can you change the module declaration to be anonymous? Explicitly declaring the module name leads to inflexibility, as I'll explain.
Per the RequireJS docs, modules should generally be declared anonymously in order to support full portability between projects. For example, if I want to put leaflet in a
lib/subfolder in my JS directory, the resolved module name might belib/leaflet(orwq/lib/leaflet), notleaflet. By defining the module anonymously, projects can integrate Leaflet wherever they wish without needing to define a RequireJS "paths" configuration pointing any dependencies onleafletto their project's location of the file.One of the only libraries that declares its AMD module explicitly is jquery, and this is largely for historical reasons - with the idea that this special case for jquery will be removed over time.
You'll notice that in this PR I've also removed the function that returns L - this is not needed since define() can be used directly with simple objects, in which case it will just return the object.
Edit 2013-11-18: Note that AMD best practice is to put third party libs at the AMD
baseUrlso that they can be referenced by their common names. As above, the purpose of this is to avoid needing a complicated paths config for RequireJS or a similar loader. This is especially important when integrating a plugin such as Proj4leaflet, which AMD-depends on both 'proj4' and 'leaflet'. In general, Leaflet will likely be referenced from other AMD modules as 'leaflet' (and not './leaflet' or 'lib/leaflet'). So, my initial motivation for making Leaflet's AMD definition anonymous was not fully correct (and I am updating my library accordingly). Nevertheless, it is still recommended to use anonymous module definitions in nearly all cases.