mirror of https://github.com/Squidex/squidex.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
56 lines
1.5 KiB
56 lines
1.5 KiB
// ==========================================================================
|
|
// Squidex Headless CMS
|
|
// ==========================================================================
|
|
// Copyright (c) Squidex UG (haftungsbeschraenkt)
|
|
// All rights reserved. Licensed under the MIT license.
|
|
// ==========================================================================
|
|
|
|
using Squidex.Infrastructure.EventSourcing;
|
|
|
|
namespace Squidex.Infrastructure.States
|
|
{
|
|
public static class Save
|
|
{
|
|
public static SnapshotInstance<T> Snapshot<T>(T initial)
|
|
{
|
|
return new SnapshotInstance<T>(initial);
|
|
}
|
|
|
|
public static EventsInstance Events(int keep = int.MaxValue)
|
|
{
|
|
return new EventsInstance(keep);
|
|
}
|
|
|
|
public sealed class SnapshotInstance<T>
|
|
{
|
|
public T Value { get; set; }
|
|
|
|
public HandleSnapshot<T> Write { get; }
|
|
|
|
public SnapshotInstance(T initial)
|
|
{
|
|
Value = initial;
|
|
|
|
Write = (state, _) =>
|
|
{
|
|
Value = state;
|
|
};
|
|
}
|
|
}
|
|
|
|
public sealed class EventsInstance : List<IEvent>
|
|
{
|
|
public HandleEvent Write { get; }
|
|
|
|
public EventsInstance(int keep = int.MaxValue)
|
|
{
|
|
Write = @event =>
|
|
{
|
|
Add(@event.Payload);
|
|
|
|
return Count < keep;
|
|
};
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|