Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
1
00:00:02,310 --> 00:00:10,200
So now we're managing the listeners now we need to be able to change our state and for that we should
2
00:00:10,200 --> 00:00:13,770
be able to kind of dispatch actions in our components.
3
00:00:13,770 --> 00:00:18,950
So the same idea as if we were using redux heads here and use store.
4
00:00:19,230 --> 00:00:20,640
I'll add a new constant.
5
00:00:20,910 --> 00:00:22,110
I'll name it dispatch.
6
00:00:23,020 --> 00:00:31,690
And this should actually be a function where I, let's say, get an action and then something should
7
00:00:31,690 --> 00:00:33,610
happen when that action is triggered.
8
00:00:33,890 --> 00:00:39,910
And actually here I just want to get the name or the identifier of that action because we define the
9
00:00:39,910 --> 00:00:41,710
concrete actions in a different place.
10
00:00:41,860 --> 00:00:46,730
This year is still the overall abstract definition of our store management system.
11
00:00:47,440 --> 00:00:49,230
So here we get some actual identifier.
12
00:00:49,240 --> 00:00:51,920
And keep in mind that we have does actions object up there?
13
00:00:52,270 --> 00:00:59,950
My idea is that we can later define concrete usages of our store with their own actions, and they are
14
00:00:59,950 --> 00:01:04,780
for such actions, will soon be registered here in this actions object.
15
00:01:05,610 --> 00:01:06,930
Hence here.
16
00:01:08,890 --> 00:01:15,670
Where we get action, I can reach out to actions for debt action identified because that should be a
17
00:01:15,670 --> 00:01:18,970
key of that actions object later once it is registered.
18
00:01:20,070 --> 00:01:26,310
And this action should actually be a function, so action should be an object where we have keys which
19
00:01:26,310 --> 00:01:32,310
match my identifier here and where the value then is a concrete function, which is called by me adding
20
00:01:32,310 --> 00:01:33,180
parentheses here.
21
00:01:34,760 --> 00:01:44,090
The function which I call here, should get my global state, so my current global state and should
22
00:01:44,090 --> 00:01:47,870
return me a new state, that's essentially also what happened in Redox.
23
00:01:47,870 --> 00:01:52,640
Right, and a reduction to reduce or wienies and also got to action and the reduced burden.
24
00:01:53,610 --> 00:02:00,000
Checked the action and returned a new state in the end, it's the same concept I'm following here.
25
00:02:00,310 --> 00:02:06,300
I get to actually identifier, I search for that action in my actions object.
26
00:02:06,750 --> 00:02:09,229
I expect that action is a function which I didn't execute.
27
00:02:09,240 --> 00:02:12,240
So my reduce or function, so to say, which returns and use state.
28
00:02:13,310 --> 00:02:19,370
That you will stay, the stand would emerge with my old state, so global state should then be essentially
29
00:02:19,550 --> 00:02:26,030
my old copied global state merged with everything in the new state so that my global state is a new
30
00:02:26,030 --> 00:02:29,870
object with the old data, plus the new data, the new state.
31
00:02:30,560 --> 00:02:34,540
And now we just need to inform all listeners about that state update.
32
00:02:35,090 --> 00:02:37,330
So I'll go through all my listeners.
33
00:02:37,340 --> 00:02:45,410
So for concert listener of listeners using a four off loopier and listeners, of course, istat global
34
00:02:45,410 --> 00:02:46,550
listeners every year.
35
00:02:47,480 --> 00:02:51,410
And then keep in mind that what we add to listeners is just set state.
36
00:02:51,420 --> 00:02:52,360
So it's a function.
37
00:02:52,640 --> 00:02:57,980
So here I'll simply call a listener and pass my global state here.
38
00:02:58,610 --> 00:03:01,160
So my new global state is what I pass to listener.
39
00:03:02,510 --> 00:03:07,850
What this does is that it updates this state because that's where my listener comes from ultimately
40
00:03:08,180 --> 00:03:13,580
with the new global state and hence react will rewriter the component that is using my custom hook here.
41
00:03:15,840 --> 00:03:20,960
Now, I know we're still in a relatively abstract world, but this was an important first step.
42
00:03:20,970 --> 00:03:23,970
We're now having an abstract dispatch function.
43
00:03:23,970 --> 00:03:25,610
We're able to register listeners.
44
00:03:25,950 --> 00:03:27,050
This is my custom hook.
45
00:03:27,060 --> 00:03:30,000
Now it is custom hook should also return something.
46
00:03:30,480 --> 00:03:35,900
And the something is an array with exactly two elements, and that's the global state and dispatch.
47
00:03:35,970 --> 00:03:43,470
And if that looks familiar to you, then this is exactly what the built in use reducer functional returned.
48
00:03:43,470 --> 00:03:45,630
It allows returns, a state and a dispatch function.
49
00:03:45,760 --> 00:03:50,670
It's just not suited for managing state across components, which is why I have to build my own version
50
00:03:50,670 --> 00:03:51,120
kind of.
51
00:03:51,570 --> 00:03:54,000
But here I return to global state and dispatch.
52
00:03:56,220 --> 00:04:02,190
Now, this is one thing I have here and I will export this constant hook, we need something else,
53
00:04:02,190 --> 00:04:02,460
though.
54
00:04:03,750 --> 00:04:09,330
This custom hook is nice, but it's still very generic, for example, right now, we got no way to
55
00:04:09,330 --> 00:04:10,520
change these actions.
56
00:04:10,530 --> 00:04:12,470
We can call them, but we can't set them.
57
00:04:12,930 --> 00:04:18,300
So there is another thing I will export from from this fall besides to custom hook, and that's in it
58
00:04:18,420 --> 00:04:21,450
store function, this function here.
59
00:04:22,750 --> 00:04:29,650
Which I also export as a name to export will get some actions which are defined by us, the developer,
60
00:04:29,980 --> 00:04:34,690
and maybe as an initial state, so that you can define this, too, because right now, global state
61
00:04:34,690 --> 00:04:35,740
is always an empty state.
62
00:04:35,740 --> 00:04:38,260
Maybe you have some initial state like we do.
63
00:04:38,260 --> 00:04:40,720
Actually, we do have some products initially, for example.
64
00:04:41,440 --> 00:04:48,560
And then here I will simply check if initial state, initial state should be on the initial state.
65
00:04:48,610 --> 00:04:54,670
So if initial state is not null, in which case I'll set global state equal to an object where copy
66
00:04:54,670 --> 00:05:00,070
to current global state, because keep in mind that you'll share Deadfall and you'll share that state.
67
00:05:00,290 --> 00:05:06,670
So just like in redacts, you have multiple producers that make up one global store.
68
00:05:06,820 --> 00:05:12,880
So therefore in redacts you had to call combined reducers to create one big Storrier state object.
69
00:05:13,150 --> 00:05:18,070
It's the same what we're doing here I what we currently have in a global state with the initial state
70
00:05:18,070 --> 00:05:24,040
of this concrete instantiation of this state, so to say, so that we could manage multiple things with
71
00:05:24,040 --> 00:05:25,030
this global store.
72
00:05:26,420 --> 00:05:28,370
So here, I'll merge in my initial state.
73
00:05:29,300 --> 00:05:35,330
And said actions equal to Wilder current actions and then merge into user actions.
74
00:05:36,390 --> 00:05:41,730
So now we have our global state, we have our user actions all registered here.
75
00:05:42,660 --> 00:05:49,030
Now we need someplace where we can create a concrete products store based on this store setup.
76
00:05:49,920 --> 00:05:51,240
That's the next thing I'll add.
8081
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.