Monogamous Angular2 EventEmitters 06/08/16

Trail

I COMPLETED THE MEAL TRACKER APP! Finally. Now all I have to do is the GitHub Lookup app…and all the work from this week. On the bright side, I’m halfway done with the GitHub Lookup app. It too looks like crap, but functions like a well oiled Hillary Clinton presidential campaign (see previous post).

Speaking of the Meal Tracker app, I wrote some code that I LOVE today! It’s so simple but it took me a lifetime to pull together. I had pretty much completed the entire project. My last step was to make a filter for healthy meals and unhealthy meals. Seems simple enough…but how do we define healthy. The easy route says count calories so that’s what I did:

  • 500 + calories = unhealthy
  • < 499 calories = healthy

So now when I create an object I want a method to assign a boolean (true/false) for healthy. Cool. Now to actually write the code.

I made the method from an if/else pretty easily. It’s a property of my class. Great. Now onward to the constructor… Maybe tack it before a declaration:

constructor(
public name: string,
public calorie: number,
public calorie.markHealthy(): boolean,
public detail: string,
public id: number) {}

Not likely kid. Eventually I figure it out though…

export class Food {
public healthy: boolean;
markHealthy(){
if (this.calorie >= 500){
this.healthy = false;
} else {
this.healthy = true;
}
}
  //This took me forever!!!
constructor(public name: string, public calorie: number, public detail: string, public     id: number) {
    this.markHealthy();
  }
}

*Applause

Last discovery of the day, and the purpose for the title of this post.

In Angular2, when creating custom EventEmitters, please note that this wonderful feat of technology is limited to one, YES ONE, object/data type/primitive per emit. You may not emit several properties of an object, or two of three indexes of an array! Nope, Angular2 ain’t having it. So just let it go. There can be only one. Angular2 EventEmitters are Monogamous!

Tracks

Speaking of one-to-one, every Friday (excluding 5th Fridays) there is an individual project. Just you and your wits vs the most obscure excuse for a to-do list to be completed with skills learned from the past week. One of the greatest keys an Epicoder can learn, and a quote from the founder of Epicodus himself “Every program is pretty much a to-do list”. If this makes no since now, just wait until your 1st level two programming class. It will become crystal clear.

All that to say, following your Friday fight to the death, or 5pm, whichever comes first, you relax all weekend (snuggled up with a few hours of homework) and return on Monday to have your code reviewed. Now it’s not a critical process, but the instructors (more on instructors in another post)  have no problem letting you know where you could improve. So far my individual projects have been great. I love the challenge of not working in a pair (more on pair programming in another post). It’s an opportunity to really assess your own weaknesses and to explore the topics from the week more.

Im usually the first to sign up for a code review and am excited for feedback, so it’s annoying to be behind and not having any suggestions for improvement, but I’ll be back on track soon. Until then DFTBA!

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s