These are chat archives for FreeCodeCamp/HelpJavaScript

19th
Dec 2018
Pagnito
@Pagnito
Dec 19 2018 02:48
anyone having a problem wit atom editor, the syntax colors are off for me in all files
i reloaded the editor and when it loaded back up, its all off, reloaded again and still
Jason Luboff
@JLuboff
Dec 19 2018 04:41
No? Try changing the syntax then back again.
Pagnito
@Pagnito
Dec 19 2018 06:16
i did, its doing it in every js file
somethin is up with my atom editor
Tiago Correia
@tiagocorreiaalmeida
Dec 19 2018 09:52
gm everyone, has anyone used jwt with passport?
Tiago Correia
@tiagocorreiaalmeida
Dec 19 2018 09:58
Also does it even makes sense to plug passport in if there's no need for sessions?
Mohammed Boudad
@matrixersp
Dec 19 2018 10:31

How is it possible that this comparision can be true:

componentWillReceiveProps(nextProps) {
 if (nextProps.notes !== this.props.notes) {
   // set state
 }
}

Comparison between two objects or two arrays is always false?

Greg Duncan
@GregatGit
Dec 19 2018 10:55
@matrixersp if nextProps.notes and this.props.notes are properties - they can be compared
Mohammed Boudad
@matrixersp
Dec 19 2018 11:05
@GregatGit but nextProps.notes and this.props.notes are holding arrays
I tried this and it gave me false:
let obj1 = {notes: [ {title: "Note 1"}, {title: "Note 2"} ]};
let obj2 = {notes: [ {title: "Note 1"}, {title: "Note 2"} ]};
console.log(obj1.notes === obj2.notes);  // false
Greg Duncan
@GregatGit
Dec 19 2018 11:08
they will never equal each other unless they happen to be same object
but it is !== not ===
Aditya
@ezioda004
Dec 19 2018 11:09
@matrixersp You could stringify the object and check.
JSON.stringify(obj1) === JSON.stringify(obj2); // true
Mohammed Boudad
@matrixersp
Dec 19 2018 11:13
@GregatGit I understand it's !== that means componentWillReceiveProps will keep changing the state even they contain the same values?
@ezioda004 I just didn't understand how componentWillReceiveProps compare two objects/arrays
Greg Duncan
@GregatGit
Dec 19 2018 11:14
@matrixersp where is this challenge
Mohammed Boudad
@matrixersp
Dec 19 2018 11:15
@GregatGit It's from a book
Greg Duncan
@GregatGit
Dec 19 2018 11:17
@matrixersp {temp: 1} === {temp:1} will return false - so you are correct
you can only compare values of properties
Mohammed Boudad
@matrixersp
Dec 19 2018 11:35
Now I got it! it's just the example given in the book is not a good one
Thank you @GregatGit @ezioda004
Nicolas Ramirez
@kamatheuska
Dec 19 2018 12:51
Hey everyone! I got an interview yesterday an passed the first phase!! Now, in 8 days I will have a technical interview, and I am scared as hell, so would appreciate any advice that you seniors could give me in this matter. It is for a frontend position as Vue developer, but they seem to expect for me to have backend knowledge.
Please help!
Marianissimus
@Marianissimus
Dec 19 2018 14:14
@kamatheuska most likely they mean by backend knowledge that you need to POST / GET data from a server and then render it in Vue.js. (For instance: create a new user, PUT it to the server, GET a list of all users and then display it in a table or something).
Read and learn about these methods in materials like here: https://youtu.be/btDfVBPYI-U
Nate Mallison
@NJM8
Dec 19 2018 14:21
Anyone know a few things about browser caching? I suspect an error in my app is related to either browser caching or webpack chunking. The error is that I have several repeated script tags in my built html file. What I don't understand is that when I inspect my webpack config I don't appear to have the CommonChunksPlugin, but my file names are serialized which I think this plugin does? (maybe something else does this?) Also my browser claims to not have any content cached for my production site but all the file calls say they come from the cache. 🤔
@kamatheuska Congrats! I have been working for the last 6 months as a vuejs dev.
@kamatheuska Here are some interview questions I was asked and I added a few Vuejs specific ones
Screen Shot 2018-12-19 at 9.24.26 AM.png
Nicolas Ramirez
@kamatheuska
Dec 19 2018 14:28
@Marianissimus @NJM8 thanks both, gonna get my game up on those topics :smile:
Nate Mallison
@NJM8
Dec 19 2018 14:30
Also I highly recommend anything by Maximillian Schwartzmuller, he is on Udemy and youtube
Chris
@crokita
Dec 19 2018 14:34
also recommend his course
catalin560
@catalin560
Dec 19 2018 15:23
hey guys
is storing assets in localStorage (for later usage) faster than the normal cache that browsers do?
Keggatron
@Keggatron
Dec 19 2018 16:23
Hey guys, I'm having a validation issue. So I've set a mixed.when property in my validationSchema, it checks if a boolean (isWholeDay) is toggled false and makes another property required. However I'm having issues when you toggle the isWholeDay to true then back to false again the validation is no longer checked.
                isWholeDay: boolean(),
                start: string()
                  .when('isWholeDay', {
                    is: false || undefined,
                    then: string().required('Select start time'),
                    otherwise: string(),
                  }),
