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: guides/release/tutorial/part-1/index.md
+1-1Lines changed: 1 addition & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -2,7 +2,7 @@
2
2
3
3
Welcome to the Ember Tutorial!
4
4
5
-
In this tutorial, we will use Ember to build an application called Super Rentals. This will be a website for browsing interesting places to stay during your next vacation. Check out the [finished app](https://ember-super-rentals.netlify.com) to get a sense of the scope of the project.
5
+
In this tutorial, we will use Ember to build an application called Super Rentals. This will be a website for browsing interesting places to stay during your next vacation. Check out the [finished app](https://ember-super-rentals.netlify.app) to get a sense of the scope of the project.
6
6
7
7
<imgsrc="/images/tutorial/part-2/provider-components/homepage-with-rentals-component@2x.png"alt="The finished Super Rentals app"width="1024"height="1328">
Here, we import the access token from the config file and return it from a `token`_[getter](https://javascript.info/property-accessors)_. This allows us to access our token as `this.token` both inside the `MapComponent` class body, as well as the component's template. It is also important to [URL-encode](https://javascript.info/url#encoding-strings) the token, just in case it contains any special characters that are not URL-safe.
159
+
Here, we import the access token from the config file and return it from a `token`_[getter](https://javascript.info/property-accessors)_. This allows us to access our token as `this.token` both inside the `Map` class body, as well as the component's template. It is also important to [URL-encode](https://javascript.info/url#encoding-strings) the token, just in case it contains any special characters that are not URL-safe.
160
160
161
161
## Interpolating Values in Templates
162
162
@@ -404,7 +404,7 @@ import ENV from 'super-rentals/config/environment';
Copy file name to clipboardExpand all lines: guides/release/tutorial/part-2/index.md
+1-1Lines changed: 1 addition & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -4,7 +4,7 @@ Hooray, you've made it to the second part of the tutorial! In the following sect
4
4
5
5
Along the way, we'll also add some new features to our Super Rentals app. By the end of this section, we'll have implemented some search functionality and refactored a good bit of our code to use some new Ember concepts
6
6
7
-
<imgsrc="/images/tutorial/part-2/provider-components/filtered-results@2x.png"alt="Search functionality in the Super Rentals app"width="1024"height="798">
7
+
<imgsrc="/images/tutorial/part-2/provider-components/filtered-results@2x.png"alt="Search functionality in the Super Rentals app"width="1024"height="833">
Copy file name to clipboardExpand all lines: guides/release/tutorial/part-2/provider-components.md
+60-36Lines changed: 60 additions & 36 deletions
Original file line number
Diff line number
Diff line change
@@ -4,11 +4,11 @@ In this chapter, we'll work on adding a new search feature, and refactor our `in
4
4
5
5
<!-- TODO: make this a gif instead -->
6
6
7
-
<imgsrc="/images/tutorial/part-2/provider-components/filtered-results@2x.png"alt="The Super Rentals app by the end of the chapter"width="1024"height="798">
7
+
<imgsrc="/images/tutorial/part-2/provider-components/filtered-results@2x.png"alt="The Super Rentals app by the end of the chapter"width="1024"height="833">
8
8
9
9
During this refactor, you will learn about:
10
10
11
-
- Using Ember's built-in `<Input>` component
11
+
- Using forms
12
12
- The provider component pattern
13
13
- Using block parameters when invoking components
14
14
- Yielding data to caller components
@@ -17,20 +17,22 @@ During this refactor, you will learn about:
17
17
18
18
As our app grows and as we add more features to it, one thing that would be really nice to have is some search functionality. It would be great if our users could just type a word into a search box and our app could just respond with matching and relevant rentals. So how could we go about implementing this feature?
19
19
20
-
Well, we can start simple. Before we worry about implementing the "search" part of this feature, let's just get something on the page. The first step is to add an `<input>` tag to our `index` page, and make it look pretty with a class.
20
+
Well, we can start simple. Before we worry about implementing the "search" part of this feature, let's just get something on the page. The first step is to add a form with an `<input>` tag to our `index` page, and make it look pretty with a class.
@@ -73,18 +77,20 @@ Let's start simple again and begin our refactor by creating a new template for o
73
77
74
78
There is one minor change to note here: while extracting our markup into a component, we also renamed the `@model` argument to be `@rentals` instead, just in order to be a little more specific about what we're iterating over in our `{{#each}}` loop. Otherwise, all we're doing here is copy-pasting what was on our `index.hbs` page into our new component template. Now we just need to actually use our new component in the index template where we started this whole refactor! Let's render our `<Rentals>` component in our `index.hbs` template.
@@ -198,28 +204,45 @@ Now, if we try running our tests, they should all pass after making this change.
198
204
199
205
<imgsrc="/images/tutorial/part-2/provider-components/pass-1@2x.png"alt="The new test is passing."width="1024"height="1024">
200
206
201
-
## Using Ember's `<Input>`
207
+
## Using a `form`
202
208
203
-
Now that we have our component all set up, we can finally wire up our search box and store our search query! First things first: let's create a component class to store our query state.
209
+
Now that we have our component all set up, we can finally wire up our search box and store our search query! First things first: let's create a component class to store our query state and handle events from the `form` element:
@@ -229,9 +252,7 @@ Next, we'll wire up our query state in the component template.
229
252
</div>
230
253
```
231
254
232
-
Interesting! There are a few things happening in this one-line template change. First, we're moving from using a plain HTML `<input>` tag to using an `<Input>` tag instead! As it turns out, Ember provides us with a helpful little _[`<Input>` component](../../../components/built-in-components/#toc_input)_ for this exact use case. The `<Input>` component is actually just a wrapper around the `<input>` element.
233
-
234
-
Ember's `<Input>` component is pretty neat; it will wire up things behind the scenes such that, whenever the user types something into the input box, `this.query` changes accordingly. In other words, `this.query` is kept in sync with the value of what is being searched; we finally have the perfect way of storing the state of our search query!
255
+
[`FormData`](https://developer.mozilla.org/en-US/docs/Web/API/FormData) is a built-in JavaScript object for handling forms. It requires the `name` attribute on the `input`. We handle both `submit` and `input` events for the form so that the query updates both when the user types into the input and when they submit the form.
235
256
236
257
<divclass="cta">
237
258
<divclass="cta-note">
@@ -252,7 +273,7 @@ Now that our search query is wired up to our `<Rentals>` component, we can get i
@@ -330,7 +354,7 @@ This is called the _provider component pattern_, which we see in action with one
330
354
331
355
Okay, now that we have a better sense of which component is rendering what and the theory behind why all of this is happening, let's answer the big unanswered question: does this even work? If we try out our search box in the UI, what happens?
332
356
333
-
<imgsrc="/images/tutorial/part-2/provider-components/filtered-results@2x.png"alt="Trying out the search box."width="1024"height="798">
357
+
<imgsrc="/images/tutorial/part-2/provider-components/filtered-results@2x.png"alt="Trying out the search box."width="1024"height="833">
334
358
335
359
Hooray, it works! Awesome. Now that we've tried this out manually in the UI, let's write a test for this new behavior as well.
0 commit comments