« first day (3156 days earlier)      last day (2015 days later) » 

03:00
most of that stuff seems like a waste of time to me (but I waste a lot of time on more pointless stuff so I'm not judging)
Does anyone here know async/await decently well?
I feel like I have to say yes or I risk losing my job lol
lol
ok so here's the code
let foo = 5;
async function change(){
    foo = 6;
}
async function main() {
    await change();
    console.log(foo);
}
main();
console.log("A");
That prints A then 6 as expected.
without the await in main it prints 6 and then A, again as expected.
is the confusion about when 5 is printed?
@paul23 you'd probably like the book Anathem
@DavidKamer thats the first question
I am formulating my second question...
sorry this is really confusing
ok
let foo = 5;
const syncsleep = (ms) => {
    const start = new Date();
    while (new Date() - start < ms) {}
};
async function change(){
    console.log("c1-" +foo);
    foo = 6;
}
async function change2(){
    console.log("c2-" + foo);
    foo = 8;
}
async function main() {
     await change();
     change2();
    console.log("main - "+  foo);
}
main();
console.log("A");
Prints:
c1-5
A
c2-6
main - 8
Why does "A" come before "c2-6"?
03:19
I feel like there is a simpler example lol
there probably is
Sorry about the complexity but it goes in main (change() and prints c1-5) then out of main ("A") and then back into main (change2() and prints c2-6)
I dont understand why it goes in-out-in instead of in-out
I would expect that to print c1-5,c2-6,main - 8, A
At face value c1-5 is resolved first because you're waiting for it, A is printed while change2 is executing, and change2 finishes excuting allowing last statment to be called, the confusing part is obviously what appears to be main-foo waiting for change2()
> A is printed while change2 is executing
is't sbecause you're not calling await on change2()
there's no concept of "while". only one thing can happen at a time
thats why I am not really understanding
03:23
not necessarily true in the way you're thinking of it.
go on...?
so it's single threaded, but that doesn't mean one function can't have a few cycles and then another
does that make sense?
what does "a few cycles" mean?
like the function can execute "while" another one is
cpu cycles
so like it actually might end up executing in parallel from what I understand.
how? and then wouldn't there be conflicts with two functions changing and accessing the same varible
03:25
but that'd be on the CPU or whatever (maybe OS level)
well
the value of foo at "A" is 6. so change2 didn't happen yet.
but see that's not as complicated as you're making it
because if it's single threaded
it doesn't matter
It does matter if things are happening in parallel.
yeah, I'm seeing the flaw in that logic lol
:)
yeah thats whats confusing me
03:27
not if the things that matter happen out of parallel.
but yeah, the parellel thing is out of scope
I was just making a point on that
"that matters", how would the cpu know what matters and what doesn't?
and what matters and what doesn't
basically whatever gets to it first will change it first, whatever gets to it last will change it last
whatever takes longer to execute
@DavidKamer AHA! Now I shall prove you wrong:
that's why you have stuff like Promise.race
now, here's the thing, JS may choose what is executed first
well node
I don't know what the standard is there tbh
would you agree that change2 should take less than 1000ms to execute?
DavidKamer: "Yes"
let foo = 5;
const syncsleep = (ms) => {
    const start = new Date();
    while (new Date() - start < ms) {}
};
async function change(){
    console.log("c1-" +foo);
    foo = 6;
}
async function change2(){
    console.log("c2-" + foo);
    foo = 8;
}
async function main() {
     await change();
     change2();
    console.log("main - "+  foo);
}
main();
syncsleep(1000);
console.log("A-"+foo);
outside main takes longer to run than change() but
the results are the same
c1-5
A-6
c2-6
main - 8
so time has nothing to do with it.
03:31
I'd guess whatever you call await on will happen last
@DavidKamer the only await being called is change() and that occurs first
What is a good timeout for giving the illusion that the script your running is a human?
@faceless 2131 seconds
*milliseconds
or something arbitrary like that lol
lol i was going to say
maybe do a random
03:33
yeah, thats a good idea to use random
@faceless 3.2 seconds per character types
that is slow af
people are slow
@JBis okay, so I think I get it
@faceless 190 CPM / 60 ~= 3.2
03:35
lol wiki says 190CPM is on the high end
You mean 3 characters per second?
3.2 seconds per character would be about 20 CPM
And this is why I don't do math
(Incase your interested, the reason I am asking is I am trying to make my bot exist in multiple chat rooms efficiently. I need to make sure there wont be conflicts with data saving, roomContext, etc. Also its interesting)
when you call await, it stopped the execution of the code (sort of), allowing the first line of function main to run, then it resumed to syncleep, then once that finished it moved to the next line of code, executing change2 just before and then moved to the last line in main
so change2() executes after syncsleep
but it doesn't resolve
thats just the order of events that doesn't explain why
well the await part makes easy sense
03:39
@JBis Add an invite function to all users that exist on SO ;) make a message that invites them to your room, but to make it seem like it was a mistake sending it to them because you met to send it to a different friend
then syncsleep because it's the next sync line
@*
@.*
doesn't work lol
so after sync sleep foo is already set to 6, is that the confusing part?
One of my friends when he was a junior dev shut down his companies access to google for an hour because he forgot to set a timeout lol
@DavidKamer no. I am confused why change2(); doesnt run BEFORE syncsleep(1000);console.log("A-"+foo);
because await, for all purposes, in this situation runs as sync
yeah I was getting confused on that lol
if await runs sync than the next to execute should be change2()
it shouldn't magically jump out of the function and then jump back in
03:44
not really
it's not really doing that.
@DavidKamer You may want to start looking for a new job ;)
It's just going to the next sync line
Ok well lets check
"The next sync line"
for lack of a better term
the idea is the promise is still resolving
hmm
you maybe right
03:45
change2() is resolving as the next line after syncsleep is executing
the syncronous code returns first, then the async code
ok well lets take a look
yeah idk why i was so confused, this is really simple lol
I'm just used to doing async - await a certain way and it isn't with a shared var lol
let foo = 5;

