Skip to content

Commit e94c06a

Browse files
committed
Updates
1 parent 3f3a482 commit e94c06a

File tree

2 files changed

+14
-25
lines changed

2 files changed

+14
-25
lines changed

aspnetcore/blazor/javascript-interoperability/call-javascript-from-dotnet.md

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,7 @@ Create an instance of a JS object using a constructor function and get the <xref
468468
Examples in this section demonstrate the API calls with the following `TestClass` with a constructor function (`constructor(text)`):
469469

470470
```javascript
471-
class TestClass {
471+
window.TestClass = class {
472472
constructor(text) {
473473
this.text = text;
474474
}
@@ -477,18 +477,14 @@ class TestClass {
477477
return this.text.length;
478478
}
479479
}
480-
481-
window.jsInterop = {
482-
TestClass: TestClass
483-
};
484480
```
485481

486482
### Asynchronous `InvokeNewAsync`
487483

488-
Use `InvokeNewAsync(string identifier, object?[]? args)` on <xref:Microsoft.JSInterop.IJSRuntime> and <xref:Microsoft.JSInterop.IJSObjectReference> to invoke the specified JS constructor function asynchronously. The function is invoked with the `new` operator. In the following example, `jsInterop.TestClass` contains a constructor function, and `classRef` is an <xref:Microsoft.JSInterop.IJSObjectReference>.
484+
Use `InvokeNewAsync(string identifier, object?[]? args)` on <xref:Microsoft.JSInterop.IJSRuntime> and <xref:Microsoft.JSInterop.IJSObjectReference> to invoke the specified JS constructor function asynchronously. The function is invoked with the `new` operator. In the following example, `TestClass` contains a constructor function, and `classRef` is an <xref:Microsoft.JSInterop.IJSObjectReference>.
489485

490486
```csharp
491-
var classRef = await JSRuntime.InvokeNewAsync("jsInterop.TestClass", "Blazor!");
487+
var classRef = await JSRuntime.InvokeNewAsync("TestClass", "Blazor!");
492488
var text = await classRef.GetValueAsync<string>("text");
493489
var textLength = await classRef.InvokeAsync<int>("getTextLength");
494490
```
@@ -497,11 +493,11 @@ An overload is available that takes a <xref:System.Threading.CancellationToken>
497493

498494
### Synchronous `InvokeNew`
499495

500-
Use `InvokeNew(string identifier, object?[]? args)` on <xref:Microsoft.JSInterop.IJSInProcessRuntime> and <xref:Microsoft.JSInterop.IJSInProcessObjectReference> to invoke the specified JS constructor function synchronously. The function is invoked with the `new` operator. In the following example, `jsInterop.TestClass` contains a constructor function, and `classRef` is an <xref:Microsoft.JSInterop.IJSInProcessObjectReference>.
496+
Use `InvokeNew(string identifier, object?[]? args)` on <xref:Microsoft.JSInterop.IJSInProcessRuntime> and <xref:Microsoft.JSInterop.IJSInProcessObjectReference> to invoke the specified JS constructor function synchronously. The function is invoked with the `new` operator. In the following example, `TestClass` contains a constructor function, and `classRef` is an <xref:Microsoft.JSInterop.IJSInProcessObjectReference>.
501497

502498
```csharp
503499
var inProcRuntime = ((IJSInProcessRuntime)JSRuntime);
504-
var classRef = inProcRuntime.InvokeNew("jsInterop.TestClass", "Blazor!");
500+
var classRef = inProcRuntime.InvokeNew("TestClass", "Blazor!");
505501
var text = await classRef.GetValueAsync<string>("text");
506502
var textLength = await classRef.InvokeAsync<int>("getTextLength");
507503
```
@@ -518,29 +514,24 @@ Read or modify the value of a JS object property, both data and accessor propert
518514
Examples in this section demonstrate the API calls with the following JS object (`testObject`):
519515

520516
```javascript
521-
const testObject = {
517+
window.testObject = {
522518
num: 10
523519
}
524-
525-
window.jsInterop = {
526-
testObject: testObject
527-
};
528520
```
529521

530522
### Asynchronous `GetValueAsync` and `SetValueAsync`
531523

532524
Use `GetValueAsync<TValue>(string identifier)` to read the value of the specified JS property asynchronously. A <xref:Microsoft.JSInterop.JSException> is thrown if the property doesn't exist or is a `set`-only property.
533525

534526
```csharp
535-
var valueFromDataPropertyAsync = await JSRuntime.GetValueAsync<int>(
536-
"jsInterop.testObject.num");
527+
var valueFromDataPropertyAsync = await JSRuntime.GetValueAsync<int>("testObject.num");
537528
```
538529

539530
Use `SetValueAsync<TValue>(string identifier, TValue value)` to update the value of the specified JS property asynchronously. If the property isn't defined on the target object, the property is created. A <xref:Microsoft.JSInterop.JSException> is thrown if the property exists but isn't writable or when a new property can't be added to the object.
540531

