AMD definition without explicit module name

AMD definition without explicit module name

scifiscifi Posts: 6Questions: 2Answers: 0

We just spent a few hours trying to use DataTables with RequireJS. In the end it turned out that the module is explicitly exported with the module name 'datatables':

define( 'datatables', ['jquery'], factory );

This definition results in the fact that you must use the same module name ('datatables') when you define datatables. If you use another module name, such as jquery-datatables as we did, the result seems to be a race condition and DataTables cannot be used.

Is there a special reason to specify 'datatables' explicitly? Would it hurt to define the module just like this?

define( ['jquery'], factory );

If I got things right, leaving the name away is the common way to define libraries and it avoids such issues as we had. If you stick at defining datatables with an explicit module name we would much appreciate a big warning at the download page, so other users do not run into the same situation.

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,687Questions: 1Answers: 10,500 Site admin
    Answer ✓

    Is there a special reason to specify 'datatables' explicitly?

    Same reason that jQuery do it - it is the safest option and it allows dependency loading (TableTools etc) more reliably.

    It is a bit of a pain to match the name explicitly I know - I'm going to be writing up a blog post about using DataTables and its components with RequireJS soon.

    Allan

  • scifiscifi Posts: 6Questions: 2Answers: 0

    Thank you for the fast answer. I guess that a blog post which is also linked at the download page would be great! It for sure would have saved me a few hours of googling and trial&error :).

This discussion has been closed.