Skip to content

Commit 571106f

Browse files
committed
Add sample test showcasing using object references to functions as values
1 parent 98a24a7 commit 571106f

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

src/Components/test/testassets/BasicTestApp/DotNetToJSInterop.razor

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@
9292
<div style="margin-top: 2em">
9393
<button @onclick="CreateInstanceByConstructorFunction">Call constructor function InvokeNewAsync</button>
9494
<button @onclick="CreateInstanceByClassConstructor">Call class constructor with InvokeNewAsync</button>
95+
<button @onclick="ChangeInstanceMethodWithFunctionReference">Change instance method with function reference</button>
9596
<span>@InstanceMessage</span>
9697
</div>
9798

@@ -146,13 +147,13 @@
146147

147148
private async Task CreateInstanceByConstructorFunction()
148149
{
149-
var dogRef = await JSRuntime.InvokeNewAsync("Dog", ["Igor"]);
150+
var dogRef = await JSRuntime.InvokeNewAsync("Dog", "A dog");
150151
InstanceMessage = await dogRef.InvokeAsync<string>("bark");
151152
}
152153

153154
private async Task CreateInstanceByClassConstructor()
154155
{
155-
var catRef = await JSRuntime.InvokeNewAsync("Cat", ["Whiskers"]);
156+
var catRef = await JSRuntime.InvokeNewAsync("Cat", "A cat");
156157
InstanceMessage = await catRef.InvokeAsync<string>("meow");
157158
}
158159

@@ -166,6 +167,15 @@
166167
await JSRuntime.SetValueAsync<int>("testObject.getOnlyProperty", 123);
167168
}
168169

170+
private async Task ChangeInstanceMethodWithFunctionReference()
171+
{
172+
var dogRef = await JSRuntime.InvokeNewAsync("Dog", "A dog");
173+
var dogFuncRef = await dogRef.GetValueAsync<IJSObjectReference>("bark");
174+
var catRef = await JSRuntime.InvokeNewAsync("Cat", "A cat");
175+
await catRef.SetValueAsync("meow", dogFuncRef);
176+
InstanceMessage = await catRef.InvokeAsync<string>("meow");
177+
}
178+
169179
class TestObjectModel
170180
{
171181
public int Num { get; set; }

0 commit comments

Comments
 (0)