So when you open the page, isWholeDay is undefined, so if I attempt to submit my form I will get the validation error, when I toggle isWholeDay to true and attempt to submit the form the error disappears, then when I toggle it back to false, I don't get the validation errors for the start field. Anyone experience this before?
I'm using Yup for validation btw.
Keggatron
@Keggatron
Dec 19 2018 16:39
NM I figured it out.
Pagnito
@Pagnito
Dec 19 2018 18:04
eyyyyyy
Stevegolden12
@Stevegolden12
Dec 19 2018 18:04
@matrixersp congrats on passing the tech interview.
Ankur sharma
@ankur1163
Dec 19 2018 18:06
can someone help me in understanding this code
<script>
console.log("worked");


(function($){
         $( ".menu-item-15139" ).click(function() {
             console.log("gt",mixpanel,"ki");
             mixpanel.track("kylie")
         });
     })(jQuery);

</script>
I am trying to fire mixpanel.track function when i click on my wordpress menu item
this is the recommended code and it works
when we wrap function inside ( )
it means we are creating self invoking function
this function will invoke automatically , on its own
am i correct?
Chris
@crokita
Dec 19 2018 18:17
@ankur1163 yes, that's correct. I'm not really sure why its wrapped in parentheses when all the function is doing is setting up a click listener. Like, wouldn't this work also?
<script>
console.log("worked");
         jQuery( ".menu-item-15139" ).click(function() {
             console.log("gt",mixpanel,"ki");
             mixpanel.track("kylie")
         });
</script>
Ankur sharma
@ankur1163
Dec 19 2018 18:20
@crokita yes it worked
Chris
@crokita
Dec 19 2018 18:21
ah, cool
Ankur sharma
@ankur1163
Dec 19 2018 18:21
your code is much simpler
we are just using jquery , get the item by class , attach click function
so, when that item is clicked this function is invoked
simple
what was happening in first example?
@crokita
Chris
@crokita
Dec 19 2018 18:23
the first example does the same thing. The difference is that jQuery is passed as an argument to that function, and then the parameter name is changed to $. The only reason I can think of why the first example is used is just to rename the jQuery function to $ before using it
Ankur sharma
@ankur1163
Dec 19 2018 18:24
in first example, that is immediately invoked
so when page loaded
this function gets invoked
and it spits out
$( ".menu-item-15139" ).click(function() {
             console.log("gt",mixpanel,"ki");
             mixpanel.track("kylie")
         });
