@@ -318,8 +318,12 @@ var stateFactory = services.GetStateFactory();
318
318
options =>
319
319
{
320
320
options .WithUpdateDelayer (TimeSpan .FromSeconds (1 )); // 1 second update delay
321
- options .Invalidated += state => WriteLine ($" {DateTime .Now }: Invalidated, Computed: {state .Computed }" );
322
- options .Updated += state => WriteLine ($" {DateTime .Now }: Updated, Value: {state .Value }, Computed: {state .Computed }" );
321
+ options .EventConfigurator += state1 =>
322
+ {
323
+ // A shortcut to attach 3 event handlers: Invalidated, Updating, Updated
324
+ state1 .AddEventHandler (StateEventKind .All ,
325
+ (s , e ) => WriteLine ($" {DateTime .Now }: {e }, Value: {s .Value }, Computed: {s .Computed }" ));
326
+ };
323
327
},
324
328
async (state , cancellationToken ) =>
325
329
{
@@ -339,22 +343,25 @@ The output:
339
343
340
344
``` text
341
345
Host started.
342
- 9/4/2020 9:41:49 PM: Updated, Value: , Computed: StateBoundComputed`1(FuncLiveState`1(#49967061) @26, State: Consistent)
343
- 9/4/2020 9:41:49 PM: Invalidated, Computed: StateBoundComputed`1(FuncLiveState`1(#49967061) @26, State: Invalidated)
346
+ 10/2/2020 6:27:48 AM: Updated, Value: , Computed: StateBoundComputed`1(FuncLiveState`1(#38338487) @26, State: Consistent)
347
+ 10/2/2020 6:27:48 AM: Invalidated, Value: , Computed: StateBoundComputed`1(FuncLiveState`1(#38338487) @26, State: Invalidated)
348
+ 10/2/2020 6:27:48 AM: Updating, Value: , Computed: StateBoundComputed`1(FuncLiveState`1(#38338487) @26, State: Invalidated)
344
349
CounterController.GetAsync(a)
345
350
GetAsync(a)
346
- 9/4 /2020 9:41:49 PM : Updated, Value: counters.GetAsync(a) -> 0, Computed: StateBoundComputed`1(FuncLiveState`1(#49967061 ) @4a, State: Consistent)
351
+ 10/2 /2020 6:27:48 AM : Updated, Value: counters.GetAsync(a) -> 0, Computed: StateBoundComputed`1(FuncLiveState`1(#38338487 ) @4a, State: Consistent)
347
352
CounterController.IncrementAsync(a)
348
353
IncrementAsync(a)
349
- 9/4/2020 9:41:49 PM: Invalidated, Computed: StateBoundComputed`1(FuncLiveState`1(#49967061) @4a, State: Invalidated)
354
+ 10/2/2020 6:27:48 AM: Invalidated, Value: counters.GetAsync(a) -> 0, Computed: StateBoundComputed`1(FuncLiveState`1(#38338487) @4a, State: Invalidated)
355
+ 10/2/2020 6:27:49 AM: Updating, Value: counters.GetAsync(a) -> 0, Computed: StateBoundComputed`1(FuncLiveState`1(#38338487) @4a, State: Invalidated)
350
356
GetAsync(a)
351
- 9/4 /2020 9:41 :50 PM : Updated, Value: counters.GetAsync(a) -> 1, Computed: StateBoundComputed`1(FuncLiveState`1(#49967061 ) @2o , State: Consistent)
357
+ 10/2 /2020 6:27 :50 AM : Updated, Value: counters.GetAsync(a) -> 1, Computed: StateBoundComputed`1(FuncLiveState`1(#38338487 ) @6h , State: Consistent)
352
358
CounterController.SetOffsetAsync(10)
353
359
SetOffsetAsync(10)
354
- 9/4/2020 9:41:51 PM: Invalidated, Computed: StateBoundComputed`1(FuncLiveState`1(#49967061) @2o, State: Invalidated)
360
+ 10/2/2020 6:27:50 AM: Invalidated, Value: counters.GetAsync(a) -> 1, Computed: StateBoundComputed`1(FuncLiveState`1(#38338487) @6h, State: Invalidated)
361
+ 10/2/2020 6:27:51 AM: Updating, Value: counters.GetAsync(a) -> 1, Computed: StateBoundComputed`1(FuncLiveState`1(#38338487) @6h, State: Invalidated)
355
362
GetAsync(a)
356
- 9/4 /2020 9:41:52 PM : Updated, Value: counters.GetAsync(a) -> 11, Computed: StateBoundComputed`1(FuncLiveState`1(#49967061 ) @4q , State: Consistent)
357
- 9/4 /2020 9:41:53 PM : Invalidated, Computed: StateBoundComputed`1(FuncLiveState`1(#49967061 ) @4q , State: Invalidated)
363
+ 10/2 /2020 6:27:51 AM : Updated, Value: counters.GetAsync(a) -> 11, Computed: StateBoundComputed`1(FuncLiveState`1(#38338487 ) @ap , State: Consistent)
364
+ 10/2 /2020 6:27:52 AM : Invalidated, Value: counters.GetAsync(a) -> 11, Computed: StateBoundComputed`1(FuncLiveState`1(#38338487 ) @ap , State: Invalidated)
358
365
```
359
366
360
367
As you might guess, this is exactly the logic out Blazor samples use to update
0 commit comments