Check out a free preview of the full Enterprise Architecture Patterns course

The "Immutable Store Practice" Lesson is part of the full, Enterprise Architecture Patterns course featured in this preview video. Here's what you'd learn in this lesson:

Lukas implements an immutable store by adding a dispatch method that accepts an action and calls the reducer method with the state and the action.


Transcript from the "Immutable Store Practice" Lesson

>> I think at this point we probably have a good idea of what i'm hinting at in terms of what we're building. Not a super surprise. We're just incrementally plodding along. And we are going somewhere with this. And so if I go and I look for, I'm going to take my clients store and I'm going to just move this down here.

And I'm going to make a couple changes to this. I'm going to add in a reducer property. I'm going to reduce her parameter. And so when you create the store it's also going to take reducer this reducer equals. And then from here, we're going to add in one more method and it's going to be dispatch.

Which is going to take an action. And I can even strongly type this if I so desire. And now this state equals this dot reducer this dot state action. Now, within this I'm going to send in the clients reducer and let's try something out. So const I might have already done this.

Let me see, I'm just gonna a client equals and we're gonna go. Clients store, select. Current client. And I'm gonna save this, and then I'm gonna go down here. Let's just dump this out. And just resize this so we can see it. As expected, we're getting the current client.

So now let's go back up here. And let's dispatch an action. So store dispatch. Hold on, client store, dispatch. And we're going to set in a type of client, select And we're going to send in a payload Of, Let me create a new client real quick. Const. Who am I into right now?

Well, [BLANK AUDIO]The most unoriginal I totally got stage fright. Not really but[BLANK AUDIO] when your ID equals 1234 first name Shane Last name, though. Company is a non. All right. So now I'm going to say I want to create a new client and so I did select let me do CLIENT_CREATE.

There we go. And I'm going to send in a new client and then from here what I wanna do. Is I want to go All clients equals client store select clients. I'm going to go ahead and save this. And I'm going to go down here and we're going to trace this out.

I really hope that when I move this back that we have.

Learn Straight from the Experts Who Shape the Modern Web

  • In-depth Courses
  • Industry Leading Experts
  • Learning Paths
  • Live Interactive Workshops
Get Unlimited Access Now