async function change(){
    console.log("c1-" +foo);
    foo = 6;
}
async function change2(){
    console.log("c2-" + foo);
    foo = 8;
}
async function main() {
     await change();
     console.log("GO BEFORE A");
     change2();
    console.log("main - "+  foo);
}
main();
console.log("A-"+foo);
next sync is "GO BEFORE A"
but
the result is:
c1-5
A-6
GO BEFORE A
c2-6
main - 8
!!>Promise.all([(async () => 1)(), (async () => 0)()])
@DavidKamer "SyntaxError: await is only valid in async functions and async generators"
@DavidKamer [1,0]
03:49
which one is executed first?
idk. but I would assume 1?
bc it's sync code
so it's a question of scope at that point
hold on, what I meant was:
so whats the rule
it's in an async function which is just a promise
it goes to the next sync in the outer most context?
03:51
no
I was wrong
It's just that "GO BEFORE A" is in an async function
so it's technically in a promise iirc
so "GO BEFORE A" is executing async because it's in an async function
then change2 has the same rules apply to it, etc for each promise within a promise
Hmm let's test your theory
at first I though it was actually going before A and I was confused lol
How can i send props with the link like i want to do here, or is there a better way? i want a generic page where i can inject info about it
<NavLink tag={Link} className="text-dark" to="/PageInfo-data" title={"PageInfo test"}>PageInfo data</NavLink>
!!>Promise.all([new Promise((res, rej)=>setTimeout(res(1), 100000)), (async () => 0)()])
@DavidKamer [1,0]
03:57
oops
!!>Promise.all([new Promise((res, rej)=>setTimeout(()=>res(1), 100)), (async () => 0)()])
@DavidKamer Maximum execution time exceeded
@DavidKamer "undefined"
well, if you run it in node, you'll get the idea
@DavidKamer Darn it. I can't break your logic.
Promise.all([new Promise((res, rej)=>{
  console.log('executing')
  setTimeout(()=>{
  console.log('resolving')
  res(1)
}, 1000)
}), (async () => {
  console.log('executing 2')
  return 0
})()]).then(p => {
  console.log({p})
}
run that
you'll probably get it if you understand promises and are newish to async
@DavidKamer "executing | executing 2 | resolving | { p: [ 1, 0 ] }"
04:02
yep
now why did they design it like that and is there any documentation regarding that?
lol
I am too lazy to read this but I probably explains here → medium.com/@marcellamaki/…
They designed it that way because i/o often takes time
there are probably better docs or blogs from the creator
thanks for your help
04:06
not a problem. The idea is that you can return other stuff while something else is pending
the game of "whats gonna execute next" isn't a very fun one
thanks
will do
also, if you don't mind me asking, how old are you/range?
25, so old af in this industry lol
I used to still think I was young, but I got laughed at when I said that one time. never again lol
Ah. Lol. Well thanks for all your help.
Off to sleep
o/
04:10
anyone knows some react?
 
1 hour later…
05:19
console.log(worksheet['!ref']='A1:A3')
I'm using SheetJS and trying to work with excel without being in excel. How would I assign worksheet['!ref']='A1:A3' to a variable?
My goal here to try and print the objects contained in A1:A3 range, but I'm stuck and the docs arent helping me. When running it, it prints out 'A1:A3', but i need the data contained within those ranges.
I'm going on 6 hours working out this problem
06:04
just access the cell on that position?
@faceless the info you need is here: docs.sheetjs.com/#general-structures
and use local variable if you want to work "outside" the excel
06:32
@rlemon another mis-use of document.write: stackoverflow.com/questions/56488931/why-do-i-get-a-nan
😛
07:01
Hello is there any person who have idea about vue.js?
@Dhruv 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.
remind me to never try to learn vue.js
support seems non-existent
@Neil ?
What you try to say ?
@Dhruv if it's a javascript question maybe I can help you
but I'm not familiar with vue.js
Okay no problem thank to respond
07:13
well, just ask your question
there are always lurkers. If they see your question they can answer to, they could help you.
remember that this is always a chatroom, so nobody is obliged to help. that's what the Q&A section of the site is for
Okay thanks bye
Hey @Dhruv. I am currently working on a VueJS project at work. I may be able to help you. What is the issue you are having ?
Thanks brother
created() {
      let uri = 'http://www.vuecrud.local/api/posts';
      this.axios.get(uri).then(response => {
        this.posts = response.data.data;
      });
    },
At here i have passed static url "http://www.vuecrud.local" But i want to dynamic URL so is there any function ?
It depends what you mean by dynamic. If you want to "build" the URL with some parameters, you can just concatenate the strings
07:25
I just start learning VUE from tomorrow so exactly i have no idea
I don't think the problem is related to Vue
constructing the url to call probably is not ideal if you can avoid it
if anything make a backend rest service which given the proper parameters can call the appropriate microservice
depends on whether or not you're "constructing" the url because they're parameters to a rest service or if you're calling a different service entirely
I agree with Neil
Yeah but is there any way to pass only my site URL i'm not taking about parameter
I don't understand what you mean by that. What do you have, and what do you want / need ?
07:30
let uri = getUri();
do this if anything.. and in getUri, you write the logic to construct the uri to call
I just want to get my current site URL
This is URL right http://www.vuecrud.local/api/posts'
But i want to only http://www.vuecrud.local/
without knowing the details, it's hard to gauge whether or not this is smart or even doable
@Dhruv non-vue.js people can answer that :P
@Neil Not working i have checked
Ok, well you could do 'vuecrud.local/api/posts'.indexOf('/'), but it would be better if the http://www.vuecrud.local and the /api/posts part were separate and then combined in getUri() function
@Dhruv You have to write the getUri function.. that was just an example
07:32
use new URL() construct
that API is there to manage urls easily
Okay got it thanks
@KarelG well there you go. I wasn't even aware there was such a thing
learn something new every day
Thanks to both of you
08:02
@towc *creeps on u*
does anyone use automated testing for frontend stuff?
I guess there are different levels to that
for example, automatically before commit, or automatically at every save
I've never seen it done at every save, but I wonder if it's a bad idea to have some lightweight tests for that
there are tools for that
I used Karma (with Mocha & Chai) at my last job
We hooked it up with our Jenkins CI, but you can hook it up on pre-commit hooks with Husky for example
^ husky
there are other tools that does on-the-fly actions
right but how about post-write?
I'm wondering if I should, not if I could
being a good scientist here
08:16
post-write what?
at every write to a file, run tests
If you want to test very basic stuff, like unit tests, Mocha & Chai are enough, and fast to start. However, if you have things related to the browser, like fetch or need access to the DOM, use Karma with Mocha & Chai, but Karma uses Chromium which will take some time to load (even if you set it headless).
Karma and Mocha supports files watching, if that's what you need
again, not if could, but should
you don't have to start them every time.
thanks for telling me of ways how I could though
08:20
To use my previous job as an example, we were doing TDD, so we wrote the tests, started Karma with file watching enabled, then developped the features. And every time we saved the files, the watcher started the tests (without restarting the whole browser)
assuming you make a call to a rest service to insert a new line, you can use that same rest service to load it from the database
technically you're testing both insertion and loading, but it should still be transparent which is the one causing you the problem, which is in the end the whole point
better still if you can configure some sort of memory-only mode in development where nothing is persisted
just be sure to immediately set it up that you wouldn't accidentally activate that mode in production
@Neil You should stub the requests, since you don't want to depend on the eternal tool / server when testing the front-end
so mock the backend entirely?
Yep.
yeah, I suppose that could work too
08:24
Otherwise, you would also be testing the back-end. You don't want to do that. If the back-end is down, or has an error, it will make the front-end tests fail. This is bad
@Seblor well, I do want to depend on eternal tools, if there were any
@towc This is not what I meant. You can depend on external tools. But it's not the job of the front-end tests to test them. If you want to test the external tools, make those tests in their own project workspace / repo
I was making a cheap joke on the typo
Ah ok, sorry. I don't see the typo, though
Ah nevermind, I see it
external → eternal
08:27
Indeed, good catch
 
1 hour later…
09:57
I am on iPad Pro
... congratulations
I am using VSCode on an iPad this is funnn!!!! Also why the fuck is there no XCode / Logic for it is beyond me but again apple works in mysterious ways. Would love to write an iPad app on iPad though!
@GNi33 lol I've had it for a year, I meant the iPadOS
there's a card game called eternal
very fun, highly recommended
One thing though
I am amazed by how responsive this is, for a browser app on iOS
i mean considering this is an arm tablet
and the A10X in this one is a bit oldilock
.__.
10:05
wat?
I can't be amazed typing feels sluggish on desktop compared to tablet?
IDK why but I'll get to the depth x)
Current assumption is that it's not multi-tasking (at all)
What's amazing to me is that once upon a time, you hit the enter key in a black and green console and waited up to a full second for the response because computers were slow. Now you click on a link on google and it still takes roughly a full second to navigate to the page and load it and nobody thinks this is odd
the number of operations being performed is obviously way higher now, but we've somehow managed to maintain the same response times
10:26
Yes Yes yEs
and that is what frustrates me on the web / electron apps
you can feel the difference on windows / mac / linux
or maybe its just my counter strike senses
they say if it is over a second, a user notices. If it is over 10 seconds, then they'll consider doing something else. If it is over a minute, they'll consider halting the procedure entirely
obviously faster is better, but these are good milestones
10:48
yeap
11:14
@forresthopkinsa yes
You override get and set
11:34
@BenjaminGruenbaum afaik someone here wrote a custom Map entity to solve it
that proposal should have come earlier and being implemented because he had made multiple complaints throughout days
11:57
I know this is an endless discussion but does anyone know how to hide the status bar (using javascript) in Safari on IOS? I feel like I've tried everything..
Without installing the site as a web app
@user10198470 why?
it is only shown when you hover a link
(unless you meant something else)
I think we're talking about something different. I mean the bar where a user puts in a url maybe address bar?
sorry for the confusion
go fullscreen
otherwise it's irresponsible to hide it. phishing attacks are known to utilise that
@rlemon I would love to go fullscreen but how?
so if Safari on IOS limits that. good
@user10198470 google "javascript fullscreen api"
12:03
Thanks!
ah address bar
the status bar is that little white box at left bottom box that is shown when you hover links
@KarelG Ahh sorry!
go full screen yes
@rlemon I just checked the api and tried it. It seems it's only working on IOS 12.2 and up..
well that's a shame
12:11
Tried it on 12.1 and nothing happend :(
just add it and if that feature is not supported because of the version, don't pay too much attention to it
users should - in theory - update their apps
users can also always go into fullscreen on their own
Yeah I think you're right, too bad though
hi, could you help me out? I need to find a way to stop a link (<a href""/>...) from redirecting. The links are dynamically added so I am accessing it via $(document).on("click"). I´ve tested and e.preventDefault and return false wont work on events with "on"?
@user3086972 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.
12:13
@user3086972 wdym? e.preventDefault for sure works
@user3086972 can you share your code fragment? you are probably not using it right
and are you serious to prevent all clicks?
    $(document).on("click","a",function(e) {
        e.preventDefault();
        e.stopPropagation();
    });
thats still firing
show me it failing
redirecting
because I can show you it working
working
12:15
the links are added after the page has loaded
doesn't matter when you delegate the way you are
you could have added "look, I got added after page load" message
honestly i dont get it. It doesnt work here. but with fiddle it seem to.
Hi! How can I use Bootstrap dropdowns to trigger a javascript function every time a different option of the dropdown is selected?
@Akronix 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.
12:19
we are working with mvc and the code fragment is inside a cshtml in the rootlayout
$(function () {
    $(document).on("click","a",function(e) {
        e.preventDefault();
        e.stopPropagation();
    });
});
the method gets called but it redirects every time
@Akronix they are links. add click handlers to the dropdown
._.
using ie 11
I see, thank you @rlemon
12:35
Well this is awkward, some part I never thought would be "difficult" just made me grind to a halt, as I cannot see the difference between the request from my code and the postman request..
If anyone could shine some light: stackoverflow.com/questions/56494328/…
ok i"m a moron nevermind
delete your question then
I actually used the wrong parameter name. deleted the question.
I've been helping a guy at work a bit this week but don't have the hardware to test, and don't feel like setting up anything proper
SOOOO many typos on my blind code
not even things a linter handle.
like results.map( result => someshit( results ));
instead of result.
Or if someshit only uses a single parameter : results.map(someshit);
way to completely miss the point 😛
but thanks for coming out
12:49
I understood your point, but it would have been possible to reduce the possibility of typo happening
But I'm being pedantic, sorry
Yes because I wanted to write a ten line demo just to cover all of the best cases
Lol.

« first day (3156 days earlier)      last day (2015 days later) »