text
stringlengths
1
81
start
float64
0
10.1k
duration
float64
0
24.9
JORDAN HAYASHI: Yeah.
5,498.975
0.875
It's just an array that has a length attribute,
5,499.85
1.958
so we can do this dot state dot to dos, which grabs that list,
5,501.808
3.572
and just do dot length.
5,505.38
2.61
And now we have a 0.
5,507.99
1.53
And if we add a to do, it goes ahead and increases.
5,509.52
6.46
Cool.
5,515.98
0.5
And so how are we going to keep track of the unchecked to dos?
5,516.48
3.39
Well, we know we're tracking every single to do and whether it's checked
5,527.55
3.78
or not.
5,531.33
1.37
And so one strategy might be to get all of the to dos,
5,532.7
3.13
remove all of the ones that are checked, and then count the number remaining.
5,535.83
4.77
So what functions might we use to implement that algorithm?
5,540.6
3.67
Yeah, we can use the filter function.
5,547.889
1.541
So we can do this dot state dot to dos dot filter.
5,549.43
4.812
And what are we going to filter by?
5,554.242
1.458
Well, for each to do, return if it's not checked.
5,555.7
5.46
And then we're left with a new array, and we can just grab the length.
5,566.744
2.916
And so if we do a test, now we have it unchecked.
5,572.19
2.67
What happens when we check it?
5,574.86
1.84
Well, that's going to get filtered out here, and what's left is an empty list.
5,576.7
5.37
And you grab the length of that, and we have 0.
5,582.07
2.54
What happens when we delete it?
5,584.61
1.769
Well, we don't actually have to update any logic,
5,586.379
2.041
because everything is handled completely declaratively.
5,588.42
3.627
Is there anything here that says, every time
5,606.74
2.37
we change something, make sure to go and change this count that we're keeping?
5,609.11
4.74
Not really, right?
5,613.85
1.02
We just assume that we have some to dos and some data that's coming down,
5,614.87
4.06
and we just run calculations based on that data.
5,618.93
2.51
And so we're just declaring what we want, based
5,621.44
2.28
on any data that's passed into us.
5,623.72
2.38
And so React, in that way, is very declarative.
5,626.1
3.515
And so this is great.
5,632.61
0.96
If we want to add any new features, we don't really have to worry about, oh,
5,633.57
3.17
what is every single possible method that we
5,636.74
2.56
need to update this new feature with.
5,639.3
1.8
Whereas if we were doing this in more Vanilla JS
5,641.1
2.427
and more an imperative nature, we would have
5,643.527
1.833
to make sure, oh, if we want to also keep track of the count of checks
5,645.36
4.21
to dos, we're going to have to check every single method where
5,649.57
3.59
that number might be affected and go ahead and update it there.
5,653.16
2.91
And so keeping track of all that in your mind
5,656.07
3.18
might create bugs that you might not otherwise
5,659.25
3.54
if the paradigm were more simple.
5,662.79
1.99
And so this is a much more simple way of saying, hey, given some app state,
5,664.78
4.94
go ahead and render an app based on that state.
5,669.72
3.23
Any questions?
5,675.95
2.42
Yeah?
5,678.37
0.5
AUDIENCE: [INAUDIBLE]
5,678.87
18.795
JORDAN HAYASHI: Can you repeat your question?
5,697.665
1.875
AUDIENCE: [INAUDIBLE]
5,699.54
12.51
JORDAN HAYASHI: So the question was if we,
5,712.05
5.1
rather than replacing the old state.todos over here with a new array,
5,717.15
5.88
would it still work, if we were to mutate the array?
5,723.03
3.72
And the answer to that is, it depends.
5,726.75
2.144
It depends on the React component that you're using,
5,728.894
2.166
and it depends on some other methods that you
5,731.06
3.07
could write that we'll talk about in future lectures.
5,734.13
4.2
But the fact that it depends is a bad thing,
5,738.33
2.46
because then you don't really know--
5,740.79
1.877
it depends on what else you've written, whether it will work or not.
5,742.667
2.833
But if you do it like this, where it's a completely new array,
5,745.5
2.89
it will always work.
5,748.39
2.37
And we'll talk about this in future lectures,
5,750.76
3.14
but the React paradigm is always to do things immutably,
5,753.9
4.53
which means if you ever change something, replace it
5,758.43
2.25
with something completely new.
5,760.68
1.41
And that-- be a reference to that.
5,762.09
2.22
That way, if you're ever comparing values,
5,764.31
2.82
you don't have any bugs that can appear there if you've mutated a value.
5,767.13
4.23
So technically it's changed, but the reference to that value
5,771.36
3.21
has not changed.
5,774.57
3.16
Does that make sense?
5,777.73
3.93
Cool.
5,781.66
0.5
Any other questions about React, props, state, or anything
5,782.16
3.47
that we've seen today?
5,785.63
1.47
All right.
5,792
0.78
So we talked about to do app.JS and using React on the web.
5,792.78
8.94
But why limit React just to the web?
5,801.72
3
So there exists this thing called React Native, which
5,804.72
2.31
is a framework that relies on React Core and the core algorithms implemented
5,807.03
3.6
by the React library.
5,810.63
1.48
But it's actually a framework that allows you to do much, much more.
5,812.11
3.65
It allows us to build mobile apps using only JavaScript.
5,815.76
4.56
And so when Facebook released this framework called React Native,
5,820.32
5.07
they released it with the tagline, "learn once, write anywhere."
5,825.39
2.86
So you only have to learn JavaScript once.
5,828.25
1.924
You only have to learn React once.
5,830.174
1.416
But you can actually write it, and it'll run anywhere.
5,831.59
3.53
And this supports both iOS and Android.
5,835.12
3.365
And so I'll leave you there for this lecture, and next lecture,
5,838.485
2.625
we'll look at this thing called React Native
5,841.11
1.833
and how to run JavaScript for mobile apps.
5,842.943
4.487
[AUDIO LOGO]
0
3.437
[? CARTER ZENKE: ?] Well, hello, one and all, and welcome back to CS50's
16.72
3.36
Introduction to Databases with SQL.
20.08
2.4
My name is Carter [? Zenke, ?] and last we left off,
22.48
3.24
we learned how to create our very own database schemas--
25.72
2.73
that is, a way to organize data in our database.
28.45
3.15