0

In Signalr, is there any support for having events instead of callbacks.

Let me explain before you grab your pitchforks.

In following with the first example here

Clients.All.addContosoChatMessageToPage(name, message);

Wouldn't call a hub proxy's addContosoChatMessageToPage(name, message), but would dispatch a addContosoChatMessageToPage event with some extra information. (not asking that it be the same api call exactly)

The reason I'm asking all of this is because

  1. This works much better alongside functional reactive programming frameworks like ELM and bacon.js
  2. I don't want to do this myself and essentially create my own sub-framework. Of course I could always do Clients.All.CreateEvent(name,params...) where I'm continually calling back my method to do this event creation
  3. I actually think events work better in some scenarios for separation of concerns.

Am I crazy? does something like this exist?

Brian Rosamilia
  • 1,348
  • 11
  • 21

1 Answers1

1

This is already supported. If you don't want to do the dispatching yourself and you know the name of the "event" or "method" at runtime you can do this:

IClientProxy proxy = Clients.All;
proxy.Invoke(name, args);

This lets you write code where you may not know the name of the event you're trying to callback on the client at compile time.

davidfowl
  • 32,805
  • 7
  • 81
  • 91