Signalr:'default' done for a hub.server.method call

294 views Asked by At

I have a hub server method called with signalr many times. I know i can do:

hub.server.method().done(function(data){ 
    //my_code
}

but is there any way I can set a 'default' done() function so I don't have to repeat it every time I call that method?

2

There are 2 answers

5
Toan Nguyen On BEST ANSWER

Create a function in your *.js file like this

function doSomething(){
hub.server.method().done(function(data){ 
    //my_code
}
};

And then call doSomething instead of

hub.server.method().done(function(data){ 
    //my_code
}

Edited:

If you want to add a function to the server object you can do:

 hub.server.myDecoratedBehavior= function() {
        if (connected) {
            this.originalBehavior().done(function () {
                console.log("Chat window was cleared");
            });
        }
    };
0
Michal Levý On
var onDone = function(data) {
  // code
};

hub.server.method1().done(onDone);
hub.server.method2().done(onDone);