Search code examples
javascriptrequirejsautobahnwhen-js

Getting dependencies to load correctly in requirejs (autobahn and whenjs)


I have been stuck on this problem for the past few hours. I'm trying to get autobahnjs and whenjs to be loaded correctly by requirejs.

require.config({
    paths: {
        angular:            '../bower_components/angular/angular',
        angularBootstrap:   '../bower_components/angular-bootstrap/ui-bootstrap',
        bootstrap:          '../bower_components/bootstrap/dist/js/bootstrap',
        jquery:             '../bower_components/jquery/jquery',
        chosen:             '../bower_components/chosen/chosen.jquery.min',
        text:               '../bower_components/requirejs-text/text',
        autobahn:           '../bower_components/autobahnjs/autobahn/autobahn'

    },
    packages: [
       { name: 'when', location: '../bower_components/when/', main: 'when' }
    ],
    baseUrl: '/bundles/example/app/scripts/',
    shim: {
        angular : { 
            exports : 'angular'
        },
        angularBootstrap: {
            deps: ['angular']
        },
        autobahn: {
            deps: ['when']
        }
    },
    priority: [
        'angular'
    ]
});

require
( [
    'angular',
    'app',
    'autobahn',
    'angularBootstrap',
    'jquery',
    'bootstrap',
    'chosen',
    'controllers/event',
    'services/notify'
], function(angular, app) {
    // more code here
});

Autobahnjs has a dependency on whenjs. All the files are loaded (and in the correct order). but when is always undefined. I have absolutely no idea what I'm doing wrong. I've tried all sorts of ways to solve it. I also have a bower.json file if this helps anyone replicate the problem. Thanks in advance.

EDIT: Autobahnjs does not currently support AMD. Whenjs, however, does support it.


Solution

  • This has now been implemented in v0.8.0