scttnlsn / backbone.io

Backbone.js sync via Socket.IO
http://scttnlsn.github.io/backbone.io
541 stars 66 forks source link

AMD shim #55

Closed dminkovsky closed 10 years ago

dminkovsky commented 10 years ago

Hi Scott,

Thank you very much for backbone.io.

Please consider this shim to support using this module with AMD loaders/one-file optimizers like RequireJS or almond. It's pretty basic follows the likes of backbone-amd and underscore-amd: https://github.com/amdjs/backbone/blob/master/backbone.js

Thanks, Dmitry

scttnlsn commented 10 years ago

Where do the strings backbone and io come from? Is that whatever the user chooses as the shim names? In order for this to work would the user have to shim in the same way you did? I'm not terribly familiar with RequireJS.

dminkovsky commented 10 years ago

Hi @scttnlsn, thanks for looking and responding. Been sick, but looking forward to clarifying these points for you.

Thanks again, Dmitry

dminkovsky commented 10 years ago

Hi @scttnlsn,

Haven't been able to update this PR with an answer to your questions. RequireJS is awesome, but unfortunately really poorly documented, and answer your questions a bit tough without starting from the beginning :D. Anyway, Just got back to actually working with backbone.io in my project, so I figured I'd hold off on this PR until I work with it further and make sure it's fine.

In the meantime, for anyone who is interested in shimming this for AMD without a code modifications like my PR, RequireJS 2.1.0+ lets you shim with config now, like this:

requirejs.config({
    paths: {
        jquery: 'bower_components/jquery/jquery',
        underscore: 'bower_components/underscore/underscore',
        backbone: 'bower_components/backbone/backbone',
        io: 'socket.io/socket.io',
        backboneio: 'socket.io/backbone.io'
    },
    shim: {
        backbone: { 
            deps: ['jquery', 'underscore'],
            exports: 'Backbone'
        },
        backboneio: {
            deps: ['backbone', 'io']
        }
    }
});

This follows from https://github.com/marionettejs/backbone.marionette/wiki/Using-marionette-with-requirejs

dminkovsky commented 10 years ago

Actually, closing this. Shimming via RJS config works fine.

dminkovsky commented 10 years ago

Also, wow— this is totally a dupe of https://github.com/scttnlsn/backbone.io/issues/8