dsuryd / dotNetify

Simple, lightweight, yet powerful way to build real-time web apps.
https://dotnetify.net
Other
1.17k stars 164 forks source link

Send method of MulticastVM not working in the OnRouted handler #152

Closed bugged84 closed 5 years ago

bugged84 commented 5 years ago

From the docs:

... dotNetify employs something similar to the request-response cycle, but in this case it's action-reaction cycle: the front-end initiates an action that mutates the state, the back-end processes the action and then sends back to the front-end any other states that mutate as the reaction to that action.

I'm trying to do the following, when a user enters the multicast chat room lobby.

this.OnRouted(
    (sender, args) =>
    {
        Send(
            new List<string> { connectionContext.ConnectionId }
          , "Welcome"
          , new { Rules = "..." }
        );
    }
);

However, I see nothing logged in the browser console like I do when I call Send from within an Action handler on the VM (e.g. Submit). Does the Send method only work within an action-reaction cycle?

dsuryd commented 5 years ago

No, Send goes on a separate path from that cycle. You will need to make the call async to give the chance for the initial VM request to complete first.