Skip to content

Commit

Permalink
Merge pull request #22 from canhorn/feature/action_result_callbacks
Browse files Browse the repository at this point in the history
Action Result Callbacks
  • Loading branch information
canhorn authored Jun 27, 2021
2 parents a4e94d6 + 6d075dc commit 1118194
Show file tree
Hide file tree
Showing 22 changed files with 1,038 additions and 16 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
using System.Text.Json.Serialization;

namespace EventHorizon.Blazor.Interop.Sample.Pages.Testing.InteropTesting.Model
{
[JsonConverter(typeof(CachedEntityConverter<TestClass>))]
public class TestClass : CachedEntity
{
public bool Found
{
get
{
return EventHorizonBlazorInterop.Get<bool>(
this.___guid,
"found"
);
}
set
{
EventHorizonBlazorInterop.Set(
this.___guid,
"found",
value
);
}
}

public string Arg1
{
get
{
return EventHorizonBlazorInterop.Get<string>(
this.___guid,
"arg1"
);
}
set
{
EventHorizonBlazorInterop.Set(
this.___guid,
"arg1",
value
);
}
}

public TestClass()
{
var cachedEntity = EventHorizonBlazorInterop.New(
new string[] { "Vector3" },
1,
2,
3
);
___guid = cachedEntity.___guid;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
@page "/result-callback/validation"

<h1>Interop Result Callback Validation Testing</h1>

<div class="testing-content">
<InteropResultCallbackValidationTest />
<InteropResultClassCallbackValidationTest />
<InteropResultArrayCallbackValidationTest />
<InteropResultArrayClassCallbackValidationTest />
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<div>
<h3>Array Result Callback Validation</h3>
<div class="--lighter">Interop FuncArray</div>
<div>
Status:
@if (TestStatus == "Passed")
{
<span class="green-badge">@TestStatus</span>
}
else if (TestStatus == "Failed")
{
<span class="red-badge">@TestStatus</span>
}
else
{
<span>@TestStatus</span>
}
</div>
<button class="run-btn" @onclick="HandleRunTest">Run</button>
</div>

<script suppress-error="BL9992">(function () {
const callbackActions = [];
window["InteropResultArrayCallbackValidationTest"] = {
trigger: (returnResult, predicate) => {
return predicate(returnResult);
}
};
})();</script>

@code {
public string TestStatus = "Pending";

private string testId => "InteropResultArrayCallbackValidationTest";
private bool initialized = false;

private void HandleRunTest()
{
TestStatus = "Running...";
if (!initialized)
{
var expectedArg = "testing-returned-result";
var actionHandler = new ActionResultCallback<string, string[]>((arg1) =>
{
if (arg1 == expectedArg)
{
return new[] { "found", arg1 };
}
return new[] { "found-found", arg1 };
});


var result = EventHorizonBlazorInterop.FuncArray<string>(
new string[] { testId, "trigger" },
expectedArg,
actionHandler
);
initialized = true;
TestStatus = "Failed";
if (result[0] == "found"
&& result[1] == expectedArg)
{
TestStatus = "Passed";
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<div>
<h3>Array Class Result Callback Validation</h3>
<div class="--lighter">Interop FuncArrayClass</div>
<div>
Status:
@if (TestStatus == "Passed")
{
<span class="green-badge">@TestStatus</span>
}
else if (TestStatus == "Failed")
{
<span class="red-badge">@TestStatus</span>
}
else
{
<span>@TestStatus</span>
}
</div>
<button class="run-btn" @onclick="HandleRunTest">Run</button>
</div>

<script suppress-error="BL9992">(function () {
const callbackActions = [];
window["InteropResultArrayClassCallbackValidationTest"] = {
trigger: (returnResult, predicate) => {
return predicate(returnResult);
}
};
})();</script>

@code {
public string TestStatus = "Pending";

private string testId => "InteropResultArrayClassCallbackValidationTest";
private bool initialized = false;

private void HandleRunTest()
{
TestStatus = "Running...";
if (!initialized)
{
var expectedArg = "testing-returned-result";
var actionHandler = new ActionResultCallback<string, TestClass[]>((arg1) =>
{
if (arg1 == expectedArg)
{
return new[] {
new TestClass { Found = true, Arg1 = arg1 },
new TestClass { Found = true, Arg1 = arg1 },
};
}
return new TestClass[0];
});


var result = EventHorizonBlazorInterop.FuncArrayClass<TestClass>(
entity => new TestClass { ___guid = entity.___guid },
new string[] { testId, "trigger" },
expectedArg,
actionHandler
);
initialized = true;
TestStatus = "Failed";
if (result[0].Found
&& result[0].Arg1 == expectedArg)
{
TestStatus = "Passed";
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<div>
<h3>Primitive Result Callback Validation</h3>
<div class="--lighter">Interop Func</div>
<div>
Status:
@if (TestStatus == "Passed")
{
<span class="green-badge">@TestStatus</span>
}
else if (TestStatus == "Failed")
{
<span class="red-badge">@TestStatus</span>
}
else
{
<span>@TestStatus</span>
}
</div>
<button class="run-btn" @onclick="HandleRunTest">Run</button>
</div>

<script suppress-error="BL9992">(function () {
const callbackActions = [];
window["InteropResultCallbackValidationTest"] = {
trigger: (returnResult, predicate) => {
return predicate(returnResult);
}
};
})();</script>

@code {
public string TestStatus = "Pending";

private string testId => "InteropResultCallbackValidationTest";
private bool initialized = false;

private void HandleRunTest()
{
TestStatus = "Running...";
if (!initialized)
{
var expectedArg = "testing-returned-result";
var actionHandler = new ActionResultCallback<string, string>((arg1) =>
{
if (arg1 == expectedArg)
{
return "found";
}
return "found-found";
});


var result = EventHorizonBlazorInterop.Func<string>(
new string[] { testId, "trigger" },
expectedArg,
actionHandler
);
initialized = true;
TestStatus = "Failed";
if (result == "found")
{
TestStatus = "Passed";
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<div>
<h3>Class Result Callback Validation</h3>
<div class="--lighter">Interop Func</div>
<div>
Status:
@if (TestStatus == "Passed")
{
<span class="green-badge">@TestStatus</span>
}
else if (TestStatus == "Failed")
{
<span class="red-badge">@TestStatus</span>
}
else
{
<span>@TestStatus</span>
}
</div>
<button class="run-btn" @onclick="HandleRunTest">Run</button>
</div>

<script suppress-error="BL9992">(function () {
const callbackActions = [];
window["InteropResultClassCallbackValidationTest"] = {
trigger: (returnResult, predicate) => {
return predicate(returnResult);
}
};
})();</script>

@code {
public string TestStatus = "Pending";

private string testId => "InteropResultClassCallbackValidationTest";
private bool initialized = false;

private async Task HandleRunTest()
{
TestStatus = "Running...";
if (!initialized)
{
var expectedArg = "testing-returned-result";
var actionHandler = new ActionResultCallback<string, TestClass>((arg1) =>
{
if (arg1 == expectedArg)
{
return new TestClass { Found = true, Arg1 = arg1 };
}

return new TestClass { Found = false };
});


var result = EventHorizonBlazorInterop.FuncClass<TestClass>(
entity => new TestClass { ___guid = entity.___guid },
new string[] { testId, "trigger" },
expectedArg,
actionHandler
);
initialized = true;
TestStatus = "Failed";

if (result.Found
&& result.Arg1 == expectedArg)
{
TestStatus = "Passed";
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
@using EventHorizon.Blazor.Interop.Sample.Pages.Testing.InteropTesting.ResultCallback.Validation
@using EventHorizon.Blazor.Interop.ResultCallbacks
1 change: 1 addition & 0 deletions EventHorizon.Blazor.Interop.Sample/Shared/MainLayout.razor
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
<a href="/interop/validations">Interop Validation</a>
<a href="/callback/performance">Callback Testing</a>
<a href="/callback/validation">Callback Validation</a>
<a href="/result-callback/validation">Result Callback Validation</a>
<a href="/promise/performance">Promise Performance</a>
<a href="https://github.com/canhorn/EventHorizon.Blazor.Interop" target="_blank" class="ml-md-auto">Repository</a>
</div>
Expand Down
3 changes: 3 additions & 0 deletions EventHorizon.Blazor.Interop.Sample/wwwroot/Bridge.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
}
};

var TestClass = function () {
};

var Vector3 = function (x, y, z) {
this.x = x;
this.y = y;
Expand Down
Loading

0 comments on commit 1118194

Please sign in to comment.