alekseykulikov/backbone-offline

amd, require.js javascript example please

jeacott opened this issue · 4 comments

Hi, I'd love an example or wiki entry that explains how to use this component with requirejs, or to have an amd compatible version out of the box. is it possible?

Hi, it is not for now. Added as feature for next release.

@jeacott You can shim backbone.offline when using require.js. You should set out your require.config as below:

require.config({

    baseUrl: 'scripts',

    paths:{
        'jquery': 'vendor/jquery/jquery',
        'underscore': 'vendor/underscore/underscore', // amd fork
        'backbone': 'vendor/backbone/backbone', // amd fork
        'backbone.offline': 'vendor/backbone/backbone.offline'
    },

    shim:{
        // This is the important line for you. It tells require.js that backbone.offline depends on backbone. 
        'backbone.offline': ['backbone']
    }

});

You'll likely also want to use the AMD forks of backbone and underscore which can be found at https://github.com/amdjs

HI @maxfi, thank you for great introduction to require.js. I think shim part should looks so, but I'm not sure about exports:

shim: {
  'backbone.offline': ['backbone', 'underscore', 'jquery']
  exports: 'Offline'
}

I will test it and then add to docs for next release.

Hi @ask11. I don't use the exports command and it seems to work. I'll look into it.
I'd be happy to help out with the documentation for the wiki if you like? Where is the best place to discuss this further?