Say for example I have a something like this declared in Starcounter
[Database]
public class User
{
public string Username;
public string Email;
}
I have a page listing one row from the DB with an update button with PuppetJS and all working fine.
If I change the value from another session or directly in the DB, is there anyway to directly update the values to any client who are active by pushing the new values to the clients?
*** Edit: I added following to my TestPage.json.cs file :
void Handle(Input.Update action)
{
Transaction.Commit();
Session.ForAll(s =>
{
if (s.Data is TestPage)
s.CalculatePatchAndPushOnWebSocket();
});
}
This push updates directly to other sessions nicely. Still wonder if there is some better way to do this.
The code that you've presented in your edit is exactly the way to go:
void Handle(Input.Update action)
{
Transaction.Commit();
Session.ForAll(s =>
{
if (s.Data is TestPage)
s.CalculatePatchAndPushOnWebSocket();
});
}
What it does is:
TestPage
instance attached to itMore about pushing changes over WebSocket can be found here: http://starcounter.io/guides/web/sessions/.