-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #23 from WolderLabs/cleanup
Scaffold Interactive Web project
- Loading branch information
Showing
27 changed files
with
340 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
namespace Wolder.Core.Workspace.Events; | ||
|
||
public record InvocationBeginContext( | ||
IInvokable Invokable, object? Parameter) | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
namespace Wolder.Core.Workspace.Events; | ||
|
||
public record InvocationEndContext( | ||
IInvokable Invokable) | ||
{ | ||
|
||
} |
26 changes: 26 additions & 0 deletions
26
src/Wolder.Core/Workspace/Events/WorkspaceStateDelegateDispatcher.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
namespace Wolder.Core.Workspace.Events; | ||
|
||
public class WorkspaceStateEventDispatcher | ||
{ | ||
internal WorkspaceStateEvents Events { get; } | ||
public ICollection<WorkspaceStateEvents> Delegates { get; } = new List<WorkspaceStateEvents>(); | ||
|
||
public WorkspaceStateEventDispatcher() | ||
{ | ||
Events = new WorkspaceStateEvents() | ||
{ | ||
WorkspaceInitializedAsync = async () => | ||
await Task.WhenAll(Delegates.Select(d => | ||
d.WorkspaceInitializedAsync())), | ||
WorkspaceRunEndAsync = async () => | ||
await Task.WhenAll(Delegates.Select(d => | ||
d.WorkspaceRunEndAsync())), | ||
InvocationBeginAsync = async (c) => | ||
await Task.WhenAll(Delegates.Select(d => | ||
d.InvocationBeginAsync(c))), | ||
InvocationEndAsync = async (c) => | ||
await Task.WhenAll(Delegates.Select(d => | ||
d.InvocationEndAsync(c))), | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
namespace Wolder.Core.Workspace.Events; | ||
|
||
public class WorkspaceStateEvents | ||
{ | ||
public Func<Task> WorkspaceInitializedAsync { get; set; } = () => Task.CompletedTask; | ||
public Func<Task> WorkspaceRunEndAsync { get; set; } = () => Task.CompletedTask; | ||
public Func<InvocationBeginContext, Task> InvocationBeginAsync { get; set; } = (c) => Task.CompletedTask; | ||
public Func<InvocationEndContext, Task> InvocationEndAsync { get; set; } = (c) => Task.CompletedTask; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,30 @@ | ||
namespace Wolder.Core.Workspace; | ||
|
||
public interface IInvokable<in TParameter, TOutput> | ||
public interface IInvokable<in TParameter, TOutput> : IInvokable | ||
where TParameter : notnull | ||
{ | ||
Task<TOutput> InvokeAsync(); | ||
} | ||
|
||
public interface IInvokable<TOutput> | ||
public interface IInvokable<TOutput> : IInvokable | ||
{ | ||
Task<TOutput> InvokeAsync(); | ||
} | ||
|
||
public interface IVoidInvokable<in TParameter> | ||
public interface IVoidInvokable<in TParameter> : IInvokable | ||
where TParameter : notnull | ||
{ | ||
Task InvokeAsync(); | ||
} | ||
|
||
public interface IVoidInvokable | ||
public interface IVoidInvokable : IInvokable | ||
{ | ||
Task InvokeAsync(); | ||
} | ||
|
||
/// <summary> | ||
/// Marker interface | ||
/// </summary> | ||
public interface IInvokable | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
|
||
<head> | ||
<meta charset="utf-8"/> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"/> | ||
<base href="/"/> | ||
<link rel="stylesheet" href="Wolder.Interactive.Web.styles.css"/> | ||
<link rel="icon" type="image/png" href="favicon.png"/> | ||
<HeadOutlet/> | ||
</head> | ||
|
||
<body> | ||
<Routes /> | ||
<script src="_framework/blazor.web.js"></script> | ||
</body> | ||
|
||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<div class="my-component"> | ||
This component is defined in the <strong>Wolder.Interactive.Web</strong> library. | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
.my-component { | ||
border: 2px dashed red; | ||
padding: 1em; | ||
margin: 1em 0; | ||
background-image: url('background.png'); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
@page "/" | ||
@using Wolder.Interactive.Web.Services | ||
|
||
@inject WorkspaceStateManager WorkspaceStateManager; | ||
|
||
@rendermode InteractiveServer | ||
|
||
<h3>Wolder Interactive</h3> | ||
|
||
<div> | ||
<button @onclick="WorkspaceStateManager.Pause">Pause</button> | ||
<button @onclick="WorkspaceStateManager.Resume">Resume</button> | ||
<button @onclick="WorkspaceStateManager.Step">Step</button> | ||
</div> | ||
|
||
@code { | ||
|
||
} |
9 changes: 9 additions & 0 deletions
9
src/Wolder.Interactive.Web/Components/Layout/MainLayout.razor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
@inherits LayoutComponentBase | ||
|
||
<main> | ||
@Body | ||
</main> | ||
|
||
@code { | ||
|
||
} |
5 changes: 5 additions & 0 deletions
5
src/Wolder.Interactive.Web/Components/Layout/MainLayout.razor.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
| ||
main { | ||
font-family: monospace; | ||
text-align: center; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<Router AppAssembly="typeof(App).Assembly"> | ||
<Found Context="routeData"> | ||
<RouteView RouteData="routeData" DefaultLayout="typeof(Layout.MainLayout)"/> | ||
<FocusOnNavigate RouteData="routeData" Selector="h1"/> | ||
</Found> | ||
</Router> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
namespace Wolder.Interactive.Web.Models; | ||
|
||
public record InvocationDetail(string Name); |
65 changes: 65 additions & 0 deletions
65
src/Wolder.Interactive.Web/Services/WorkspaceStateManager.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
using Wolder.Core.Workspace.Events; | ||
using Wolder.Interactive.Web.Models; | ||
|
||
namespace Wolder.Interactive.Web.Services; | ||
|
||
public class WorkspaceStateManager | ||
{ | ||
private TaskCompletionSource _proceedWhenUnpaused = new(); // Start paused | ||
|
||
public WorkspaceStateManager() | ||
{ | ||
Events = new() | ||
{ | ||
WorkspaceInitializedAsync = WorkspaceInitializedAsync, | ||
WorkspaceRunEndAsync = WorkspaceRunEndAsync, | ||
InvocationBeginAsync = InvocationBeginAsync, | ||
InvocationEndAsync = InvocationEndAsync, | ||
}; | ||
} | ||
|
||
internal WorkspaceStateEvents Events { get; } | ||
|
||
public void Pause() | ||
{ | ||
_proceedWhenUnpaused = new TaskCompletionSource(); | ||
} | ||
|
||
public void Resume() | ||
{ | ||
_proceedWhenUnpaused.TrySetResult(); | ||
} | ||
|
||
public void Step() | ||
{ | ||
var prevTcs = _proceedWhenUnpaused; | ||
_proceedWhenUnpaused = new TaskCompletionSource(); | ||
prevTcs.TrySetResult(); | ||
} | ||
|
||
public event Action<InvocationDetail>? InvocationBegin; | ||
public event Action? WorkspaceInitialized; | ||
|
||
private async Task WorkspaceInitializedAsync() | ||
{ | ||
WorkspaceInitialized?.Invoke(); | ||
await _proceedWhenUnpaused.Task; | ||
} | ||
|
||
private async Task InvocationBeginAsync(InvocationBeginContext c) | ||
{ | ||
InvocationBegin?.Invoke(new InvocationDetail(c.Invokable.GetType().Name)); | ||
await _proceedWhenUnpaused.Task; | ||
} | ||
|
||
private async Task WorkspaceRunEndAsync() | ||
{ | ||
Pause(); | ||
await _proceedWhenUnpaused.Task; | ||
} | ||
|
||
private Task InvocationEndAsync(InvocationEndContext c) | ||
{ | ||
return Task.CompletedTask; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Wolder.Core.Workspace; | ||
|
||
namespace Wolder.Interactive.Web; | ||
|
||
public static class GeneratorWorkspaceBuilderExtensions | ||
{ | ||
public static GeneratorWorkspaceBuilder AddInteractiveWebServer(this GeneratorWorkspaceBuilder builder) | ||
{ | ||
var server = new WorkspaceInteractiveWebHost(); | ||
builder.Services.AddSingleton(server); | ||
builder.EventDispatcher.Delegates.Add(server.WorkspaceStateManager.Events); | ||
return builder; | ||
} | ||
} |
Oops, something went wrong.