This course has been updated! We now recommend you take the State Management with Redux & MobX course.
Transcript from the "Redux Store: createStore" Lesson
>> Steve Kinney: So we have this Redux Store. We can now produce new states of the world. We need to store that somewhere, right? I'm trying to think of the right now, and if I looked up here for where I could store stuff, I'll create a place to store stuff.
[00:00:16] Well, I could use Create Store. That seems good. So I'll go ahead and I'm just gonna use it, we'll find out what happens. If I just call createStore, I'm not gonna like blow up my console cuz I know what's gonna happen. This is gonna blow up. One does not just create a store, you also have to give it a reducer.
[00:00:39] But turns out, guess what I have? I made a reducer just before.
>> Steve Kinney: So I hand it this reducer, I save it.
>> Steve Kinney: I've got the store. And it's a lot for the console right here, but it itself only has a few methods, right? It's got a dispatch method, it's got a getState method, there's not a lot necessarily going on with this one either.
>> Steve Kinney: So let's play around with some of these. We could, for instance, let's go ahead and let's create a subscriber, lets subscribe to the story cause like your state changes. We can imagine a world where the view layer might want to know that the state of the world changed, and listen for it, and receive that new state of the world and update the view.
[00:01:33] That seems rational, right? So let's take a look at that. Again this is, Redux doesn't have anything to do with reacts, we're just imagineering right now. Cool, so we'll just have a console log that's gonna be like subscription. And, we'll actually say, we're passing the store and we'll say getState.
>> Steve Kinney: And I'm just going to get the result off of that, because I don't want to blow up this console. So, we have this subscriber, which is just a function, that console logs, and will at any given point log out the state of the store. Very cool, and the next thing we need to do is we have the store and it has a subscribe method.
[00:02:29] I will give it subscriber. That will return a value, which will be a function that you can call to unsubscribe. So I could say
>> Steve Kinney: And then if I called unsubscribe later, that event scenario would be taken off. All right, let's try it out.
>> Steve Kinney: We've got the store.
[00:02:57] And let's store.dispatch which is our next method to play around with. We'll say store.dispatch and we'll give it the
>> Steve Kinney: Add action, and you can see that the subscription rang true and the current state was 4. Let's call it again. Look. The current state is now eight, right?
[00:03:28] So, the store is keeping track of the current state of the world. It's receiving, it's dispatching actions to go into the reducer, which is then modifying the state of the world and it's keeping track of that, right? So all of a sudden, we have a way to manage state, we have a way to manipulate state.
[00:03:47] Very cool. Now I could implement subtract, and multiply, and all those, but I'm gonna to spare on that right now because it's basically means using every operator on the number of my keyboard, and that in variants different factions. So not necessarily gonna do that right now.