Why does DataTables register as a named AMD module?
Why does DataTables register as a named AMD module?
Hi everybody,
this is just a thing that got me scratching my head when I was setting up a map configuration in RequireJS.
I created a wrapper module for DataTables which require
s DataTables, sets the default settings and then returns the DataTables instance.
I then mapped the module key "datatables" for every module (using the "*" wildcard) to this wrapper module instead of the actual DataTables library file, so that the config is always being loaded with the library.
I obviously added another mapping specifically for the wrapper module so that the "datatables" module actually refers to the DataTables library within the wrapper.
This way I don't need to manually include the DataTables config everywhere I use DataTables.
This approach seems to be working, even though the RequireJS manual states that mapping may not be working with named modules. And that's the point: Why does DataTables register as a named AMD module in the first place? As far as I could see, this doesn't give you any advantage, rather the contrary even.
Replies
For the same reason jQuery registers itself as a named module - there is other software that depends upon it, thus consistent naming is required. Editor and all of the other DataTables extensions for example need to load both jQuery and DataTables - this why it needs to be a named module.
Allan