This works fine
class Window.AppViewModel
message : ko.observable("")
chatMessages : ko.observableArray()
canSendMessage : ko.observable(false)
Window.sHub.addMsg = (data) =>
@::chatMessages.push(data)
whereas this
class Window.AppViewModel
constructor : ->
@message = ko.observable("")
@chatMessages = ko.observableArray()
@canSendMessage = ko.observable(false)
Window.sHub.addMsg = (data) =>
@chatMessages.push(data)
Results in my server side hub recieving server messages but it can’t make any callbacks.
What am I missing here??? This is driving me up the wall. Obviously the prototype based solution will work because it’s making everything “static” but I’m crippled because I can’t write nicely separated code at the moment.
Is there any way to see what the hub is trying to invoke?? The SignalR documentation talks about tracing/logging but never explains how.
All wired client events can be found by adding a small snippet to the “On” anonymous function in jquery.SignalR in the hubProxy prototype
So now it looks something like this
And gives you nice output of what client methods can be called back from the server
Also, I learned that CreateHubProxies (reflects through the callbacks you add) is only called once for an entire hub.Start()–So all methods must be added to the hub proxy before you start.
This should definitely be on the github wiki. It makes sense but it isn’t obvious.
Edit : It would make sense to allow you to call CreateHubProxies multiple times. People are accustom to writing Knockout.js code in a way where they delay allocating a viewmodel until a certain event happens–if your viewmodel has any SignalR callbacks, this isn’t impossible. Having to create all of your viewmodels upfront is a bit of a kludge. You could even keep it pretty lean by keeping a list of proxy members already generated and excluding them.