-
Notifications
You must be signed in to change notification settings - Fork 2
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 #22 from canhorn/feature/action_result_callbacks
Action Result Callbacks
- Loading branch information
Showing
22 changed files
with
1,038 additions
and
16 deletions.
There are no files selected for viewing
57 changes: 57 additions & 0 deletions
57
EventHorizon.Blazor.Interop.Sample/Pages/Testing/InteropTesting/Model/TestClass.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,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; | ||
} | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
...rop.Sample/Pages/Testing/InteropTesting/ResultCallback/ResultCallbackValidationPage.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,10 @@ | ||
@page "/result-callback/validation" | ||
|
||
<h1>Interop Result Callback Validation Testing</h1> | ||
|
||
<div class="testing-content"> | ||
<InteropResultCallbackValidationTest /> | ||
<InteropResultClassCallbackValidationTest /> | ||
<InteropResultArrayCallbackValidationTest /> | ||
<InteropResultArrayClassCallbackValidationTest /> | ||
</div> |
67 changes: 67 additions & 0 deletions
67
...g/InteropTesting/ResultCallback/Validation/InteropResultArrayCallbackValidationTest.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,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"; | ||
} | ||
} | ||
} | ||
} |
71 changes: 71 additions & 0 deletions
71
...eropTesting/ResultCallback/Validation/InteropResultArrayClassCallbackValidationTest.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,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"; | ||
} | ||
} | ||
} | ||
} |
66 changes: 66 additions & 0 deletions
66
...esting/InteropTesting/ResultCallback/Validation/InteropResultCallbackValidationTest.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,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"; | ||
} | ||
} | ||
} | ||
} |
70 changes: 70 additions & 0 deletions
70
...g/InteropTesting/ResultCallback/Validation/InteropResultClassCallbackValidationTest.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,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"; | ||
} | ||
} | ||
} | ||
} |
2 changes: 2 additions & 0 deletions
2
...tHorizon.Blazor.Interop.Sample/Pages/Testing/InteropTesting/ResultCallback/_Imports.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,2 @@ | ||
@using EventHorizon.Blazor.Interop.Sample.Pages.Testing.InteropTesting.ResultCallback.Validation | ||
@using EventHorizon.Blazor.Interop.ResultCallbacks |
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 |
---|---|---|
|
@@ -13,6 +13,9 @@ | |
} | ||
}; | ||
|
||
var TestClass = function () { | ||
}; | ||
|
||
var Vector3 = function (x, y, z) { | ||
this.x = x; | ||
this.y = y; | ||
|
Oops, something went wrong.