Join egghead, unlock knowledge.

Want more egghead?

This lesson is for members. Join us? Get access to all 3,000+ tutorials + a community with expert developers around the world.

Unlock This Lesson
Become a member
to unlock all features

Level Up!

Access all courses & lessons on egghead today and lock-in your price for life.


    Flux Architecture: Dumb Stores

    0.14 - 16

    In this lesson we'll simplify future development by reducing the logic contained in our application's store.



    Become a Member to view code

    You must be a Pro Member to view code

    Access all courses and lessons, track your progress, gain confidence and expertise.

    Become a Member
    and unlock code for this lesson
    orLog In




    One improvement we could make to our Flux application is to get a lot of this logic out of our store and leave our store pretty dumb and just consuming an API of sorts. I'm going to delete all that and what I've done is, I've taken that exact same code and created a directory called API and there I've got a JavaScript file called cart-api.js.

    I've just converted those all to objects and object methods. We've taken our fore-loop that initially populates it and thrown it into this init method and we call that right before we export our cart API.

    Now back in our store we can just import that and update a bunch of these methods. Here we do cart-api.cart-items. We'll skip this one for right now. Here we'll return cart API totals and then on each of these method calls it'll just be from cart to API.

    This one here is a bit complex. It really looks like something that belongs in our cart API. I'm going to grab this and jump over to our API, jump that guy right there, cite this.catalog, object assign, this.cart-items, and we're looking good. Save that, and we'll jump back to our app store and this get-catalog and just return inaudible API, get-catalog.

    Let's try that out in the browser and it looks like everything is working just fine. I'm just going to jump around a bit, test everything out, increase, decrease, and remove and continue shopping. Everything's working just fine and our app store is a bit dumber, a bit easier to manage...