Permalink
Browse files

Fixed some isseus with hubs JS client.

  • Loading branch information...
1 parent ff25cb4 commit 7808c90bbbcecb4f8ce2d01d8198d93aac30620c @DamianEdwards DamianEdwards committed Jul 6, 2012
@@ -69,7 +69,7 @@
var self = this,
args = $.makeArray(arguments).slice(1),
userCallback = args[args.length - 1], // last argument
- methodArgs = $.type(userCallback) === "function" ? args.slice(0, -1) /* all but last */ : args,
+ methodArgs = $.type(userCallback) === "function" ? args.slice(0, args.length - 1) /* all but last */ : args,
argValues = methodArgs.map(getArgValue),
data = { hub: self.hubName, method: methodName, args: argValues, state: self.state, id: callbackId },
d = $.Deferred(),
@@ -75,8 +75,24 @@
}
function invoke(hub, methodName, args) {
+ // Extract user callback from args
+ var userCallback = args[args.length - 1], // last argument
+ callback = function (result) {
+ // Update hub state from proxy state
+ $.extend(hub, hub._.proxy.state);
+ if ($.isFunction(userCallback)) {
+ userCallback.call(hub, result);
+ }
+ };
+
+ if ($.isFunction(userCallback)) {
+ // Replace user's callback with our own
+ args = $.merge(args.splice(0, args.length - 1), [callback]);
+ }
+
// Update proxy state from hub state
$.extend(hub._.proxy.state, copy(hub, ["_"]));
+
return hub._.proxy.invoke.apply(hub._.proxy, $.merge([methodName], args));
}
@@ -41,7 +41,7 @@
};
demo.complexType(p, function () {
- $('#value').html('Complex Type ->' + window.JSON.stringify(this.person));
+ $('#complexType').html('Complex Type ->' + window.JSON.stringify(this.person));
});
demo.multipleCalls();
@@ -46,6 +46,10 @@
<div id="simpleArray">
</div>
+ <h3>ComplexType</h3>
+ <div id="complexType">
+ </div>
+
<h3>ComplexArray</h3>
<div id="complexArray">
</div>
@@ -75,8 +75,24 @@
}
function invoke(hub, methodName, args) {
+ // Extract user callback from args
+ var userCallback = args[args.length - 1], // last argument
+ callback = function (result) {
+ // Update hub state from proxy state
+ $.extend(hub, hub._.proxy.state);
+ if ($.isFunction(userCallback)) {
+ userCallback.call(hub, result);
+ }
+ };
+
+ if ($.isFunction(userCallback)) {
+ // Replace user's callback with our own
+ args = $.merge(args.splice(0, args.length - 1), [callback]);
+ }
+
// Update proxy state from hub state
$.extend(hub._.proxy.state, copy(hub, ["_"]));
+
return hub._.proxy.invoke.apply(hub._.proxy, $.merge([methodName], args));
}
@@ -1356,7 +1356,7 @@
var self = this,
args = $.makeArray(arguments).slice(1),
userCallback = args[args.length - 1], // last argument
- methodArgs = $.type(userCallback) === "function" ? args.slice(0, -1) /* all but last */ : args,
+ methodArgs = $.type(userCallback) === "function" ? args.slice(0, args.length - 1) /* all but last */ : args,
argValues = methodArgs.map(getArgValue),
data = { hub: self.hubName, method: methodName, args: argValues, state: self.state, id: callbackId },
d = $.Deferred(),
Oops, something went wrong.
@@ -1356,7 +1356,7 @@
var self = this,
args = $.makeArray(arguments).slice(1),
userCallback = args[args.length - 1], // last argument
- methodArgs = $.type(userCallback) === "function" ? args.slice(0, -1) /* all but last */ : args,
+ methodArgs = $.type(userCallback) === "function" ? args.slice(0, args.length - 1) /* all but last */ : args,
argValues = methodArgs.map(getArgValue),
data = { hub: self.hubName, method: methodName, args: argValues, state: self.state, id: callbackId },
d = $.Deferred(),
Oops, something went wrong.

0 comments on commit 7808c90

Please sign in to comment.