this part?
Chris
@crokita
Dec 19 2018 18:25
yep, but the code inside the script tag gets invoked automatically already. so, I don't see the need to use an IIFE in this case. unless I'm missing something here
Ankur sharma
@ankur1163
Dec 19 2018 18:26
true
ok got it
thanks @crokita
Chris
@crokita
Dec 19 2018 18:27
:+1:
Jason Luboff
@JLuboff
Dec 19 2018 18:58
:wave:
Chris
@crokita
Dec 19 2018 19:00
hello
Jason Luboff
@JLuboff
Dec 19 2018 19:02
Hows it going?
Chris
@crokita
Dec 19 2018 19:03
Pretty well, thank you. Appreciating the power of CSS animations with Vue
Jason Luboff
@JLuboff
Dec 19 2018 19:04
One of these days I'll spend a good chunk of time to properly learn CSS...
Chris
@crokita
Dec 19 2018 19:04
I'm trying to get away with learning as little as possible for now, lol
Jason Luboff
@JLuboff
Dec 19 2018 19:05
Eh.. I'm always learning. Now that I can relax a bit on my SQL learning.. I think I need to take a bit more time to understand React better along with maybe some more advanced JS concepts
Chris
@crokita
Dec 19 2018 19:08
me finally understanding promises was worth the trouble
Jason Luboff
@JLuboff
Dec 19 2018 19:10
I mostly understand them... :P
I mean...I use them.. and...they work..so..must be doing something right
Chris
@crokita
Dec 19 2018 19:11
lol. have you used that await/async syntax?
Jason Luboff
@JLuboff
Dec 19 2018 19:13
Yup
I've moved to using that mainly
Chris
@crokita
Dec 19 2018 19:13
my life is so much better because of it
Jason Luboff
@JLuboff
Dec 19 2018 19:14
Ya I like it alot. Cleaner looking
Pagnito
@Pagnito
Dec 19 2018 20:52
ima bit confused about redis, where is the data being saved?
Brad
@bradtaniguchi
Dec 19 2018 21:11
@Pagnito In the redis database
Pagnito
@Pagnito
Dec 19 2018 21:12
lol i get that, but i mean, it says its an in memory database, someone said it sits between client and the webserver, im confused as to where that is, is it in the clients memory or where
Brad
@bradtaniguchi
Dec 19 2018 21:16
@Pagnito Its in the memory where-ever your running your redis database (IE your machine, another machine, a cloud machine) just like any other database. So if you have 4 servers running on different machines they all connect to the same database, redis or otherwise that's on another machine. Redis is "in-memory" so its blazing fast compared to a normal DB for common use-cases. (that's as far as my knowledge of redis goes)
Pagnito
@Pagnito
Dec 19 2018 21:16
ah i see thnx
Brad
@bradtaniguchi
Dec 19 2018 21:17
Also, knowing your on google cloud, id look into memcache. Same idea as redis, but for google cloud (plus its got a free tier and faster since its on google server right next to your apps)
Jason Luboff
@JLuboff
Dec 19 2018 21:29
I know nothing about redis...how much data are you typically storing in it?
Brad
@bradtaniguchi
Dec 19 2018 21:35
@JLuboff You asking me or @Pagnito ?
Jason Luboff
@JLuboff
Dec 19 2018 21:36
Just in general
Brad
@bradtaniguchi
Dec 19 2018 21:38
Usually it's not much, compared to a traditional database. I was kinda wondering the limits and found this: https://redis.io/topics/faq
Redis itself takes up only a hundred+MB of ram memory
Jason Luboff
@JLuboff
Dec 19 2018 21:39
Wow...ya that uses a lot less storage than I expected
Brad
@bradtaniguchi
Dec 19 2018 21:39
It mentions that redis can only take in as much ram you have, so not much
But yea I don't know much about redis, I only know of the idea due to google's memcache. (which maxes out at 20bg or 100gb depending on where in the world its hosted)
We use it to hold user-sessions between instances, so unless like a few million people (or even more) show up we won't need anywhere near 20gb haha
Jason Luboff
@JLuboff
Dec 19 2018 21:41
With MS SQL Server we now have Memory-optimized tables...I wonder if its really necessary for something like redis at that point
Brad
@bradtaniguchi
Dec 19 2018 21:50
It's possible that could replace some of the functionality, but Redis is a key-value store, which is different than SQL. Depends on the use case i guess
Jason Luboff
@JLuboff
Dec 19 2018 21:57
Ah.
17 mill weekly downloads:
var toString = {}.toString;

