Check out a free preview of the full Enterprise Architecture Patterns course:
The "Reducer Exercise" Lesson is part of the full, Enterprise Architecture Patterns course featured in this preview video. Here's what you'd learn in this lesson:

Students are instructed to create a reducer function that accepts a state and an action parameter. A switch statement should evaluate the action type and call the appropriate method.

Get Unlimited Access Now

Transcript from the "Reducer Exercise" Lesson

>> So you're just gonna essentially create a reducer with the state and action parameter that has a switch statement based on the action type for load, read, create, update, delete. And then it creates an appropriate method for each of those. Now, what I would do is for the methods, just return state of, so that's one thing I did do wrong is for these, in order for this to be correct, you need to return state.

[00:00:29] And so your handler methods, it's totally fine if they look like this initially. All right, so with that said, do we have any questions about the examples and or the challenge that we're about to endeavor to conquer? Yeah, so the question is how would I go about separating my code into modules or would I just leave it all in one place?

[00:00:56] And the answer is I would absolutely extract this into modules. And a module really, under the hood is just typically a file that you're exporting certain, really just an object and then consuming it in something else. So there's nothing particularly magical about a module. But I would absolutely, if this was anything other than an exercise in programming concepts, I would break this up, move this into separate files, and then consume them in pieces into the application.

[00:01:33] So we're making some concessions here because we are kinda starting at ground zero and then moving up. But if this was an actual application, all of these would be broken out into its separate respective file slash modules and then assembled back together of the composition. So that's a very good question.

[00:01:55] This is not typically how I do this. But it is for the sake of an example or creating, I think cognitive cohesion by keeping everything together as we iterate on this.
>> Will we get to a point in this workshop that we will learn how to do it, just separate them into modules or does it not part of the scope?

>> So the question is in the workshop, will we learn how to separate the code into modules? And the answer is I hadn't thought about that. But since you've asked, then I'm certain I can show some demonstration on how to do that. So your request has been heard.

[00:02:38] And I will see if I can work that in at some point. It's actually fairly straightforward. But I realize some people may have some questions about that. So thank you for asking that. I will do my best to touch up on that.