541532
```csharp
542-
await JSRuntime.SetValueAsync("jsInterop.testObject.num", 20);
543-
await JSRuntime.SetValueAsync("jsInterop.testObject.num2", 30);
533+
await JSRuntime.SetValueAsync("testObject.num", 20);
534+
await JSRuntime.SetValueAsync("testObject.num2", 30);
544535
```
545536

546537
### Synchronous `GetValue` and `SetValue`
@@ -549,15 +540,15 @@ Use `GetValue<TValue>(string identifier)` to read the value of the specified JS
549540

550541
```csharp
551542
var inProcRuntime = ((IJSInProcessRuntime)JSRuntime);
552-
var valueFromDataProperty = inProcRuntime.GetValue<int>("jsInterop.testObject.num");
543+
var valueFromDataProperty = inProcRuntime.GetValue<int>("testObject.num");
553544
```
554545

555546
Use `SetValue<TValue>(string identifier, TValue value)` to update the value of the specified JS property synchronously. The property can't be a `get`-only property. If the property isn't defined on the target object, the property is created. A <xref:Microsoft.JSInterop.JSException> is thrown if the property exists but isn't writable or when a new property can't be added to the object.
556547

557548
```csharp
558549
var inProcRuntime = ((IJSInProcessRuntime)JSRuntime);
559-
inProcRuntime.SetValue("jsInterop.testObject.num", 20);
560-
inProcRuntime.SetValue("jsInterop.testObject.num2", 30);
550+
inProcRuntime.SetValue("testObject.num", 20);
551+
inProcRuntime.SetValue("testObject.num2", 30);
561552
```
562553

563554
:::moniker-end

aspnetcore/release-notes/aspnetcore-10/includes/blazor.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -307,16 +307,14 @@ The following asynchronous methods are available on <xref:Microsoft.JSInterop.IJ
307307
"jsInterop.testObject.num");
308308
```
309309
310-
* `SetValueAsync<TValue>(string identifier, TValue value)`: Updates the value of the specified JS property asynchronously. The property can't be a `get`-only property. If the property isn't defined on the target object, the property is created. In the following example, `num` is created on `testObject` with a value of 30 if it doesn't exist:
310+
* `SetValueAsync<TValue>(string identifier, TValue value)`: Updates the value of the specified JS property asynchronously. The property can't be a `get`-only property. If the property isn't defined on the target object, the property is created. A <xref:Microsoft.JSInterop.JSException> is thrown if the property exists but isn't writable or when a new property can't be added to the object. In the following example, `num` is created on `testObject` with a value of 30 if it doesn't exist:
311311
312312
```csharp
313313
await JSRuntime.SetValueAsync("jsInterop.testObject.num", 30);
314314
```
315315
316316
Overloads are available for each of the preceding methods that take a <xref:System.Threading.CancellationToken> argument or <xref:System.TimeSpan> timeout argument.
317317
318-
The special overload `IJSObjectReference.GetValueAsync<TValue>()` doesn't take an identifier and simply returns the value of the object (`TValue` is a model of the object's properties that the caller is interested in).
319-
320318
The following synchronous methods are available on <xref:Microsoft.JSInterop.IJSInProcessRuntime> and <xref:Microsoft.JSInterop.IJSInProcessObjectReference> with the same scoping behavior as the existing <xref:Microsoft.JSInterop.IJSInProcessObjectReference.Invoke%2A?displayProperty=nameWithType> method:
321319
322320
* `InvokeNew(string identifier, object?[]? args)`: Invokes the specified JS constructor function synchronously. The function is invoked with the `new` operator. In the following example, `jsInterop.TestClass` is a class with a constructor function, and `classRef` is an <xref:Microsoft.JSInterop.IJSInProcessObjectReference>:
@@ -336,7 +334,7 @@ The following synchronous methods are available on <xref:Microsoft.JSInterop.IJS
336334
"jsInterop.testObject.num");
337335
```
338336
339-
* `SetValue<TValue>(string identifier, TValue value)`: Updates the value of the specified JS property synchronously. The property can't be a `get`-only property. If the property isn't defined on the target object, the property is created. In the following example, `num` is created on `testObject` with a value of 20 if it doesn't exist:
337+
* `SetValue<TValue>(string identifier, TValue value)`: Updates the value of the specified JS property synchronously. The property can't be a `get`-only property. If the property isn't defined on the target object, the property is created. A <xref:Microsoft.JSInterop.JSException> is thrown if the property exists but isn't writable or when a new property can't be added to the object. In the following example, `num` is created on `testObject` with a value of 20 if it doesn't exist:
340338
341339
```csharp
342340
var inProcRuntime = ((IJSInProcessRuntime)JSRuntime);

0 commit comments

Comments
 (0)