module.exports = Array.isArray || function (arr) {
  return toString.call(arr) == '[object Array]';
};
🤦‍♀️🤦‍♀️🤦‍♀️🤦‍♀️
Tiago Correia
@tiagocorreiaalmeida
Dec 19 2018 22:40
@ezioda004 that's nothing compare to this https://www.npmjs.com/package/is-odd
Jason Luboff
@JLuboff
Dec 19 2018 22:42
@ezioda004 You using it at work? :P
Aditya
@ezioda004
Dec 19 2018 22:43
@tiagocorreiaalmeida Lol, atleast its got more lines of code - and ofc its using another dependency
@JLuboff Oh no, I was reading about this article, quite interesting
Jason Luboff
@JLuboff
Dec 19 2018 22:45
Ah
Aditya
@ezioda004
Dec 19 2018 22:45
My views on this are changing, before working I think functions/modules like this should be written by the dev themselves, but now that I see deadlines is a thing, and making the thing "work" is the priority, I can see why people rely on such modules
Jason Luboff
@JLuboff
Dec 19 2018 22:46
I use modules since it obiviousily makes things easier especially higher level stuff that perhaps..I don't understand
However...there's always the "Ok...this module does most of what I want..but not exactly"
Aditya
@ezioda004
Dec 19 2018 22:48
But using modules for something like isArray or isOdd is concerning to me
Jason Luboff
@JLuboff
Dec 19 2018 22:48
oh for sure. I don't use things like that lol
Aditya
@ezioda004
Dec 19 2018 22:48
Yeah, the thing is even if you dont...some module that you're using might be using these as dependencies
And they could go rogue, like the whole event-stream incident
🤷‍♀️
Jason Luboff
@JLuboff
Dec 19 2018 22:49
This is very true
Aditya
@ezioda004
Dec 19 2018 22:50
I hope we get a better system than npm
Sometime soon, but currently npm is synonymous with "official" JS packet manager
Jason Luboff
@JLuboff
Dec 19 2018 22:50
is yarn any better? Or is yarn just an alternative for npm but still the same thing essentially?
Aditya
@ezioda004
Dec 19 2018 22:51
Its the same thing atleast now, yarn used to be faster but now npm has caught up
Jason Luboff
@JLuboff
Dec 19 2018 22:52
I've always used npm so its all i know
Aditya
@ezioda004
Dec 19 2018 22:53
Hmm as I can see yarn also uses npm registry, so the package problem would still exist
Jason Luboff
@JLuboff
Dec 19 2018 22:56
Ya I was under the impression that that was the case
Think its just a different mechanism to grab things
Aditya
@ezioda004
Dec 19 2018 23:01
Yeah basically
I know deno wont use npm, if it uses a new package manager then we might see some competition in few years
Till then watch yo crypto wallets
Jason Luboff
@JLuboff
Dec 19 2018 23:09
Considering BTC is at $3700... I don't bother looking at my wallet..
Kelechi Chinaka
@ke1echi
Dec 19 2018 23:11
hows the job going? @ezioda004
Aditya
@ezioda004
Dec 19 2018 23:13
@ke1echi Not bad, quite a lot of work
That reminds me I should sleep, its almost 5 am heh
Brad
@bradtaniguchi
Dec 19 2018 23:13
Man I like code reviews... but I'm reviewing 2k lines ug
Jason Luboff
@JLuboff
Dec 19 2018 23:14
@bradtaniguchi Never done one... what is it? Youre reviewing someone elses work?
Aditya
@ezioda004
Dec 19 2018 23:15
How many lines do you guys think is acceptable in a JS file?
I saw a file with more than 2k lines, I cant even fathom to refactor it
Jason Luboff
@JLuboff
Dec 19 2018 23:17
< 1000? I guess it depends on what it is. I have seperate files for CRUD, so for example, my Read file is 912 lines but that includes comments and nicely formatted queries
My routes file for the same app, is 654
I find both of them to be manageable (I also have the exports or routes in alphabetical order)
But... my react app I'm working on.. my entry point file...is 859 lines..and I have a hard time navigating through it although I haven't attempted to clean it up yet
Aditya
@ezioda004
Dec 19 2018 23:20
Yeah that file was backend so I cant give much thoughts on that but for React I'd consider anything more than 500+ lines should be broken into another component or move some of the methods to different file
I'm writing code in a way so the next guy who takes my job wont try to hunt me down 😁
Jason Luboff
@JLuboff
Dec 19 2018 23:21
Yup...I definitely am looking to do that...its just majority of my state is held there.. I will need to look back after I get it close to finished on how to break it up if I can
Jason Luboff
@JLuboff
Dec 19 2018 23:28
Oh man...this guy is using 500-1000 replace functions in one SQL query...
Brad
@bradtaniguchi
Dec 19 2018 23:28
we have some pretty large files, with 1k+ lines. But there's lots of multi-line logging, aggressive formatting that wraps almost anything, and butloads of comments.
We also dont' have much nesting, so the code is very flat and very straight forward. I did just refactor a 2k line file to like 2 seperate 1k line files haha
@JLuboff Yea pretty much, doing it now so we don't have todo it later. Let's just say there is a lot of feedback. But that's good, better catch it now than later when the backend is exploding since someone didn't check for null :D (actually exists in multiple places in the code I am reviewing)
Jason Luboff
@JLuboff
Dec 19 2018 23:31
oh our buddy null!
Brad
@bradtaniguchi
Dec 19 2018 23:38
That guy needs to buy some real estate so I stop getting errors :P
Jason Luboff
@JLuboff
Dec 19 2018 23:48
Not sure I get the reference there
Jason Luboff
@JLuboff
Dec 19 2018 23:56
Well this sucks.. dropped my test database due to wanting to start fresh...only to find I guess I didn't save all my original inserts ugh
Brad
@bradtaniguchi
Dec 19 2018 23:57
bad joke I guess :/
and that's why I don't like DB hehe
Jason Luboff
@JLuboff
Dec 19 2018 23:58
It wouldn't be so bad if I didn't have to create all these relationships :joy: