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 7" Lesson is part of the full, Ember 2.x course featured in this preview video. Here's what you'd learn in this lesson:

In this exercise, you will enhance the {{github-org}} component by adding a computed property for the favorite state. You will do this by creating the macro “isFavorited”.

Get Unlimited Access Now

Transcript from the "Exercise 7" Lesson

>> [MUSIC]

>> Mike: Something's been bugging me about the app we have been building. And it's that this word favorite on the screen, it's always favorite. You don't have it switch to unfavorite if something's already in the array. We are not really surfacing the concept of this has been to the favorite list.

[00:00:21] So we're gonna use computer properties to solve that problem. We're gonna enhance the github-org component. And we're gonna add some indication of a favorited state to the list, to each item in the list of orgs, on the orgs page. And so you're going to implement a computer property called isFavorited.

[00:00:47] And I want you guys to build a computer property macro just like sum, which I've just showed you. We will call it isInArray, and you'll pass the name of a property and then the name of another property, which is the list of items to look through to try to detect whether the item's in the array.

[00:01:09] And I want you to use that property in the template for your github-org component to alternate between the word Favorite and Unfavorite. So if you click something, it'll toggle, indicating that it's favorited and you can toggle it again. And now we'll be finally be surfacing this thing that we added yesterday, this favorited state to the user.