SignalR and RequireJS : client methods undefined

生来就可爱ヽ(ⅴ<●) 提交于 2020-01-25 10:33:46

问题


I am trying to use SignalR (1.3) with RequireJS.

My requireJs shim contains :

    "signalr.core": {
            deps: ["jquery"],
            exports: "$.connection"
        },
        "signalr.hubs": {
            deps: ["signalr.core"],
            exports: "$.connection"
        },

I have a module :

define(["jquery", "signalr.hubs"], function ($) {
    var Test = {};
    Test.Init = function () {
        //Code init
        $.connection.myHub.client.ClientMethod = function () { console.log("Hello"); };
    };
    Test.Start = function () {
        return $.connection.hubs.start();
    };
    return Test;
});

I call my module two times in my code, first time for init, second for start :

require(["jquery", "myModule"], function ($, Test) {
    Test.Init();
});
require(["jquery", "myModule"], function ($, Test) {
    Test.Start().done(function () {
        $(document.body).append($("<p />").text("Connected"));
    });
});

But when I call the Test.Start() method, the value of $.connection.myHub.client.ClientMethod is undefined.

What is the correct way to declare my shim to avoid loosing my hubs' client methods ?

Thanks.

来源:https://stackoverflow.com/questions/18571545/signalr-and-requirejs-client-methods-undefined

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!