00:00:03.325 --> 00:00:03.555 Tips.
00:00:05.335 --> 00:00:10.995 Mean that the variables like essentially mean that multiple
00:00:10.995 --> 00:00:16.843 variables can refer to the same thing, because the thing they
00:00:16.843 --> 00:00:22.598 refer to is like and like a thing in memory that essentially
00:00:22.598 --> 00:00:25.145 like has an address, right?
00:00:25.115 --> 00:00:28.815 Like passing down props because that's like a reference to.
00:00:31.135 --> 00:00:31.965 Another variable.
00:00:34.225 --> 00:00:36.455 To to some degree, yes.
00:00:36.885 --> 00:00:41.160 So like for instance, let's say that everybody lives in a house,
00:00:41.160 --> 00:00:44.975 or at least something resembling a house, and you're out.
00:00:44.985 --> 00:00:47.495 Your house has an address, right?
00:00:48.285 --> 00:00:51.245 Umm, so mines, 1326 Jake Patton Rd.
00:00:52.515 --> 00:00:57.189 Now we could also refer to my address by where it is relative
00:00:57.189 --> 00:01:00.055 to the city I live closest to, right?
00:01:00.065 --> 00:01:04.432 And you could say it's like so many feet this direction from
00:01:04.432 --> 00:01:07.655 the center of the sitting next to me, right.
00:01:07.695 --> 00:01:10.791 Or we could refer to what the GPS coordinates, right if we
00:01:10.791 --> 00:01:14.045 wanted, if we felt so inclined, we could, like, find them and
00:01:14.045 --> 00:01:14.675 refer to it.
00:01:15.225 --> 00:01:18.125 But all of those are referring to the same house.
00:01:20.425 --> 00:01:20.815 Right.
00:01:21.105 --> 00:01:21.805 Does that make sense?
00:01:22.755 --> 00:01:23.015 Mm-hmm.
00:01:24.045 --> 00:01:28.469 Hey, you have a lot of different ways to describe your house,
00:01:24.315 --> 00:01:24.755 So that's.
00:01:24.335 --> 00:01:24.585 Yeah.
00:01:28.469 --> 00:01:28.755 yes.
00:01:28.995 --> 00:01:29.225 Right.
00:01:30.905 --> 00:01:36.381 So for instance here like I could have like product threads
00:01:36.381 --> 00:01:41.674 and then I could say constant Y equals product scores and
00:01:41.674 --> 00:01:46.967 Constance Z equals products res and then anything I do to
00:01:46.967 --> 00:01:51.075 products threads here would affect progress.
00:01:51.095 --> 00:01:55.293 Y&Z because they're all referring to the same house,
00:01:55.293 --> 00:01:55.735 right?
00:01:55.745 --> 00:01:59.775 So products res dot Foo equals bar.
00:02:01.325 --> 00:02:04.784 Well, if I do console dot log why dot Boo course is going to,
00:02:04.784 --> 00:02:07.295 you know, TypeScript is going to yell at me.
00:02:07.345 --> 00:02:11.925 But why is he and products threats?
00:02:14.065 --> 00:02:18.757 These would all be equal to bar even though products res Y&Z
00:02:18.757 --> 00:02:23.017 are technically different variables, they're all referring
00:02:23.017 --> 00:02:27.205 to the same point in memory, the same house, if you will.
00:02:28.415 --> 00:02:32.945 So by contrast, of course, strings integers.
00:02:34.235 --> 00:02:37.428 Now this is generally a particularly your JavaScript,
00:02:37.428 --> 00:02:40.798 and generally true of both languages, although there are
00:02:40.798 --> 00:02:44.405 like weird instances like in Java where like a string can be
00:02:44.405 --> 00:02:48.189 a reference type, but ignoring edge cases, so strings integers,
00:02:48.189 --> 00:02:49.195 things like that.
00:02:49.765 --> 00:02:53.575 They are not represent types, they're just primitive types.
00:02:53.805 --> 00:03:01.609 And what that means is if we have constant a or let's say let
00:03:01.609 --> 00:03:09.540 a equal 1A equals or one what be equal A and let C equal B and
00:03:09.540 --> 00:03:11.555 then I do a = 3.
00:03:13.465 --> 00:03:20.810 Well then a is equal to 3 for musical to three and see is it
00:03:20.810 --> 00:03:22.015 was three.
00:03:24.845 --> 00:03:25.895 No, that's not true.
00:03:25.985 --> 00:03:27.775 Sorry, correct.
00:03:27.785 --> 00:03:33.536 Scratch that, a would be equal to three and B because it's not
00:03:33.536 --> 00:03:38.375 a reference type, B&C are still just equal to 1.
00:03:41.095 --> 00:03:41.675 That makes sense.
00:03:42.245 --> 00:03:46.672 Because this is not tied to a, A can change, B is just whatever
00:03:46.672 --> 00:03:50.822 was given to it the first time you assigned a value because
00:03:50.822 --> 00:03:54.835 it's an integer, so I'm glad it corrected myself quickly.
00:03:52.555 --> 00:03:52.765 Umm.
00:03:54.845 --> 00:03:54.985 There.
00:03:56.145 --> 00:03:58.395 So who cares, right?
00:03:58.825 --> 00:04:01.433 Because like, you don't need to know this in most of the time of
00:04:01.433 --> 00:04:02.075 day to day life.
00:04:02.165 --> 00:04:05.059 Well, here was the bug I ran into and I could not for the
00:04:05.059 --> 00:04:07.555 life of me figured out and here's why it matters.
00:04:07.685 --> 00:04:14.157 So what this used to do is this used to do let new products
00:04:14.157 --> 00:04:21.170 equal boxes that data like that which is what we would all think
00:04:21.170 --> 00:04:22.465 to do right.
00:04:24.965 --> 00:04:29.474 And in my mind, this was a brand new array because you're
00:04:29.474 --> 00:04:34.295 spreading an existing right into a new array, and I'm not in.
00:04:33.035 --> 00:04:33.245 Mm-hmm.
00:04:34.365 --> 00:04:35.675 It wasn't entirely wrong.
00:04:35.685 --> 00:04:38.065 OK, but here's what I didn't know.
00:04:38.195 --> 00:04:40.605 So here was the bug before I tell you how I fixed it.
00:04:40.875 --> 00:04:45.373 So new products would come from the promiser and then get
00:04:45.373 --> 00:04:50.259 assigned inventory, get assigned pricing, get assigned reviews
00:04:50.259 --> 00:04:55.145 and then get approved by ID's gets called again because of the
00:04:55.145 --> 00:04:59.953 whole problem, we're like the proxy or few metal form doesn't
00:04:59.953 --> 00:05:02.125 match the first time, right.
00:05:02.175 --> 00:05:04.105 So when it changes, it calls it again.
00:05:04.295 --> 00:05:08.855 So this we call it again get products by ID's would get
00:05:08.855 --> 00:05:13.742 called from the promiser it would resolve with the same key
00:05:13.742 --> 00:05:18.628 but then new products here would already have inventory and
00:05:18.628 --> 00:05:20.665 pricing assigned to them.
00:05:21.765 --> 00:05:21.975 Umm.
00:05:23.355 --> 00:05:27.083 And I was like, how the hell does this have inventory
00:05:27.083 --> 00:05:30.535 assigned President signed if this is a new array?
00:05:32.965 --> 00:05:33.325 Right.
00:05:33.335 --> 00:05:35.845 Because like this, go ahead.
00:05:33.835 --> 00:05:34.125 Because.
00:05:36.455 --> 00:05:36.705 Yeah.
00:05:36.715 --> 00:05:40.172 I just see cause there was pointing back to the same same
00:05:40.172 --> 00:05:42.855 object still, even though it is a new array.
00:05:42.415 --> 00:05:44.085 It yes.
00:05:45.355 --> 00:05:50.360 So what I didn't know is that newer product new products is a
00:05:50.360 --> 00:05:55.607 new array, but it's only a a new array like this cloning or this
00:05:55.607 --> 00:06:00.451 putting these objects in this new array it's only one level
00:06:00.451 --> 00:06:00.855 deep.
00:06:03.375 --> 00:06:03.845 Right.
00:06:04.225 --> 00:06:08.528 So all the product, all the objects inside of the array are
00:06:08.528 --> 00:06:12.115 the same objects as the ones in the promised her.
00:06:13.595 --> 00:06:17.861 So when you assign inventory to them, inventory already exists
00:06:17.861 --> 00:06:21.045 because the objects in the array are the same.
00:06:22.825 --> 00:06:26.181 Which of course is bad because every time you fetched the
00:06:26.181 --> 00:06:29.712 products you want to get the actual inventory because that's
00:06:29.712 --> 00:06:33.242 something that like we care about having the newest like the
00:06:32.045 --> 00:06:32.335 Umm.
00:06:33.242 --> 00:06:36.888 latest information on you know it sounds like and I spent like
00:06:36.888 --> 00:06:40.477 an hour, hour and a half trying to figure this out and I just
00:06:40.477 --> 00:06:43.891 could not figure it out and I had to call a friend and old
00:06:43.891 --> 00:06:47.422 friend of mine helped me get in programming and he was like,
00:06:47.422 --> 00:06:51.126 yeah, all the all the product, all the objects in there are the
00:06:51.126 --> 00:06:53.615 same objects even though the array is new.
00:06:55.295 --> 00:06:59.621 So the only way to get around that is to create a clone deep
00:06:59.621 --> 00:07:04.090 version of the array and that will actually create a new array
00:07:04.090 --> 00:07:08.204 and all the all the objects in it will be new and all the
00:07:08.204 --> 00:07:11.255 nested objects inside of them will be new.
00:07:12.005 --> 00:07:12.645 I.
00:07:13.745 --> 00:07:17.675 So yeah, that sucked.
00:07:18.795 --> 00:07:19.835 But I'm glad I fixed it.
00:07:20.835 --> 00:07:21.885 Yeah, that's interesting.
00:07:21.425 --> 00:07:21.685 It's.
00:07:22.735 --> 00:07:24.165 Yeah, it was.
00:07:24.705 --> 00:07:27.951 I did not know that I figured new array, everything else in
00:07:27.951 --> 00:07:30.765 inside the array is new and it's it's not the case.
00:07:30.775 --> 00:07:32.665 You have to clone deep of course.
00:07:32.735 --> 00:07:35.455 Normally it doesn't matter because normally like we're
00:07:35.455 --> 00:07:38.621 getting new data so often, it's like, well, every time the page
00:07:38.621 --> 00:07:40.155 loads, there's new data, right?
00:07:41.455 --> 00:07:46.039 So most of the time when you're developing, this doesn't matter,
00:07:46.039 --> 00:07:50.624 but it can matter in cases like this where you're like assigning
00:07:50.624 --> 00:07:54.575 something to an existing version, you might have to use
00:07:54.575 --> 00:07:57.185 clone deep and to avoid the problem.
00:07:59.185 --> 00:07:59.365 Cool.
00:08:00.335 --> 00:08:00.495 Yeah.
00:08:01.855 --> 00:08:02.375 So there you go.
00:08:04.095 --> 00:08:06.650 I'm not going to take any questions because I don't know
00:08:06.650 --> 00:08:09.475 anymore answers than everything I told you guys, but that's a.
00:08:11.925 --> 00:08:12.615 About the.
00:08:11.965 --> 00:08:12.695 No, that was.
00:08:12.355 --> 00:08:12.635 That's.
00:08:12.805 --> 00:08:13.765 I really like that.
00:08:13.775 --> 00:08:14.455 That was great.
00:08:14.965 --> 00:08:15.105 Yeah.