You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: aspnetcore/blazor/advanced-scenarios.md
+5-5Lines changed: 5 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -63,10 +63,10 @@ When a circuit ends because a user has disconnected and the framework is cleanin
63
63
64
64
## Manual RenderTreeBuilder logic
65
65
66
-
`Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder` provides methods for manipulating components and elements, including building components manually in C# code.
66
+
<xref:Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder> provides methods for manipulating components and elements, including building components manually in C# code.
67
67
68
68
> [!NOTE]
69
-
> Use of `RenderTreeBuilder` to create components is an advanced scenario. A malformed component (for example, an unclosed markup tag) can result in undefined behavior.
69
+
> Use of <xref:Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder> to create components is an advanced scenario. A malformed component (for example, an unclosed markup tag) can result in undefined behavior.
70
70
71
71
Consider the following `PetDetails` component, which can be manually built into another component:
72
72
@@ -82,7 +82,7 @@ Consider the following `PetDetails` component, which can be manually built into
82
82
}
83
83
```
84
84
85
-
In the following example, the loop in the `CreateComponent` method generates three `PetDetails` components. When calling `RenderTreeBuilder` methods to create the components (`OpenComponent` and `AddAttribute`), sequence numbers are source code line numbers. The Blazor difference algorithm relies on the sequence numbers corresponding to distinct lines of code, not distinct call invocations. When creating a component with `RenderTreeBuilder` methods, hardcode the arguments for sequence numbers. **Using a calculation or counter to generate the sequence number can lead to poor performance.** For more information, see the [Sequence numbers relate to code line numbers and not execution order](#sequence-numbers-relate-to-code-line-numbers-and-not-execution-order) section.
85
+
In the following example, the loop in the `CreateComponent` method generates three `PetDetails` components. When calling <xref:Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder> methods to create the components (`OpenComponent` and `AddAttribute`), sequence numbers are source code line numbers. The Blazor difference algorithm relies on the sequence numbers corresponding to distinct lines of code, not distinct call invocations. When creating a component with <xref:Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder> methods, hardcode the arguments for sequence numbers. **Using a calculation or counter to generate the sequence number can lead to poor performance.** For more information, see the [Sequence numbers relate to code line numbers and not execution order](#sequence-numbers-relate-to-code-line-numbers-and-not-execution-order) section.
86
86
87
87
`BuiltContent` component:
88
88
@@ -118,7 +118,7 @@ In the following example, the loop in the `CreateComponent` method generates thr
118
118
```
119
119
120
120
> [!WARNING]
121
-
> The types in `Microsoft.AspNetCore.Components.RenderTree` allow processing of the *results* of rendering operations. These are internal details of the Blazor framework implementation. These types should be considered *unstable* and subject to change in future releases.
121
+
> The types in <xref:Microsoft.AspNetCore.Components.RenderTree> allow processing of the *results* of rendering operations. These are internal details of the Blazor framework implementation. These types should be considered *unstable* and subject to change in future releases.
122
122
123
123
### Sequence numbers relate to code line numbers and not execution order
124
124
@@ -206,7 +206,7 @@ This is a trivial example. In more realistic cases with complex and deeply neste
206
206
207
207
* App performance suffers if sequence numbers are generated dynamically.
208
208
* The framework can't create its own sequence numbers automatically at runtime because the necessary information doesn't exist unless it's captured at compile time.
209
-
* Don't write long blocks of manually-implemented `RenderTreeBuilder` logic. Prefer *.razor* files and allow the compiler to deal with the sequence numbers. If you're unable to avoid manual `RenderTreeBuilder` logic, split long blocks of code into smaller pieces wrapped in `OpenRegion`/`CloseRegion` calls. Each region has its own separate space of sequence numbers, so you can restart from zero (or any other arbitrary number) inside each region.
209
+
* Don't write long blocks of manually-implemented <xref:Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder> logic. Prefer *.razor* files and allow the compiler to deal with the sequence numbers. If you're unable to avoid manual <xref:Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder> logic, split long blocks of code into smaller pieces wrapped in <xref:Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder.OpenRegion%2A>/<xref:Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder.CloseRegion%2A> calls. Each region has its own separate space of sequence numbers, so you can restart from zero (or any other arbitrary number) inside each region.
210
210
* If sequence numbers are hardcoded, the diff algorithm only requires that sequence numbers increase in value. The initial value and gaps are irrelevant. One legitimate option is to use the code line number as the sequence number, or start from zero and increase by ones or hundreds (or any preferred interval).
211
211
* Blazor uses sequence numbers, while other tree-diffing UI frameworks don't use them. Diffing is far faster when sequence numbers are used, and Blazor has the advantage of a compile step that deals with sequence numbers automatically for developers authoring *.razor* files.
Copy file name to clipboardExpand all lines: aspnetcore/blazor/call-dotnet-from-javascript.md
+13-13Lines changed: 13 additions & 13 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -21,9 +21,9 @@ This article covers invoking .NET methods from JavaScript. For information on ho
21
21
22
22
## Static .NET method call
23
23
24
-
To invoke a static .NET method from JavaScript, use the `DotNet.invokeMethod` or `DotNet.invokeMethodAsync` functions. Pass in the identifier of the static method you wish to call, the name of the assembly containing the function, and any arguments. The asynchronous version is preferred to support Blazor Server scenarios. The .NET method must be public, static, and have the `[JSInvokable]` attribute. Calling open generic methods isn't currently supported.
24
+
To invoke a static .NET method from JavaScript, use the `DotNet.invokeMethod` or `DotNet.invokeMethodAsync` functions. Pass in the identifier of the static method you wish to call, the name of the assembly containing the function, and any arguments. The asynchronous version is preferred to support Blazor Server scenarios. The .NET method must be public, static, and have the [`[JSInvokable]`](xref:Microsoft.JSInterop.JSInvokableAttribute) attribute. Calling open generic methods isn't currently supported.
25
25
26
-
The sample app includes a C# method to return an `int` array. The `JSInvokable` attribute is applied to the method.
26
+
The sample app includes a C# method to return an `int` array. The [`[JSInvokable]`](xref:Microsoft.JSInterop.JSInvokableAttribute) attribute is applied to the method.
27
27
28
28
*Pages/JsInterop.razor*:
29
29
@@ -58,7 +58,7 @@ Array(4) [ 1, 2, 3, 4 ]
58
58
59
59
The fourth array value is pushed to the array (`data.push(4);`) returned by `ReturnArrayAsync`.
60
60
61
-
By default, the method identifier is the method name, but you can specify a different identifier using the `JSInvokableAttribute` constructor:
61
+
By default, the method identifier is the method name, but you can specify a different identifier using the [`[JSInvokable]`](xref:Microsoft.JSInterop.JSInvokableAttribute) attribute constructor:
62
62
63
63
```csharp
64
64
@code {
@@ -87,8 +87,8 @@ returnArrayAsyncJs: function () {
87
87
You can also call .NET instance methods from JavaScript. To invoke a .NET instance method from JavaScript:
88
88
89
89
* Pass the .NET instance by reference to JavaScript:
90
-
* Make a static call to `DotNetObjectReference.Create`.
91
-
* Wrap the instance in a `DotNetObjectReference` instance and call `Create` on the `DotNetObjectReference` instance. Dispose of `DotNetObjectReference` objects (an example appears later in this section).
90
+
* Make a static call to <xref:Microsoft.JSInterop.DotNetObjectReference.Create%2A?displayProperty=nameWithType>.
91
+
* Wrap the instance in a <xref:Microsoft.JSInterop.DotNetObjectReference> instance and call <xref:Microsoft.JSInterop.DotNetObjectReference.Create%2A> on the <xref:Microsoft.JSInterop.DotNetObjectReference> instance. Dispose of <xref:Microsoft.JSInterop.DotNetObjectReference> objects (an example appears later in this section).
92
92
* Invoke .NET instance methods on the instance using the `invokeMethod` or `invokeMethodAsync` functions. The .NET instance can also be passed as an argument when invoking other .NET methods from JavaScript.
93
93
94
94
> [!NOTE]
@@ -134,9 +134,9 @@ Console output in the browser's web developer tools:
134
134
Hello, Blazor!
135
135
```
136
136
137
-
To avoid a memory leak and allow garbage collection on a component that creates a `DotNetObjectReference`, adopt one of the following approaches:
137
+
To avoid a memory leak and allow garbage collection on a component that creates a <xref:Microsoft.JSInterop.DotNetObjectReference>, adopt one of the following approaches:
138
138
139
-
* Dispose of the object in the class that created the `DotNetObjectReference` instance:
139
+
* Dispose of the object in the class that created the <xref:Microsoft.JSInterop.DotNetObjectReference> instance:
140
140
141
141
```csharp
142
142
publicclassExampleJsInterop : IDisposable
@@ -198,7 +198,7 @@ To avoid a memory leak and allow garbage collection on a component that creates
198
198
}
199
199
```
200
200
201
-
* When the component or class doesn't dispose of the `DotNetObjectReference`, dispose of the object on the client by calling `.dispose()`:
201
+
* When the component or class doesn't dispose of the <xref:Microsoft.JSInterop.DotNetObjectReference>, dispose of the object on the client by calling `.dispose()`:
202
202
203
203
```javascript
204
204
window.myFunction= (dotnetHelper) => {
@@ -212,7 +212,7 @@ To avoid a memory leak and allow garbage collection on a component that creates
212
212
To invoke a component's .NET methods:
213
213
214
214
* Use the `invokeMethod` or `invokeMethodAsync` function to make a static method call to the component.
215
-
* The component's static method wraps the call to its instance method as an invoked `Action`.
215
+
* The component's static method wraps the call to its instance method as an invoked <xref:System.Action>.
216
216
217
217
In the client-side JavaScript:
218
218
@@ -258,11 +258,11 @@ function updateMessageCallerJS() {
258
258
}
259
259
```
260
260
261
-
When there are several components, each with instance methods to call, use a helper class to invoke the instance methods (as `Action`s) of each component.
261
+
When there are several components, each with instance methods to call, use a helper class to invoke the instance methods (as <xref:System.Action>s) of each component.
262
262
263
263
In the following example:
264
264
265
-
* The `JSInterop` component contains several `ListItem` components.
265
+
* The `JSInteropExample` component contains several `ListItem` components.
266
266
* Each `ListItem` component is composed of a message and a button.
267
267
* When a `ListItem` component button is selected, that `ListItem`'s `UpdateMessage` method changes the list item text and hides the button.
0 commit comments