Skip to content

Commit

Permalink
Testing fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Mike-E-angelo committed Mar 20, 2024
1 parent 71c04cf commit ca3121c
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 7 deletions.
7 changes: 6 additions & 1 deletion DragonSpark.Application/Entities/Editing/CommitAwareEdits.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@

namespace DragonSpark.Application.Entities.Editing;

sealed class CommitAwareEdits<TIn, T> : IEdit<TIn, T>
public class CommitAwareEdits<T> : CommitAwareEdits<T, T>
{
protected CommitAwareEdits(IScopes scopes) : base(scopes, Start.A.Selection<T>().By.Self.Operation().Out()) {}
}

public class CommitAwareEdits<TIn, T> : IEdit<TIn, T>
{
readonly IScopes _scopes;
readonly ISelecting<TIn, T> _select;
Expand Down
50 changes: 46 additions & 4 deletions DragonSpark.Application/Entities/Editing/EditExisting.cs
Original file line number Diff line number Diff line change
@@ -1,21 +1,63 @@
using DragonSpark.Compose;
using DragonSpark.Model.Operations.Selection;
using DragonSpark.Model.Commands;
using DragonSpark.Model.Operations;
using System;
using System.Threading.Tasks;

namespace DragonSpark.Application.Entities.Editing;

public class EditExisting<T> : ISelecting<T, Edit<T>> where T : class
public class EditExisting<T> : IEdit<T> where T : class
{
readonly IScopes _scopes;
readonly bool _reload;

protected EditExisting(IScopes scopes) => _scopes = scopes;
protected EditExisting(IScopes scopes, bool reload = true)
{
_scopes = scopes;
_reload = reload;
}

public async ValueTask<Edit<T>> Get(T parameter)
{
var (context, disposable) = _scopes.Get();
var editor = new Editor(context, await disposable.Await());
editor.Attach(parameter);
await context.Entry(parameter).ReloadAsync().ConfigureAwait(false);
if (_reload)
{
await context.Entry(parameter).ReloadAsync().ConfigureAwait(false);
}

return new(editor, parameter);
}
}

// TODO

public class ModifyExisting<T> : IOperation<T>
{
readonly IEdit<T> _edit;
readonly IOperation<Edit<T>> _modify;

protected ModifyExisting(IEdit<T> edit, ICommand<Edit<T>> modify) : this(edit, modify.Then().Operation().Out()) {}

protected ModifyExisting(IEdit<T> edit, ICommand<T> modify)
: this(edit, Start.A.Selection<Edit<T>>().By.Calling(x => x.Subject).Terminate(modify).Operation().Out()) {}

protected ModifyExisting(IEdit<T> edit, Action<T> modify) : this(edit, Start.A.Command(modify).Get()) {}

protected ModifyExisting(IEdit<T> edit, IOperation<T> modify)
: this(edit, Start.A.Selection<Edit<T>>().By.Calling(x => x.Subject).Select(modify).Out()) {}

protected ModifyExisting(IEdit<T> edit, IOperation<Edit<T>> modify)
{
_edit = edit;
_modify = modify;
}

public async ValueTask Get(T parameter)
{
using var edit = await _edit.Await(parameter);
await _modify.Await(edit);
await edit.Await();
}
}
2 changes: 2 additions & 0 deletions DragonSpark.Application/Entities/Editing/IEdit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@

namespace DragonSpark.Application.Entities.Editing;

public interface IEdit<T> : IEdit<T, T>;

public interface IEdit<in TIn, T> : ISelecting<TIn, Edit<T>>;
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public EvaluateToAny(IReading<None, T> reading) : base(reading) {}
public class EvaluateToAny<TIn, T> : Evaluate<TIn, T, bool>, IDepending<TIn>
{
public EvaluateToAny(IScopes scopes, Expression<Func<DbContext, TIn, IQueryable<T>>> expression)
: this(new Reading<TIn, T>(scopes, (d, @in) => expression.Invoke(d, @in).Take(1))) {}
: this(new Reading<TIn, T>(scopes, (d, @in) => expression.Invoke(d, @in))) {}

protected EvaluateToAny(IReading<TIn, T> reading) : base(reading, ToAny<T>.Default) {}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using DragonSpark.Application.Connections.Events;
using DragonSpark.Application.Runtime;
using DragonSpark.Compose;
using DragonSpark.Model;
using DragonSpark.Model.Operations;
using Microsoft.AspNetCore.Components;
using System;
using System.Threading.Tasks;
Expand All @@ -10,19 +12,26 @@ namespace DragonSpark.Presentation.Components.State;
public abstract class SubscriptionComponent<T> : ComponentBase, IAsyncDisposable where T : notnull
{
ISubscription? _connection;
IOperation<T> _operation = null!;

[Parameter]
public EventCallback<T> Received { get; set; }

[Parameter]
public TimeSpan Throttle { get; set; } = TimeSpan.FromMilliseconds(250);

protected override Task OnInitializedAsync()
{
_operation = new ThrottleOperation<T>(Fire, Throttle);
_connection = DetermineSubscription();
return _connection.Allocate();
}

protected abstract ISubscription DetermineSubscription();

protected virtual Task OnReceive(T parameter) => InvokeAsync(() => Received.InvokeAsync(parameter));
protected virtual Task OnReceive(T parameter) => _operation.Get(parameter).AsTask();

Task Fire(T parameter) => InvokeAsync(() => Received.InvokeAsync(parameter));

public ValueTask DisposeAsync() => _connection?.DisposeAsync() ?? Task.CompletedTask.ToOperation();
}
Expand Down
14 changes: 14 additions & 0 deletions DragonSpark.Presentation/Model/Selections.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
using DragonSpark.Model;
using DragonSpark.Model.Results;
using Microsoft.AspNetCore.Components;
using System.Collections.Generic;
using System.Threading.Tasks;

namespace DragonSpark.Presentation.Model;

Expand All @@ -10,4 +13,15 @@ public Selections() {}
public Selections(IEnumerable<SelectionListing<T>> collection) : base(collection) {}

public IEnumerable<T> Selected { get; set; } = Empty.Enumerable<T>();
}

// TODO

public sealed class Signal : Variable<EventCallback?>
{
public Task Fire()
{
var callback = Get();
return callback is not null ? callback.Value.InvokeAsync() : Task.CompletedTask;
}
}

0 comments on commit ca3121c

Please sign in to comment.