RequireJS - Database-related modules for reuse in other Rails / JS applications

I am building a web application based on Rails and on the client side of Backbone.js. To structure my Coffeescript code, I used RequireJS and requirejs-rails . Each of my base classes lives in its own RequireJS module.

I recently reorganized a lot of code into some base classes and want to pack them somehow, so that I can easily reuse them in other projects (Rails and / or Javascript / Coffeescript, maybe even without RequireJS) and share it with GitHub as a separate project from my application Rails I read the RequireJS documentation on packages, but this is not very important. So here is what I would like to do:

  • Move my generic code into your own package, so views/base_collection_viewwill become commons/views/base_collection_viewsetc.
  • Include the package in my requirejs-rails setup in my rails applications and provide a compiled file my-commons.jsfor use in installations that do not require installation (I think the latter will be done using almonds quite easily as soon as I come up with a package layout)

A complete example of the RequireJS reusable package would really help me a lot at this point, as well as some ideas on how this could be ported to requirejs-rails.

+3
source share
1 answer

Not sure about requirejs-rails, but with RequireJS it's pretty easy.

define(['dep1', 'dep2'] , function ($, otherLibrary) {
    return function () {
        // your module code
    };
});

'dep1' 'dep2' - RequireJS, . , . var, ($ otherLibrary ), - , .

, RequireJS, , , .

, "my-super-lib.js" libs, libs/my-super-lib , .

: , coffeescript. , :

define ['dep1', 'dep2'], ($, otherLibrary) ->
    () ->
        // your module code

.;)

0