Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not use ImmutableList for Events collections #113

Merged
merged 1 commit into from
May 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/EventLogExpert/MainPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ private void OpenEventLogFile(string fileName)
fileName,
EventLogState.LogType.File)));


Utils.UpdateAppTitle(fileName);
}

Expand Down
16 changes: 8 additions & 8 deletions src/EventLogExpert/Store/EventLog/EventLogReducers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ public static EventLogState ReduceAddEvent(EventLogState state, EventLogAction.A

if (state.ContinuouslyUpdate)
{
newState = newState with { Events = newEvent.Concat(state.Events).ToImmutableList() };
newState = newState with { Events = newEvent.Concat(state.Events).ToList().AsReadOnly() };
}
else
{
var updatedBuffer = newEvent.Concat(state.NewEventBuffer.Events).ToImmutableList();
var updatedBuffer = newEvent.Concat(state.NewEventBuffer.Events).ToList().AsReadOnly();
var full = updatedBuffer.Count >= MaxNewEvents;
newState = newState with { NewEventBuffer = new(updatedBuffer, full) };

Expand All @@ -46,19 +46,19 @@ public static EventLogState ReduceAddEvent(EventLogState state, EventLogAction.A

[ReducerMethod(typeof(EventLogAction.ClearEvents))]
public static EventLogState ReduceClearEvents(EventLogState state) =>
state with { Events = ImmutableList<DisplayEventModel>.Empty };
state with { Events = new List<DisplayEventModel>().AsReadOnly() };

[ReducerMethod]
public static EventLogState ReduceLoadEvents(EventLogState state, EventLogAction.LoadEvents action) =>
state with { Events = action.Events.ToImmutableList(), Watcher = action.Watcher };
state with { Events = action.Events.ToList().AsReadOnly(), Watcher = action.Watcher };

[ReducerMethod]
public static EventLogState ReduceLoadNewEvents(EventLogState state, EventLogAction.LoadNewEvents action)
{
var newState = state with
{
Events = state.NewEventBuffer.Events.Concat(state.Events).ToImmutableList(),
NewEventBuffer = new(ImmutableList<DisplayEventModel>.Empty, false)
Events = state.NewEventBuffer.Events.Concat(state.Events).ToList().AsReadOnly(),
NewEventBuffer = new(new List<DisplayEventModel>().AsReadOnly(), false)
};

if (state.Watcher != null && !state.Watcher.IsWatching)
Expand Down Expand Up @@ -93,8 +93,8 @@ public static EventLogState ReduceSetContinouslyUpdate(EventLogState state, Even
{
newState = newState with
{
Events = state.NewEventBuffer.Events.Concat(state.Events).ToImmutableList(),
NewEventBuffer = new(ImmutableList<DisplayEventModel>.Empty, false)
Events = state.NewEventBuffer.Events.Concat(state.Events).ToList().AsReadOnly(),
NewEventBuffer = new(new List<DisplayEventModel>().AsReadOnly(), false)
};
}

Expand Down
7 changes: 4 additions & 3 deletions src/EventLogExpert/Store/EventLog/EventLogState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@
using EventLogExpert.Library.Models;
using Fluxor;
using System.Collections.Immutable;
using System.Collections.ObjectModel;

namespace EventLogExpert.Store.EventLog;

[FeatureState]
public record EventLogState
{
public record EventBuffer(ImmutableList<DisplayEventModel> Events, bool IsBufferFull);
public record EventBuffer(ReadOnlyCollection<DisplayEventModel> Events, bool IsBufferFull);

public record LogSpecifier(string Name, LogType? LogType);

Expand All @@ -20,9 +21,9 @@ public enum LogType { Live, File }

public bool ContinuouslyUpdate { get; init; } = false;

public ImmutableList<DisplayEventModel> Events { get; init; } = ImmutableList<DisplayEventModel>.Empty;
public ReadOnlyCollection<DisplayEventModel> Events { get; init; } = new List<DisplayEventModel>().AsReadOnly();

public EventBuffer NewEventBuffer { get; init; } = new (ImmutableList<DisplayEventModel>.Empty, false);
public EventBuffer NewEventBuffer { get; init; } = new (new List<DisplayEventModel>().AsReadOnly(), false);

public DisplayEventModel? SelectedEvent { get; init; }

Expand Down