Transcript from the "Adding Methods Solution" Lesson
>> Let's get into the solution for this challenge. So, the idea was to create a ProjectStore class, at a state property, a constructor with a state parameter, getState method, select method. instantiate the ProjectStore with the initialState object. And then call select on the class to get the project's collection.
[00:00:24] All right, so with that said, let me refresh this. Make sure that this is still running, and let me get my code next to this. So we'll just pause temporarily, and let's get everything situated. All right, perfect. And then from here, we'll hop into the mobile application and I'm gonna go into the home component.ts which is what we're working on.
[00:01:11] And I think we are good to go. There we go. All right, and I'm just gonna zoom this out just a bit. And, so we are going to build essentially a version of the ProjectsStore. So, I'm gonna go down here ,and let's build this out. So we'll go class, ProjectsStore.
[00:01:49] And this is going to have a property of state which is going to be of ProjectsState, and constructor, that takes state. The state = state and that is spelt incorrectly. Constructor, there we go. And then from here, we need to then add in a select method which takes a key, which is a string.
[00:02:33] And then from here we're going to return the value of whatever key this may be, okay? And I believe I have one more method. Let me check here. GetState, so getState, all this does is this returns ProjectState, return this.state, okay. And I believe this is correct. So now what we will do is I'm going to instantiate this, const projectsStore =new ProjectsStore and we gonna send in initial ProjectState.
[00:03:22] And from here, let's go ahead and let's just get currentProjects = projectsStore, select. And we're gonna pass in a key of, Projects. And then let's just, Trace this out so const, there we go. And I would be a mess if I did not have my IDE giving me these helpful little hints as I program.
[00:03:59] I am human and I am fallible. So I'm gonna save this and let's see what we have here. All right, so now we're returning the projects. If I switch this to current project, my variable doesn't make sense, but it should update and you should see just this empty project.