Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
1
00:00:02,090 --> 00:00:09,260
So what we built here in the end is our custom redacts like story implementation, we're having some
2
00:00:09,680 --> 00:00:15,860
variables which are not global, not registered on the window object, but which do exist in this file
3
00:00:15,860 --> 00:00:16,040
here.
4
00:00:16,040 --> 00:00:19,190
And they only exist once in our application lifetime.
5
00:00:19,190 --> 00:00:23,870
So they're shared in the entire application, every module.
6
00:00:23,870 --> 00:00:30,410
So every other file which imports from the stored jazz file will use the same values which are stored
7
00:00:30,410 --> 00:00:30,650
here.
8
00:00:31,280 --> 00:00:34,190
Then in the same file, we create our own custom hook.
9
00:00:34,430 --> 00:00:39,080
These variables are defined outside of the hook, though, and that's an important thing, because if
10
00:00:39,080 --> 00:00:45,650
they were defined inside of the hook, then every component that used this hook would use its own values,
11
00:00:46,070 --> 00:00:51,870
since they're to find outside of the hook every component that uses our custom hook uses the same values.
12
00:00:51,920 --> 00:00:57,620
So now we're not just sharing the hook logic, but also some share data.
13
00:00:58,010 --> 00:01:00,250
And sometimes you don't want this here.
14
00:01:00,260 --> 00:01:09,980
We absolutely do want this because this allows us to globally manage some state, some actions and listeners
15
00:01:10,010 --> 00:01:15,820
which are interested in state changes, which in turn are triggered by actions in our use store hook.
16
00:01:15,830 --> 00:01:16,970
We're managing all of that.
17
00:01:17,300 --> 00:01:23,480
We're having our dispatch function in there, which makes sure that whenever we call dispatch, we update
18
00:01:23,480 --> 00:01:30,410
our global state and we call our listeners where our listeners are in and just said state calls where
19
00:01:30,410 --> 00:01:33,710
we abuse in quotes because it's not really a hack.
20
00:01:33,710 --> 00:01:40,940
But we're simply using that feature that when you call that state updating function use state gives
21
00:01:40,940 --> 00:01:44,720
you any component that uses this hook will render.
22
00:01:45,830 --> 00:01:46,850
That's what we want here.
23
00:01:48,250 --> 00:01:54,100
We register one listener per component with the help of USA Fact, and we unregister it when that component
24
00:01:54,100 --> 00:01:54,850
is destroyed.
25
00:01:57,010 --> 00:02:03,160
And we then also have a way of initializing our store, which you can call multiple times because we're
26
00:02:03,160 --> 00:02:06,280
not replacing our global state or replacing our actions.
27
00:02:06,310 --> 00:02:11,710
Instead, we're always taking the current global state and the current actions to map to emerging new
28
00:02:11,710 --> 00:02:12,130
data.
29
00:02:12,670 --> 00:02:19,030
We're doing this so that you can create concrete store slices, just as we're doing it with redux,
30
00:02:19,030 --> 00:02:24,730
with multiple reducers, where in one slice you manage your products, maybe in a narrow slice you managed
31
00:02:24,730 --> 00:02:26,410
to use authentication status.
32
00:02:26,980 --> 00:02:30,400
Of course, you have to make sure you avoid name clashes, but that's all.
33
00:02:30,880 --> 00:02:32,590
So here I'm then setting up some actions.
34
00:02:32,590 --> 00:02:34,900
For example, one action, of course, only here.
35
00:02:35,200 --> 00:02:42,790
And then we call in its store to pass our actions here and our initial state for this slice of the global
36
00:02:42,790 --> 00:02:43,090
state.
37
00:02:43,100 --> 00:02:47,110
So that will be merged in our global state and in our global actions map.
38
00:02:47,750 --> 00:02:56,230
And then from anywhere in our project, we can use that store and then ever tap into our state or use
39
00:02:56,230 --> 00:02:58,270
the dispatch function to dispatch an action.
40
00:02:58,280 --> 00:02:59,620
That's the idea here.
41
00:03:00,040 --> 00:03:03,970
That's roughly kind of also the idea how Redox works behind the scenes.
42
00:03:03,970 --> 00:03:10,840
But now we rebuilt it totally without redacts saving that extra dependency and using react and hooks
43
00:03:10,840 --> 00:03:11,230
only.
4517
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.