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: docs/01-components-and-layout.md
+7-5Lines changed: 7 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -15,8 +15,8 @@ The solution already contains four projects:
15
15
16
16
-**BlazingPizza.Client**: This is the Blazor project. It contains the UI components for the app.
17
17
-**BlazingPizza.Server**: This is the ASP.NET Core project hosting the Blazor app and also the backend services for the app.
18
-
-**BlazingPizza.Shared**: Shared model types for the app.
19
-
-**BlazingPizza.ComponentsLibrary**: A library of components and helper code to be used by the app in later sessions.
18
+
-**BlazingPizza.Shared**: This project contains the shared model types for the app.
19
+
-**BlazingPizza.ComponentsLibrary**: This is a library of components and helper code to be used by the app in later sessions.
20
20
21
21
The **BlazingPizza.Server** project should be set as the startup project.
22
22
@@ -46,7 +46,7 @@ Add a `@code` block to *Index.razor* with a list field to keep track of the avai
46
46
}
47
47
```
48
48
49
-
The code in the `@code` block is added to the generated class for the component. The `PizzaSpecial` type is already defined for you in the Shared project.
49
+
The code in the `@code` block is added to the generated class for the component. The `PizzaSpecial` type is already defined for you in the **BlazingPizza.Shared** project.
50
50
51
51
To get the available list of specials we need to call an API on the backend. Blazor provides a preconfigured `HttpClient` through dependency injection that is already setup with the correct base address. Use the `@inject` directive to inject an `HttpClient` into the `Index` component.
52
52
@@ -70,7 +70,7 @@ Override the `OnInitializedAsync` method in the `@code` block to retrieve the li
70
70
}
71
71
```
72
72
73
-
The `/specials` API is defined by the `SpecialsController` in the Server project.
73
+
The `/specials` API is defined by the `SpecialsController` in the **BlazingPizza.Server** project.
74
74
75
75
Once the component is initialized it will render its markup. Replace the markup in the `Index` component with the following to list the pizza specials:
76
76
@@ -123,7 +123,9 @@ Update the `MainLayout` component to define a top bar with a branding logo and a
Copy file name to clipboardExpand all lines: docs/02-customize-a-pizza.md
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -65,7 +65,7 @@ Now we need to implement the pizza customization dialog so we can display it whe
65
65
66
66
Add a *ConfigurePizzaDialog.razor* file under the *Shared* directory. Since this component is not a separate page, it does not need the `@page` directive.
67
67
68
-
> Note: In Visual Studio, you can right-click the *Shared* directory in Solution Explorer, then choose *Add* -> *New Item*, then use the *Razor Component* item template.
68
+
> Note: In Visual Studio, you can right-click the *Shared* directory in Solution Explorer, then choose *Add* -> *New Item* to use the *Razor Component* item template to add a new Razor component.
69
69
70
70
The `ConfigurePizzaDialog` should have a `Pizza` parameter that specifies the pizza being configured. Component parameters are defined by adding a writable property to the component decorated with the `[Parameter]` attribute. Add a `@code` block to the `ConfigurePizzaDialog` with the following `Pizza` parameter:
71
71
@@ -134,7 +134,7 @@ Now the dialog shows a slider that can be used to change the pizza size. However
We want the value of the `Pizza.Size` to reflect the value of the slider. When the dialog opens, the slider gets its value from `Pizza.Size`. Moving the slider should update the pizza size stored in `Pizza.Size` accordingly. This concept is called two-way binding.
137
+
We want the value of `Pizza.Size` to reflect the value of the slider. When the dialog opens, the slider gets its value from `Pizza.Size`. Moving the slider should update the pizza size stored in `Pizza.Size` accordingly. This concept is called two-way binding.
138
138
139
139
If you wanted to implement two-way binding manually, you could do so by combining value and @onchange, as in the following code (which you don't actually need to put in your application, because there's an easier solution):
Copy file name to clipboardExpand all lines: docs/03-show-order-status.md
+16-9Lines changed: 16 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -85,7 +85,7 @@ Then add a `@code` block that makes an asynchronous request for the data we need
85
85
86
86
```csharp
87
87
@code {
88
-
List<OrderWithStatus>ordersWithStatus;
88
+
IEnumerable<OrderWithStatus>ordersWithStatus;
89
89
90
90
protectedoverrideasyncTaskOnParametersSetAsync()
91
91
{
@@ -108,7 +108,7 @@ It's simple to express this using `@if/else` blocks in Razor code. Update the ma
108
108
{
109
109
<text>Loading...</text>
110
110
}
111
-
else if (ordersWithStatus.Count == 0)
111
+
else if (!ordersWithStatus.Any())
112
112
{
113
113
<h2>No orders placed</h2>
114
114
<aclass="btn btn-success"href="">Order some pizza</a>
@@ -142,7 +142,7 @@ Asynchronous work when applying parameters and property values must occur during
142
142
143
143
### 5. How can I reset the database?
144
144
145
-
If you want to reset your database to see the "no orders" case, simply delete `pizza.db` from the Server project and reload the page in your browser.
145
+
If you want to reset your database to see the "no orders" case, simply delete `pizza.db` from the **BlazingPizza.Server** project and reload the page in your browser.
@@ -199,7 +199,7 @@ Once again we'll add a component to handle this. In the `Pages` directory, creat
199
199
}
200
200
```
201
201
202
-
This code illustrates how components can receive parameters from the router by declaring them as tokens in the `@page` directive. If you want to receive a `string`, the syntax is simply `{parameterName}`, which matches a `[Parameter]` name case-insensitively. If you want to receive a numeric value, the syntax is `{parameterName:int}`, as in the example above. The `:int` is an example of a *route constraint*. Other route constraintsare supported too.
202
+
This code illustrates how components can receive parameters from the router by declaring them as tokens in the `@page` directive. If you want to receive a `string`, the syntax is simply `{parameterName}`, which matches a `[Parameter]` name case-insensitively. If you want to receive a numeric value, the syntax is `{parameterName:int}`, as in the example above. The `:int` is an example of a *route constraint*. Other route constraints, such as bool, datetime and guid, are also supported.
@@ -280,7 +287,7 @@ The code is a bit intricate, so be sure to go through it carefully to understand
280
287
* This uses `OnParametersSet` instead of `OnInitialized` or `OnInitializedAsync`. `OnParametersSet` is another component lifecycle method, and it fires when the component is first instantiated *and* any time its parameters change value. If the user clicks a link directly from `myorders/2` to `myorders/3`, the framework will retain the `OrderDetails` instance and simply update its `OrderId` parameter in place.
281
288
* As it happens, we haven't provided any links from one "my orders" screen to another, so the scenario never occurs in this application, but it's still the right lifecycle method to use in case we change the navigation rules in the future.
282
289
* We're using an `async void` method to represent the polling. This method runs for arbitrarily long, even while other methods run. `async void` methods have no way to report exceptions upstream to callers (because typically the callers have already finished), so it's important to use `try/catch` and do something meaningful with any exceptions that may occur.
283
-
* We're using `CancellationTokenSource` as a way of signalling when the polling should stop. Currently it only stops if there's an exception, but we'll add another stopping condition later.
290
+
* We're using `CancellationTokenSource` as a way of signalling when the polling should stop. Currently it stops if there's an exception, or once the order is delivered.
284
291
* We need to call `StateHasChanged` to tell Blazor that the component's data has (possibly) changed. The framework will then re-render the component. There's no way that the framework could know when to re-render your component otherwise, because it doesn't know about your polling logic.
0 commit comments