Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SignalR & require.js configuration

I'm incorporating SignalR into a project where I'm already using require.js to handle my scripts dependencies.

I'm having a little trouble making sure "/signalr/hubs" is called after "jquery.signalR-1.1.2" loads.

I got it to work, but I'm wondering if there is a better alternative out there.

This is what I have:

require(["signalr"], function () {
  require(["noext!/signalr/hubs"], function () {
      //initialize and work with the hub here
  }
}

Is there a way I can create a shim here to establish the dependency between signalr/hubs and the signalr script?

Thanks!

like image 417
Raciel R. Avatar asked Jul 11 '13 15:07

Raciel R.


Video Answer


1 Answers

This works for me with SignalR 1.1.2:

require.config({
baseUrl: "/<your scripts dir>",
paths: {
    "jquery": "jquery-<your jquery version>.min",
    "signalr.core": "jquery.signalR-<your signalr version>.min",
    "signalr.hubs": "/signalr/hubs?"
},
shim: {
    "jquery": {
        exports: "$"
    },
    "signalr.core": {
        deps: ["jquery"],
        exports: "$.connection"
    },
    "signalr.hubs": {
        deps: ["signalr.core"],
    }
}
});

require(["jquery", "signalr.hubs"],
    function($)
    {
        var hubProxy = $.connection.myHub;

        // ... go to town ...
    });
like image 99
Drew Marsh Avatar answered Oct 05 '22 11:10

Drew Marsh