« first day (3698 days earlier)      last day (1464 days later) » 

05:44
Hello folks. Modules such as mqtt.js install a binary program on npm install which is subsequently available in the node_modules folder (./node_modules/.bin/ path). How to do something like this for your project?
 
8 hours later…
13:52
@MileMijatović define a function in the useEffect callback, not outside
@entithat i hope that password is hashed
i also hope you aren't sending back the password hash (or plaintext) to the user
14:18
obviously no
u can notice "-password" option.
ah, that seems to be a mongoose thing. Fair enough. First point still stands.
@jbis
why ?
I cam calling that function in useEffect hook
@entithat You can either use await with try catch or then/catch. In this situation i would use then/catch.
@MileMijatović has to do with how react works but if you want to keep it defined outside then you need to add the function as a dependency. In terms of the url thing i dont understand your question.
Ok, then I will define it inside
for more information you can read this: reactjs.org/docs/…
14:32
What I want to do ? On mount I want to fetch data from two APIs
second is related to the first
use fetch with then
fetch('https://eonet.sci.gsfc.nasa.gov/api/v3/categories').then(resp => resp.json()).then(data => {
      setCategoryData(data.categories);
      setSelectedCategory(data.categories[0]);
      setLoading(false);
      return fetch('<anotherurl>');
}).then(resp => json()).then(secondData => {
   // do whatever
});
something like that
Great @JBis , I will try your solution
14:57
@JBis, like this ?
 const fetchCategories = () => {
    try {
      const url = 'https://eonet.sci.gsfc.nasa.gov/api/v3/categories';
      fetch(url)
        .then((response) => response.json())
        .then((data) => {
          setCategoryData(data.categories);
          setSelectedCategory(data.categories[0]);
          setLoading(false);

          return fetch(data.categories[0].link);
        })
        .then((response) => response.json())
        .then((eventData) => {
          console.log('Event data', eventData);
with a lot of .then chaining
any way to do the same with async/await ?
or this is ok in your opinion ?
|| status
I am currently alive!
|| formatting LinuxUser
@LinuxUser Please don't post unformatted code - hit Ctrl+K before sending, use up-arrow to edit messages, and see the faq. Please separate code blocks from your actual question. Put your question in 1 message and then your code in a 2nd and format it.
1 message moved to Trash can
@LinuxUser Please reask with proper formatting.
@MileMijatović i still see no reason for the function, just put it straight into the useEffect but that looks good to me
15:01
still works fine without second .then((response) => response.json())
I am not sure why
lol, if you remove that then you are logging the response object not the JSON
|| mdn Fetch response
Wanting to see why this code does not work?
// Using ES6 syntax
Array.prototype.random = () => {
  return this[Math.floor((Math.random() * this.length))];
}


let arr1 = [1, 2, 3, 4, 5]
console.log(arr1.random()) // Prints undefined
@LinuxUser First, I highly recommend you don't add to the Array prototype
Second, the reason that isn't working is because arrow functions don't add a this context. So this in the random arrow function refers to the Window object. Change it to an anonymous function.
||> // Using ES6 syntax
Array.prototype.random =  function(){
  return this[Math.floor((Math.random() * this.length))];
}


let arr1 = [1, 2, 3, 4, 5]
console.log(arr1.random()) // Prints undefined
@JBis undefined Logged: 5 Took: 0ms
15:07
now it works ^
@JBis Thank you.
np :)
16:02
question about dropzone.js
should not ` paramName: "file"` change the filename of the input ?
@real_hagrid it is the input parameter name, f.e. paramName: inputFile will make the form behave like an <input type="file" name="inputFile" /> field
so the paramName value should change the file name if changed
16:18
no
this is for changing the filename: dropzonejs.com/#config-renameFile
paramName is the name of the parameter the file is send along. File sending works via from / FormData which has a (field)name and a value. The File Blob + Filename is the data, paramName is the name.
@JBis you are right , thank you
on Server side paramName field is used to check for uploads, f.e. in PHP probably something like $_FILES['inputFile'] but the filename is separate
hm I changed ` renameFile: "file", `
but got still an error on server side
renameFile: function(file) {return "file";} probably, it needs to be a function, documentation doesn't say wha to return tho so thats an assumption
obviously that does not work for multifile uploads since they would get the same name
Do I need try catch if i .catch an error of Promise ?
or I can remove try / catch
like this
    try {
      fetch(url)
        .then((response) => response.json())
        .then((data) => {
          setCategoryData(data.categories);
          setSelectedCategory(data.categories[0]);
          setLoading(false);

          return fetch(data.categories[0].link);
        })
        .then((response) => response.json())
        .then((eventData) => {
          setEventData(eventData);
        })
        .catch((err) => console.log(err));
    } catch (error) {
      alert(error);
    }
16:30
@MileMijatović remove try catch
Ok
now, below this useEffect(() => {}, []); I have plan to define one more useEffect(() => [selectedCategory]);
17:30
Mandem, why my sass giving me a difficult time? I've deleted the node_modules forlder and tried npm install and yarn install and still got this. (node:14588) UnhandledPromiseRejectionWarning: TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received undefined
17:47
Typescript confusion of the day
// Doesn't work
if (!this.hasSocket) {
    throw new Error("No socket");
}
this.ws.send(...); // ws is possibly null

// Does work

if (!this.ws) {
    throw new Error('No socket');
}
this.ws.send(...); // perfectly fine


has socket has a !!this.ws in it :|
@ShrekOverflow Please don't post unformatted code - hit Ctrl+K before sending, use up-arrow to edit messages, and see the faq. You have 25 seconds to edit and format your message properly before it will be removed. Please separate code blocks from your actual question. Put your question in 1 message and then your code in a 2nd and format it.
For posting large code blocks, use a paste site like like gist.github.com, hastebin.com, pastie.org or a demo site like jsbin.com
I don't even know how to phrase this!
@ShrekOverflow -- check the actual value of .hasSocket vs .ws, sounds like you're running into truthy-ness, and may need !!! instead of ! so that the type is coerced to a boolean
@storsoc Welcome to the JavaScript chat! Please review the room rules. If you have a question, just post it, and if anyone's free and interested they'll help. If you want to report an abusive user or a problem in this room, visit our meta.
17:59
@storsoc Nu nu the code is exactly the same
!this.ws vs !!!this.ws nd somehow the latter doesn't work
@ShrekOverflow im confused. Whats the issue?
@JBis Typescript infers the former as this.ws is possibly null
the latter its perfectly fine with
I forgot what this check is called :D
but how would typescript know that this.hasSocket being true means that ws is not null in the first one.
this.hasSocket is literally return !!this.ws
@ShrekOverflow i'm not sure typescript can read that far into it
18:05
That's quite sad :( it can infer out quite a lot of things
Hello again, for some reason second useEffect hook catch an error - SyntaxError: Unexpected token < in JSON at position 0
  useEffect(() => {
    const url = 'https://eonet.sci.gsfc.nasa.gov/api/v3/categories';

    fetch(url)
      .then((response) => response.json())
      .then((data) => {
        setCategoryData(data.categories);
        setSelectedCategory(data.categories[0]);
        setLoading(false);

        return fetch(data.categories[0].link);
      })
      .then((response) => response.json())
      .then((eventData) => {
        setEventData(eventData);
      })
      .catch((err) => alert(err));
  }, []);
probably I have a side effect here
because in first useEffect hook I have setSelectedCategory(data.categories[0]);
but second hook should be triggered just when selectedCategory changes
totally confusion
@ShrekOverflow :(
@ShrekOverflow you can always use "!" to tell typescript to fuck off
this.ws!.send
Yeah but that just looks bad
i'll create an issue if I can figure this out how to describe
18:35
posted on November 30, 2020 by Geo Hsu

The Stable channel is being updated to 86.0.4240.199 (Platform version: 13421.102.0) for most Chrome OS devices. This build contains a number of bug fixes and security updates. Systems will be receiving updates over the next several days. If you find new issues, please let us know by visiting our forum or filing a bug. Interested in switching channels Find out how. You can s

about dropzone.js how can I find out the name of the idden input elment? , I need the name on the server side
18:58
Hey Mr. Mod o/
oh hey folks :)
@TylerH bit of time and no see - how you doing ?
hello, any Strava users here?
while this may look like a random question, I'm developing an app based on Strava and would love a few test users! Please let me know if you're interested. I'm not too sure if it's allowed to post links here!
19:09
@JonClements busy. house projects out the wazoo
including enlarging our fenced in area so the dog has 3x as much run-around room :-)
hallo
anyone know why this code is only generating one square?
var canvas = document.getElementById("ok");
var ctx = canvas.getContext("2d");
var y = 0;
var Rg = Math.floor(Math.random() * 480);
function newBall(x) {
  ctx.clearRect(0, 0, 1000, 1000);
  ctx.fillRect(x, y, 20, 20);
  y++;
}
function newFaller(x) {
  setInterval(() => {
    newBall(x);
  }, 5);
}
function generateFaller() {
  Rg = Math.floor(Math.random() * 40);
  newFaller(Rg);
}
setInterval(generateFaller, 1000);
19:26
I'm kind of wondering, is the array.reduce function really the best way to do a "map + filter" (or array.map-if like it would be in other languages).
define best
It feels really inefficient with constantly passing the reference around... It's also not really descriptive to use "reduce" to create a new array which actually maps datapoints in the original map (instead of actually acting like a reducer to combine data).
it gets the intended result with only looping once rather than twice, which is certainly good, though you could do the same with a, loop
Yeah I'm nearly always prefering a loop. Apart from then I have to go through quite some hoops like make it an iife, so I can pass it into a const variable. (Which useful for being more certain of the type down the road)
19:30
so i accidentally created an alert spammer on codesandbox.io don't ask me why or how I don't know anyone know how to stop the alerts for a minute so i can take out that bit of code
in case you didnt realize i have got myself into a major clusterfuck
in chrome, after n popups you can tell it to ignore them
o thx
wheres that
just keep closing them till it appears
will be a checkbox
Oh be careful though: you'll have to go to site settings to enable the popups for debugging late again
but it just says ok not close should i just clicking ok
19:32
Also f12 should stay responsive? you can press "pause" in the source tab to forcibly pause javascript.
no im on a school chromebook i cant disable javascript
popups and rediracts are locked too
so im pretty much fucked
???
Can you press f12?
Well I am almost certain you can, but do you see then a new view open to the left or bottom of the page?
i cant press f12 im on a chromebook
Hi! is this a good room for npm related questions?
19:37
yup
it shows up as greyed out i cant go into devtools on this computer
Well then people who gave you your computer really don't want you to develop website (frontends)... Talk to tthem.
Cool! So, I made a private repository in AWS and can publish to my scoped repo, but my package has a dependency to aws-sdk which I do not host in my private repo and then npm install fails with the error "'aws-sdk@^2.794.0' is not in the npm registry.", any clue how to fix?
in my .npmrc I do have @my-co.registry=https://....
uh think you have answered your own question: you have a different registry rather than main npm as your go to... And npm needs to be able to find the package needs there.
I do understand that, and I also have tried with the extra line: registry=registry.npmjs.org and it still cannot find un-scoped packages
19:46
Anyone know why this code is only generating one new falling square?
var canvas = document.getElementById("ok");
var ctx = canvas.getContext("2d");
var y = 0;
var Rg = Math.floor(Math.random() * 480);
function newBall(x) {
  ctx.clearRect(0, 0, 1000, 1000);
  ctx.fillRect(x, y, 20, 20);
  y++;
}
function newFaller(x) {
  setInterval(() => {
    newBall(x);
  }, 5);
}
function generateFaller() {
  Rg = Math.floor(Math.random() * 40);
  newFaller(Rg);
}
setInterval(generateFaller, 1000);
I guess my question is how can I specify a private repo for a scope, but use the general reposiroty for un-scoped packages?
 
1 hour later…
20:47
Fixed it, fwiw I had to add the npm-store upstream in my CodeArtifact repository
after that, npm install was able to "find" normal npm packages (unscoped)
21:47
Hi Guys!
@Mahdi Welcome to the JavaScript chat! Please review the room rules. If you have a question, just post it, and if anyone's free and interested they'll help. If you want to report an abusive user or a problem in this room, visit our meta.

« first day (3698 days earlier)      last day (1464 days later) »