File tree Expand file tree Collapse file tree 3 files changed +10
-42
lines changed
crates/bindings-csharp/Runtime
modules/sdk-test-connect-disconnect-cs Expand file tree Collapse file tree 3 files changed +10
-42
lines changed Original file line number Diff line number Diff line change @@ -142,6 +142,8 @@ public static class ReducerKind
142142{
143143 public const string Init = "__init__" ;
144144 public const string Update = "__update__" ;
145+ public const string Connect = "__identity_connected__" ;
146+ public const string Disconnect = "__identity_disconnected__" ;
145147}
146148
147149public interface IReducer
Original file line number Diff line number Diff line change @@ -229,37 +229,6 @@ public DbEventArgs(byte[] senderIdentity, ulong timestamp_us)
229229 }
230230 }
231231
232- public static event Action < DbEventArgs > ? OnConnect ;
233- public static event Action < DbEventArgs > ? OnDisconnect ;
234-
235- // Note: this is accessed by C bindings.
236- private static string ? IdentityConnected ( byte [ ] sender_identity , ulong timestamp )
237- {
238- try
239- {
240- OnConnect ? . Invoke ( new ( sender_identity , timestamp ) ) ;
241- return null ;
242- }
243- catch ( Exception e )
244- {
245- return e . ToString ( ) ;
246- }
247- }
248-
249- // Note: this is accessed by C bindings.
250- private static string ? IdentityDisconnected ( byte [ ] sender_identity , ulong timestamp )
251- {
252- try
253- {
254- OnDisconnect ? . Invoke ( new ( sender_identity , timestamp ) ) ;
255- return null ;
256- }
257- catch ( Exception e )
258- {
259- return e . ToString ( ) ;
260- }
261- }
262-
263232 [ MethodImpl ( MethodImplOptions . InternalCall ) ]
264233 private extern static void ScheduleReducer (
265234 string name ,
Original file line number Diff line number Diff line change 11using SpacetimeDB . Module ;
22using static SpacetimeDB . Runtime ;
3- using System . Runtime . CompilerServices ;
43
54static partial class Module
65{
@@ -16,18 +15,16 @@ public partial struct Disconnected
1615 public Identity identity ;
1716 }
1817
19- [ ModuleInitializer ]
20- public static void Init ( )
18+ [ SpacetimeDB . Reducer ( ReducerKind . Connect ) ]
19+ public static void OnConnect ( DbEventArgs e )
2120 {
22- OnConnect += ( e ) =>
23- {
24- new Connected { identity = e . Sender } . Insert ( ) ;
25- } ;
21+ new Connected { identity = e . Sender } . Insert ( ) ;
22+ }
2623
27- OnDisconnect += ( e ) =>
28- {
29- new Disconnected { identity = e . Sender } . Insert ( ) ;
30- } ;
24+ [ SpacetimeDB . Reducer ( ReducerKind . Disconnect ) ]
25+ public static void OnDisconnect ( DbEventArgs e )
26+ {
27+ new Disconnected { identity = e . Sender } . Insert ( ) ;
3128 }
3229
3330 [ SpacetimeDB . Reducer ]
You can’t perform that action at this time.
0 commit comments