Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
1
00:00:02,060 --> 00:00:06,010
And let's start with running the async code,
2
00:00:06,010 --> 00:00:09,770
the side effect inside of our components.
3
00:00:09,770 --> 00:00:12,850
Let's maybe start with adding items to a card
4
00:00:12,850 --> 00:00:15,920
from inside the product item component.
5
00:00:15,920 --> 00:00:20,350
That means that in here we have this add to cart handler
6
00:00:20,350 --> 00:00:24,020
and we could of course then not just dispatch an action
7
00:00:24,020 --> 00:00:28,270
to our Redux store but we could also send
8
00:00:28,270 --> 00:00:32,159
that data to Firebase to the backend.
9
00:00:32,159 --> 00:00:34,730
We would just have one problem with that.
10
00:00:34,730 --> 00:00:38,690
If we just send the product data to Firebase.
11
00:00:38,690 --> 00:00:41,010
So the data which we're sending to Redux here
12
00:00:41,010 --> 00:00:43,710
if we just sent that to Firebase,
13
00:00:43,710 --> 00:00:47,650
we would just store that product data in Firebase,
14
00:00:47,650 --> 00:00:52,430
but Firebase the way we are using it does not have any logic
15
00:00:52,430 --> 00:00:54,470
on its own on the backend.
16
00:00:54,470 --> 00:00:59,170
So on the Firebase backend we don't run any extra code.
17
00:00:59,170 --> 00:01:01,840
So if we send some product data there
18
00:01:01,840 --> 00:01:05,970
that product data would simply be added to the database
19
00:01:05,970 --> 00:01:08,440
but all the logic we have in the reducer
20
00:01:08,440 --> 00:01:12,650
for checking whether a product is already part of the cart
21
00:01:12,650 --> 00:01:17,030
and if it is updating as quantity, if it's not adding it
22
00:01:17,030 --> 00:01:21,360
that kind of logic simply does not run on Firebase,
23
00:01:21,360 --> 00:01:24,660
because that's a pretty dumb backend here
24
00:01:24,660 --> 00:01:26,110
the way we're using it
25
00:01:26,110 --> 00:01:29,120
and therefore we don't have such logic there.
26
00:01:29,120 --> 00:01:32,970
Now if you would be using Firebase for a real project
27
00:01:32,970 --> 00:01:35,820
you could add server side code to it.
28
00:01:35,820 --> 00:01:38,150
There is a service called functions
29
00:01:38,150 --> 00:01:40,520
which allows you to add your own code
30
00:01:40,520 --> 00:01:43,460
on the Firebase backend which can be triggered
31
00:01:43,460 --> 00:01:46,420
for incoming requests and which would allow you
32
00:01:46,420 --> 00:01:49,000
to transform data on the backend.
33
00:01:49,000 --> 00:01:52,220
So it would be possible to integrate this here.
34
00:01:52,220 --> 00:01:55,680
And if you're using your own backend built with Node.js
35
00:01:55,680 --> 00:01:59,960
or PHP or whatever if you build your own backend API
36
00:01:59,960 --> 00:02:03,340
then of course you're also totally free to add code
37
00:02:03,340 --> 00:02:07,430
on that backend API that does more with the incoming data
38
00:02:07,430 --> 00:02:09,763
than just store it in the database.
39
00:02:10,740 --> 00:02:14,910
But since this is no course about backend API development
40
00:02:14,910 --> 00:02:17,580
and about backend programming languages
41
00:02:17,580 --> 00:02:20,310
that's not the route I will take here.
42
00:02:20,310 --> 00:02:23,370
It's something you can do but it requires knowledge
43
00:02:23,370 --> 00:02:28,160
about backend programming languages like Node.js or PHP.
44
00:02:28,160 --> 00:02:31,000
And we don't have that here in this course.
45
00:02:31,000 --> 00:02:33,670
Therefore it's important to recognize
46
00:02:33,670 --> 00:02:36,680
that the code we need to write on the frontend
47
00:02:36,680 --> 00:02:40,090
and where we write dead code will depend
48
00:02:40,090 --> 00:02:42,170
on our backend code.
49
00:02:42,170 --> 00:02:45,030
Because we of course have our backend API,
50
00:02:45,030 --> 00:02:49,380
our backend server talking to our frontend application
51
00:02:49,380 --> 00:02:51,700
with help of these http requests
52
00:02:51,700 --> 00:02:54,510
and the responses which we send around.
53
00:02:54,510 --> 00:02:59,210
Now if we would have a backend API that does a lot of work
54
00:02:59,210 --> 00:03:02,220
so that does not just store incoming data
55
00:03:02,220 --> 00:03:03,950
but also transform it.
56
00:03:03,950 --> 00:03:08,650
If we had an API like this then our frontend application
57
00:03:08,650 --> 00:03:10,380
could do less work.
58
00:03:10,380 --> 00:03:14,140
It could just send data like data for a product
59
00:03:14,140 --> 00:03:16,030
that should be added to a cart.
60
00:03:16,030 --> 00:03:18,720
It could send that data to the backend,
61
00:03:18,720 --> 00:03:21,220
lets the backend do the transformation
62
00:03:21,220 --> 00:03:24,000
and then use the response on the frontend
63
00:03:24,000 --> 00:03:27,910
to then just there hand it off to the reducer for example,
64
00:03:27,910 --> 00:03:30,230
to store that response.
65
00:03:30,230 --> 00:03:33,520
So then we could slim down our reducer
66
00:03:33,520 --> 00:03:36,560
and basically just take the incoming data which is coming
67
00:03:36,560 --> 00:03:39,530
from the backend and which was transformed there
68
00:03:39,530 --> 00:03:43,620
so let's say the final card we could just take that
69
00:03:43,620 --> 00:03:47,710
and store that in Redux that's something we could do then.
70
00:03:47,710 --> 00:03:50,480
But that's not the scenario we have here
71
00:03:50,480 --> 00:03:53,680
for the reasons mentioned a couple of seconds ago.
72
00:03:53,680 --> 00:03:56,550
Instead here we have a backend that does not
73
00:03:56,550 --> 00:03:58,410
do a lot of work.
74
00:03:58,410 --> 00:04:02,170
It basically just stores incoming data in the format
75
00:04:02,170 --> 00:04:03,870
It receives it in.
76
00:04:03,870 --> 00:04:06,670
And that means that we do need to do more work
77
00:04:06,670 --> 00:04:07,822
on the frontend.
78
00:04:07,822 --> 00:04:11,780
There we don't just need to store data in the Redox store,
79
00:04:11,780 --> 00:04:14,210
we also need to prepare that data.
80
00:04:14,210 --> 00:04:16,550
We need to transform the data.
81
00:04:16,550 --> 00:04:19,730
So exactly what we're doing here in add item to cart
82
00:04:19,730 --> 00:04:21,930
and in remove item from cart.
83
00:04:21,930 --> 00:04:25,360
We are not just getting the finished cart as a payload
84
00:04:25,360 --> 00:04:27,740
on the action instead we get a product
85
00:04:27,740 --> 00:04:30,510
and we need to find out how to add it to the cart
86
00:04:30,510 --> 00:04:32,320
here in this code.
87
00:04:32,320 --> 00:04:34,490
And the same for removing.
88
00:04:34,490 --> 00:04:38,830
And that's no problem and it of course makes 100% sense
89
00:04:38,830 --> 00:04:42,230
if we have no backend but if we do have a backend
90
00:04:42,230 --> 00:04:44,610
it is at least something to be aware of
91
00:04:44,610 --> 00:04:46,510
that depending on the backend
92
00:04:46,510 --> 00:04:48,870
and the amount of work the backend does
93
00:04:48,870 --> 00:04:51,330
we could do less work here
94
00:04:51,330 --> 00:04:54,330
if the backend would do the work for us.
95
00:04:54,330 --> 00:04:57,720
But as mentioned multiple times, that's not the case here
96
00:04:57,720 --> 00:04:59,990
and therefore we will need to find a way
97
00:04:59,990 --> 00:05:03,300
to still do the work here on the frontend
98
00:05:03,300 --> 00:05:05,890
and at the same time then send
99
00:05:05,890 --> 00:05:08,383
that transformed data to the backend
100
00:05:08,383 --> 00:05:13,110
without doing that sending inside of the reducer
101
00:05:13,110 --> 00:05:16,950
because we learned that we're not allowed to do it there.
102
00:05:16,950 --> 00:05:20,400
So that's the problem set with which we have to work here.
103
00:05:20,400 --> 00:05:24,990
And therefore let's now determine where to best put our code
104
00:05:24,990 --> 00:05:28,280
for sending the updated card to the backend
105
00:05:28,280 --> 00:05:31,080
if the backend is not doing that work for us
106
00:05:31,080 --> 00:05:34,360
and we therefore have to do it here and at the same time
107
00:05:34,360 --> 00:05:37,100
we're not allowed to send our requests inside
108
00:05:37,100 --> 00:05:38,603
of the reducer function.
8821
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.