Ember 2.x

Ember 2.x Exercise 2 Solution, Part 2


This course has been updated! We now recommend you take the Ember Octane Fundamentals course.

Check out a free preview of the full Ember 2.x course:
The "Exercise 2 Solution, Part 2" Lesson is part of the full, Ember 2.x course featured in this preview video. Here's what you'd learn in this lesson:

Mike wraps up the solution to Exercise 2 by answering a few audience questions about the exercise.

Get Unlimited Access Now

Transcript from the "Exercise 2 Solution, Part 2" Lesson

>> [MUSIC]

>> Speaker 1: So you may notice that if I do a hard refresh here I'm sorry that's, I'm not illustrating the correct thing. So I'm entering the application on a route with a redirect. I still end up with this back button problem. There is an add-on that you can use which makes redirecting a little bit easier that has similar logic here and instead of transition to you'll just use like redirect to.

[00:00:35] In a future version of Ember this will work cleanly and out of the box. But I just wanted to teach you guys the concept here of transitioning and redirecting, and I will send a link out to that add on where all the little kinks are addressed.
>> Speaker 2: So that add on, will that like address doing actual 301 redirects?

>> Speaker 1: So that's a status code that an API would have to provide. Remember that we're not actually responding to a request. At its core we're responding to a hashchange event or something similar if you have html five history support. But it will be the equivalent in that it's forwarding you and sending information back to the consumer that you should always go here.

>> Speaker 2: Right can I see your router file real quick? My brain broke like 15 minutes ago.
>> Speaker 1: No problem.
>> Speaker 2: And I'm completely lost.
>> Speaker 1: It's a file. [TYPING CLICKS] Okay, see how I kind of have things separated?
>> Speaker 2: No, that's. Strange is exactly what I had before I added those two routes I didn't need.

[00:02:05] That complete put me in a tail spin so.
>> Speaker 1: So, do you noticed that I generated some routes, but the only that to get deaf in my side bar here is showing its comments. The reason is, you don't need to modify the router when you add an index.

[00:02:24] Because it's already implied. So all the code generation does is, it's still reporting that it added a route, but it's a no op, in the case of index. You don't see the word index here, at all. It doesn't need to do it, so it doesn't add the clutter.

[00:02:44] Yes.
>> Speaker 3: Just a couple questions. The triple dots in front of argument, could you just explain that quick?
>> Speaker 1: You should go, that is a spread operator, and go watch the Frontend masters ES6 course. That is not an ember feature, that is the current draft of JavaScript. Yes, I can say that now.

>> Speaker 3: [LAUGH] And then can you go over using model versus content and then he says, I thought using content was discouraged for info and guides and in controller source, has that changed?
>> Speaker 1: You can currently use either. Content is not deprecated yet to the best of my knowledge, I would be getting deprecation warnings otherwise.

[00:03:27] They're equivalent, and I would just look at whatever the guides say for now. I can go through and change things, but I wouldn't say it's so strongly discouraged that the framework is throwing warnings at me, which is like when you have to be concerned that somethings about to get ripped out.

[00:03:50] The core team is very very serious about giving ample warning whenever API's are going to break. In fact, because we're on 2.2 right now and content is working and throwing no deprecations It will be available throughout the two x series and you would only need to worry at 3.0 that they would go and remove this thing.

[00:04:17] I think the change from content to model had to do with a deprecation that was removed in ember 2.0. A different way of using controllers. And the idea was to sort of shift away from that, even shifting like some of the default conventions to help people with migration.

[00:04:40] And I'm actually not going to go deep into that, because in terms of writing an app today, with this version of Ember, you don't really need to know that. As far as I know, model and content are both fine. I use content nearly a hundred percent of the time because it's muscle memory at this point.

[00:04:58] Any other questions?
>> Speaker 1: All right. I'm gonna make sure, I think there's still another stop to this [NOISE]. I have to actually return a list of stuff. From my route. So I'm gonna go to orgs routes orgs.
>> Speaker 1: And implement model.
>> Speaker 1: And return an array.
>> Speaker 1: And then I can go to orgs.hbs.

[00:05:28] And instead of being so explicit about each and every list item I can wrap this in an each and loop over my array. So I'm gonna get, people there.
>> Speaker 1: As. All right, so now if we go back to the list, we're going to get JQuery a bunch of times.

[00:05:56] And we simply need to do org.id, org.id, and there we go. So now, this is a much more generic template here. This is, this is much more closer to what you would see if you were using real data, but we will use when we use real data, because there is nothing in here about any particular record.

[00:06:22] It's just all the datas coming from the route.