Skip to content

Commit

Permalink
Fix conflict resolution shenanigans (#87)
Browse files Browse the repository at this point in the history
  • Loading branch information
RReverser authored May 13, 2024
1 parent 07633ad commit 7064c20
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 75 deletions.
7 changes: 0 additions & 7 deletions examples/quickstart/client/module_bindings/Message.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,9 @@ public static bool ComparePrimaryKey(SpacetimeDB.SATS.AlgebraicType t, Spacetime

public delegate void InsertEventHandler(Message insertedValue, SpacetimeDB.Types.ReducerEvent dbEvent);
public delegate void DeleteEventHandler(Message deletedValue, SpacetimeDB.Types.ReducerEvent dbEvent);
public delegate void RowUpdateEventHandler(SpacetimeDBClient.TableOp op, Message oldValue, Message newValue, SpacetimeDB.Types.ReducerEvent dbEvent);
public static event InsertEventHandler OnInsert;
public static event DeleteEventHandler OnBeforeDelete;
public static event DeleteEventHandler OnDelete;
public static event RowUpdateEventHandler OnRowUpdate;

public static void OnInsertEvent(object newValue, ClientApi.Event dbEvent)
{
Expand All @@ -129,10 +127,5 @@ public static void OnDeleteEvent(object oldValue, ClientApi.Event dbEvent)
{
OnDelete?.Invoke((Message)oldValue,(ReducerEvent)dbEvent?.FunctionCall.CallInfo);
}

public static void OnRowUpdateEvent(SpacetimeDBClient.TableOp op, object oldValue, object newValue, ClientApi.Event dbEvent)
{
OnRowUpdate?.Invoke(op, (Message)oldValue,(Message)newValue,(ReducerEvent)dbEvent?.FunctionCall.CallInfo);
}
}
}
7 changes: 0 additions & 7 deletions examples/quickstart/client/module_bindings/User.cs
Original file line number Diff line number Diff line change
Expand Up @@ -126,12 +126,10 @@ public static SpacetimeDB.SATS.AlgebraicType GetPrimaryKeyType(SpacetimeDB.SATS.
public delegate void InsertEventHandler(User insertedValue, SpacetimeDB.Types.ReducerEvent dbEvent);
public delegate void UpdateEventHandler(User oldValue, User newValue, SpacetimeDB.Types.ReducerEvent dbEvent);
public delegate void DeleteEventHandler(User deletedValue, SpacetimeDB.Types.ReducerEvent dbEvent);
public delegate void RowUpdateEventHandler(SpacetimeDBClient.TableOp op, User oldValue, User newValue, SpacetimeDB.Types.ReducerEvent dbEvent);
public static event InsertEventHandler OnInsert;
public static event UpdateEventHandler OnUpdate;
public static event DeleteEventHandler OnBeforeDelete;
public static event DeleteEventHandler OnDelete;
public static event RowUpdateEventHandler OnRowUpdate;

public static void OnInsertEvent(object newValue, ClientApi.Event dbEvent)
{
Expand All @@ -152,10 +150,5 @@ public static void OnDeleteEvent(object oldValue, ClientApi.Event dbEvent)
{
OnDelete?.Invoke((User)oldValue,(ReducerEvent)dbEvent?.FunctionCall.CallInfo);
}

public static void OnRowUpdateEvent(SpacetimeDBClient.TableOp op, object oldValue, object newValue, ClientApi.Event dbEvent)
{
OnRowUpdate?.Invoke(op, (User)oldValue,(User)newValue,(ReducerEvent)dbEvent?.FunctionCall.CallInfo);
}
}
}
123 changes: 62 additions & 61 deletions src/SpacetimeDBClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -704,85 +704,86 @@ void InternalInsertCallback(DbOp op)
var oldValue = dbOps[i].oldValue;
var newValue = dbOps[i].newValue;

switch (tableOp)
switch (tableOp)
{
case TableOp.Insert:
if (oldValue == null && newValue != null)
{
case TableOp.Insert:
if (oldValue == null && newValue != null)
try
{
if (dbOps[i].table.InsertCallback != null)
{
dbOps[i].table.InsertCallback.Invoke(newValue,
message.TransactionUpdate?.Event);
}
}
catch (Exception e)
{
Logger.LogException(e);
}
}
else
{
Logger.LogError("Failed to send callback: invalid insert!");
}

break;
case TableOp.Delete:
{
if (oldValue != null && newValue == null)
{
if (dbOps[i].table.DeleteCallback != null)
{
try
{
if (dbOps[i].table.InsertCallback != null)
{
dbOps[i].table.InsertCallback.Invoke(newValue,
message.TransactionUpdate?.Event);
}
dbOps[i].table.DeleteCallback.Invoke(oldValue,
message.TransactionUpdate?.Event);
}
catch (Exception e)
{
Logger.LogException(e);
}
}
else
{
Logger.LogError("Failed to send callback: invalid insert!");
}
}
else
{
Logger.LogError("Failed to send callback: invalid delete");
}

break;
case TableOp.Delete:
break;
}
case TableOp.Update:
{
if (oldValue != null && newValue != null)
{
try
{
if (oldValue != null && newValue == null)
{
if (dbOps[i].table.DeleteCallback != null)
{
try
{
dbOps[i].table.DeleteCallback.Invoke(oldValue,
message.TransactionUpdate?.Event);
}
catch (Exception e)
{
Logger.LogException(e);
}
}
}
else
if (dbOps[i].table.UpdateCallback != null)
{
Logger.LogError("Failed to send callback: invalid delete");
dbOps[i].table.UpdateCallback.Invoke(oldValue, newValue,
message.TransactionUpdate?.Event);
}

break;
}
case TableOp.Update:
catch (Exception e)
{
if (oldValue != null && newValue != null)
{
try
{
if (dbOps[i].table.UpdateCallback != null)
{
dbOps[i].table.UpdateCallback.Invoke(oldValue, newValue,
message.TransactionUpdate?.Event);
}
}
catch (Exception e)
{
Logger.LogException(e);
}
}
else
{
Logger.LogError("Failed to send callback: invalid update");
}

break;
Logger.LogException(e);
}
case TableOp.NoChange:
// noop
break;
default:
throw new ArgumentOutOfRangeException();
}
else
{
Logger.LogError("Failed to send callback: invalid update");
}

break;
}
}
case TableOp.NoChange:
// noop
break;
default:
throw new ArgumentOutOfRangeException();
}
}
}

private void OnMessageProcessComplete(Message message, List<DbOp> dbOps)
{
Expand Down

0 comments on commit 7064c20

Please sign in to comment.