Skip to content

Commit 9083278

Browse files
committed
More efficent event score events
1 parent 802c7be commit 9083278

2 files changed

Lines changed: 5 additions & 10 deletions

File tree

PocketDDD.BlazorClient/PocketDDD.BlazorClient/Features/EventScore/Store/EventScoreEffects.cs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,11 @@ public class EventScoreEffects
99
{
1010
private readonly LocalStorageContext _localStorage;
1111

12-
public EventScoreEffects(LocalStorageContext localStorage)
12+
public EventScoreEffects(LocalStorageContext localStorage, IDispatcher dispatcher)
1313
{
1414
_localStorage = localStorage;
15+
_localStorage.EventScore.SubscribeToChanges(newScore =>
16+
dispatcher.Dispatch(new SetEventScoreAction(newScore)));
1517
}
1618

1719
[EffectMethod]
@@ -20,11 +22,4 @@ public async Task OnFetchExistingEventScore(FetchExistingEventScoreAction action
2022
var eventScore = await _localStorage.EventScore.GetOrDefaultAsync(() => 0);
2123
dispatcher.Dispatch(new SetEventScoreAction(eventScore));
2224
}
23-
24-
[EffectMethod]
25-
public async Task OnEventScoreUpdated(EventScoreUpdatedAction action, IDispatcher dispatcher)
26-
{
27-
await _localStorage.EventScore.SetAsync(action.Score);
28-
dispatcher.Dispatch(new SetEventScoreAction(action.Score));
29-
}
3025
}

PocketDDD.BlazorClient/PocketDDD.BlazorClient/Features/Sync/Store/SyncEffects.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ public async Task OnSyncEventFeedbackItems(SyncEventFeedbackItemsAction action,
101101
{
102102
var result = await _pocketDDDAPI.SubmitClientEventFeedback(item);
103103
await _localStorage.EventFeedbackSync.RemoveSyncItemAsync(result.ClientId);
104-
dispatcher.Dispatch(new EventScoreUpdatedAction(result.Score));
104+
await _localStorage.EventScore.SetAsync(result.Score);
105105
}
106106
catch
107107
{
@@ -129,7 +129,7 @@ public async Task OnSyncSessionFeedbackItems(SyncSessionFeedbackItemsAction acti
129129
{
130130
var result = await _pocketDDDAPI.SubmitClientSessionFeedback(item);
131131
await _localStorage.SessionFeedbackSync.RemoveSyncItemAsync(result.ClientId);
132-
dispatcher.Dispatch(new EventScoreUpdatedAction(result.Score));
132+
await _localStorage.EventScore.SetAsync(result.Score);
133133
}
134134
catch
135135
{

0 commit comments

Comments
 (0)