This lesson is for PRO members.

Unlock this lesson NOW!
Already subscribed? sign in

React Flux: Wrapping Up

9:13 React lesson by

With this lesson, we will bring it all together, using what we've learned in the series to fisnish out the React Flux architecture example.

The completed code for this series can be found here on Github.

Get the Code Now
click to level up

egghead.io comment guidelines

Avatar
egghead.io

With this lesson, we will bring it all together, using what we've learned in the series to fisnish out the React Flux architecture example.

The completed code for this series can be found here on Github.

Avatar
Otto

For some reason when I try to run the code on Github, the app-cart component isn't getting compiled correctly into main.js. I saw an error "Uncaught SyntaxError: Unexpected token < " and when I look in main.js, I see:
return (


...

Upon closer examination, all other components are being compiled correctly, e.g.

return React.DOM.button({onClick: this.handleClick}, "+")

but the Cart component isn't.

Any ideas?

In reply to egghead.io
Avatar
Ashley

I noticed at the very end of the video (last minute) whilst navigating the cart empties itself.

Is that a bug?

Avatar
Pavel

I think he pressed 'X' button to delete whole set of items in cart. On Wild West he was called 'Joe the fast cart cleaner' =)

In reply to Ashley
Avatar
Pavel

What I cant really get is why we do catalog item detains in such bazaar way?

  1. why we can't just render page based on provided from parent item?
  2. why we pass item from parent instead of id if we dont use whole item.
  3. why this function is not in store and expands store functionality in such way?

I ve got to much why per seconds for this last bit =))

In reply to egghead.io
Avatar
Delchina

Do you plan to finish the tutorial - how to build a real app with react & flux?

Avatar
Robert

Nice tutorial.
One thing: I think in getItem() in app-catalogdetail.js is useless toString() in item.id. It's saved as a string in the store.

Avatar
Jerome Doyle

Navigating to the cart and item detail pages works, however, I get a 404 anytime I refresh on a page other than the home page.

Hey guys. In this video, we are going to complete our application using everything we learned in our previous videos to flesh out the rest of our app.

We've got our header up and running. We need to get this cart summary guy working. We need to change the layout of our catalog page, and we need to get this catalog item widget up and running.

Then, we'll create our catalog detail page, and our cart is pretty much good to go at this point. One thing I've added here, right in the assets directory, is this little product image placeholder. We will be able to use that as our product image.

The first thing we're going to do is get our cart summary working. For that to work, we're going to need our app store and our store watch mix-in. We're going to create a function here called "CartTotals," and that's just going to return AppStore.GetCartTotals.

Let's plug that into our mix-ins. Then, down here where we had this hard-coded, we'll now have this state quantity/this state total. Drop a little dollar sign right before that, save that guy and we should be able to test that out right away. We'll load up our application here, and as we add items to the car, we can see that our cart summary object is updating.

While we're in here, let's go and create a continue shopping link right here in the app cart. For that, we're going to need our link component from react router component. Down here, while we're returning this table, we are going to wrap this guy in a div, just so that we can add our link component outside of the table.

That'll be link, the href there would be our group directory, and our inner HTML would be continue shopping. Let's load our app again, add some items to the cart and we've got our continue shopping button there. Let's move to our catalog, and we are going to need to update the layout here.

Looks like we've got four across, and we're going to use a little bootstrap to get that done. Jump over here to our catalog. Here, where we're building up our items, rather than outputting a table row, we are going to return our items rather than outputting a table row. We're going to return our catalog item component, passing it the individual item.

We're going to close that, and here this is going to be a div with a class name of row. Then we're also going to need our store watch mix and so forth. We'll get that in there, and then we'll also get our catalog item component on the page. Here, we can drop initial state, get our mix-ins in place, passing it, get catalog.

Let's now move on to our, "get catalog" item. Here, I'm going to actually paste in some code really quick, and we will walk through it.

First, I'm creating this item style, giving each of our catalog items a border on the bottom and a padding on the bottom. We've got a div with a class name of CallSM3, that's going to give us our four across, then, we're passing in our item style and outputting the item title, our image, our summary.

Here, I'll turn off word wrapping. We're outputting our cost and we've got a span with a text name of text/success. If the item is in our car, we are going to go ahead and output the quantity and the string in cart. After that, we've got a quick button group with a link, we are going to need our router link component.

That's linking to the /item/itemID route that we set up earlier with an inner HTML of, "learn more." We're going to add to cart component. Up here, we are going to need our link component, as well as our add to cart component. Over on our add to cart, we're going to add a quick style so that it matches up with our other button. Button-default.

Let's go ahead and try this guy out. Reload here in the browser. Cool, we've got our new layout, we can add an item to the car, we can see how many of that item are in the cart. We can jump to our cart, and get back to it. Now, we need to create our catalog detail page.

That's actually going to be here in product, we're going to create a new component called AppCatalogDetail.js. This is actually going to end up using a lot of the same things that we were using in catalogs, I'm just going to copy these guys out of here and paste them in right there, and build up our catalog detail component.

Catalog detail, which we'll and of exporting. This one is actually going to be a little bit tricky, because we need to create a function that's going to return a specific item. Let me go to create this docket catalog item, and what we're going to do is we are going to pass in our entire component to this method.

We're going to have this item, we are going to take our AppStore.get catalog, and then for each of those, we're just going to cycle through and we are going to say, if Item.ID.2 string equals Component.Props.Item, then, this item equals item. After that, we'll just return this item for our initial state.

Now, when we add in our mixin, calling our GetCatalog method, the problem we are going to run into is that we don't really have a way to add an extra argument to our StoreWatch mixin. What we're going to do is jump over here into our mixin, and then, we are going to add an argument into our callback of this.

We're basically returning our entire component. Now that we have this component, we are going to jump over to our app, and rather than directing catalog detail to catalog item, we're going to direct it to product app catalog detail. Save that, we're going to jump back over to our product page.

Here, we're not going to need catalog item, and add to cart is going to be like that. Here, in our render method, we can actually copy all of this out of the catalog item right there. We can use that to get started. Here, we're not going to worry about the size of the column. We make our title a little bigger.

Instead of summary, we're going to do description. All of these items that say props are now going to be state. We're going to make our buttons a little bigger, and then, this link will actually be a link back to the home page. Our text there again will be continue shopping, and we will drop that after add to cart in this case.

We're going to save that, and we were reload our home page. Make sure that's fresh. We have to learn more, and we are getting an error there. The link is not defined. Yep, we forgot to add that guy. Let's add it, try this guy one more time, reload and learn more.

Cool. That's working, we can add the cart, we can continue shopping. Now, we are getting this message hear about a missing unique key prop. That's going to be in our catalog. Here, we're going to pass in a key of Item.ID. We will reload this one more time. Cool, we can add items here, we can jump over here and learn more about the item.

We can add items there, we can jump to our cart, we can increase and decrease some of these, jump back. Jumping back over to our wire frame, it seems that we have satisfied all of the requirements for this wire frame. There you go, that is our full flux application.

HEY, QUICK QUESTION!
Joel's Head
Why are we asking?