Kev
Kev

Reputation: 765

loading backbone and backbone relational with require js

Hi all Im trying to load backbone and backbone-relational in require js every time I just require 'backbone', this is my code:

main.js:

requirejs.config({
    paths: {
        'domReady': 'lib/require/domReady',
        'text': 'lib/require/text',
        'jquery': 'lib/jquery/jquery',
        'underscore': 'lib/underscore',
        'backbone': 'lib/backbone/loader',
        'relational': 'lib/backbone/relational',
        'iosync': 'lib/backbone/iosync',
        'iobind': 'lib/backbone/iobind'
    },
    shim: {
        'underscore': {
            exports: '_'
        },
        'backbone': {
            deps: ['underscore', 'jquery'],
            exports: 'Backbone'
        },
        'relational': {
            deps: ['backbone']
        },
        'iobind': {
            deps: ['backbone']
        },
        'iosync': {
            deps: ['backbone']
        }
    }
});

require([
    'domReady!',
    'jquery',
    'backbone',
    'models/application',
    'views/application'
], function () {
    // start the app
    var applicationModel = new BACON.models.Application();
    var applicationView = new BACON.views.Application({
        el: $('body'),
        model: applicationModel
    });
});

and lib/backbone/loader.js:

define([
    'lib/backbone/backbone',
    'relational',
    'iobind',
    'iosync'
]);

but running my app on chrome gives me:

Uncaught Error: Load timeout for modules: relational,iobind,iosync

So it seems i have a dependency loop... Is there a way to make this work or is there another way to accomplish this??

Upvotes: 1

Views: 514

Answers (1)

Ingro
Ingro

Reputation: 2841

In your shim config you added a depedency for relational to backbone, which refer to libs/backbone/loader, and this generate a loop while loading lib/backbone/loader.js.

You should change your path config for backbone to 'lib/backbone/backbone' and add another named path for the loader if you want.

Upvotes: 1

Related Questions