My big problem with Typescript is that it's transpiled to Javascript in stead of a real compilation target and will sometimes inherit weird stuff like this scoping and such
|
|
# ? May 9, 2019 19:52 |
|
|
# ? May 20, 2024 22:11 |
|
One thing I will say about Typescript is that its compiler is amazing, way way smaller faster simpler and better than babel. I may even like it more than buble.
|
# ? May 9, 2019 19:57 |
|
Joda posted:My big problem with Typescript is that it's transpiled to Javascript in stead of a real compilation target and will sometimes inherit weird stuff like this scoping and such Considering it predates WASM there wasn't really much choice.
|
# ? May 9, 2019 21:49 |
|
I made a small app to make some of my every day tasks easier. I often find myself needing to alphabetize a list, or put in some filenames and wrap them in img tags with urls, or generate an unordered list. It works, though I'm sure I did a lot wrong and was wondering if anyone had any advice: https://codesandbox.io/s/rj1zq9125q One thing I was confused by was if I change the output to this: code:
|
# ? May 10, 2019 02:17 |
|
First thing, I would generally avoid nested ternary operations, they're a bit hard to understand. As far as you're actual question, it looks like you're trying to do some weird stuff. You're trying to insert stuff that's not text into a text area. If you want to display the text output of generating HTML, I'd do something like the following. code:
|
# ? May 10, 2019 02:30 |
|
huhu posted:First thing, I would generally avoid nested ternary operations, they're a bit hard to understand. I was running into trouble with the normal if/else statements, and figured if it was only one extra statement it wasn't so bad... but I agree. I'm also not so strong on the `template literals` and using dollar signs - gotta read up on those!
|
# ? May 10, 2019 02:38 |
|
LifeLynx posted:I was running into trouble with the normal if/else statements, and figured if it was only one extra statement it wasn't so bad... but I agree. In basic usage they are just strings that have whatever is inside the dollar sign curly brackets evaluated and stuck into the string at that spot. Plus they can be multi-line, which is handy! JavaScript code:
|
# ? May 10, 2019 04:35 |
|
Fun trivia in case it comes up in an interview for any of you, ternary operations don't evaluate whatever. For example someOperation will never run as long as someBoolean is true:code:
Nolgthorn fucked around with this message at 10:37 on May 10, 2019 |
# ? May 10, 2019 10:35 |
|
Lumpy posted:You can also use them as “tagged templates” which pairs them with a custom parsing function, but I have yet to use them that way. Huh, I hadn't heard of those before
|
# ? May 10, 2019 15:02 |
|
Munkeymon posted:Huh, I hadn't heard of those before They can be pretty useful. The thing that shocked me, however, is that tagged templates do not always result in a string: the template function can return whatever it wants and that will be the result. It made sense once I learned that, but it confused me for a little while at first.
|
# ? May 10, 2019 15:27 |
|
Nolgthorn posted:Fun trivia in case it comes up in an interview for any of you, ternary operations don't evaluate whatever. For example someOperation will never run as long as someBoolean is true: FWIW, this is called short-circuit evaluation. The same mechanism is how come you can do something like (using another language to demonstrate how common short-circuiting is): Python code:
C code:
|
# ? May 10, 2019 16:04 |
|
If I was going to do that in javascript I think I'd use the || operator.code:
With the ternary operator I always saw it as a bit of a shortcut selection operation, not that I could (or should) use it to navigate code.
|
# ? May 10, 2019 18:13 |
|
What's the benefit of that ${ } syntax over just appending expressions using + like with regular strings?
|
# ? May 10, 2019 20:58 |
|
It breaks IE. What more of a benefit do you need? For a real answer, it makes templating easier.
|
# ? May 10, 2019 21:12 |
|
Dumb Lowtax posted:What's the benefit of that ${ } syntax over just appending expressions using + like with regular strings? 1) No need to change whatever outer quote if some content inside needs a quote character. Obviously still need to escape ` but that's far less common 2) If you have a lot of interpolation for whatever reason its a lot easier to edit with ${} vs moving around your concatenations 3) You can do multiline strings finally I dunno, maybe some others?
|
# ? May 10, 2019 21:22 |
|
Nolgthorn posted:Fun trivia in case it comes up in an interview for any of you, ternary operations don't evaluate whatever. For example someOperation will never run as long as someBoolean is true: why would this even be the expected case. that's like expecting an else statement to execute when the if conditional is true.
|
# ? May 10, 2019 21:27 |
|
Dumb Lowtax posted:What's the benefit of that ${ } syntax over just appending expressions using + like with regular strings? Template literals are easier to read: JavaScript code:
JavaScript code:
|
# ? May 10, 2019 21:30 |
|
duz posted:It breaks IE. What more of a benefit do you need?
|
# ? May 11, 2019 01:04 |
|
duz posted:It breaks IE. What more of a benefit do you need? typescript will let you use template literals with ie if you're so inclined.
|
# ? May 11, 2019 02:19 |
|
Bruegels Fuckbooks posted:typescript will let you use template literals with ie if you're so inclined. we're not.
|
# ? May 11, 2019 02:24 |
|
Lumpy posted:
I think your JS is broken, there is nowhere you will see "8" and not "eight".
|
# ? May 11, 2019 03:37 |
|
MrMoo posted:I think your JS is broken, there is nowhere you will see "8" and not "eight". Or his browser has become self-aware and is happy to put its own spin on information to be displayed.
|
# ? May 11, 2019 04:22 |
|
Strong Sauce posted:why would this even be the expected case. that's like expecting an else statement to execute when the if conditional is true. Yes apparently it works like if else. Congratulations on knowing that before learning it.
|
# ? May 11, 2019 04:45 |
|
Every experienced programmer knows what a ternary expression is. My university teaches them in the intro courses too. They are incredibly useful shorthand in the hands of someone who knows how to write clean, readable code. Keep them (and most code) out of any other hands than those though.
|
# ? May 11, 2019 05:18 |
|
Dumb Lowtax posted:Keep them (and most code) out of any other hands than those though. https://hackernoon.com/rethinking-javascript-the-if-statement-b158a61cd6cb
|
# ? May 11, 2019 12:43 |
|
I've been trying to debug a weird behavior in my React app and haven't had much luck so far. I'm using useContext and useReducer to access a "global" state object across a bunch of components. Most of the time, but not all of the time, the reducer's "dispatch" function will fire twice. What's weird is that any functions that fire the dispatch will only fire once. Here's a heavily-trimmed overview of the general code structure: code:
This wouldn't really be a problem except that for certain actions, like adding an item to a list, firing twice will mean two items get added. The actual app obviously is a lot more complex and has a lot more code. Any general ideas on what I should be looking for to fix this? tankadillo fucked around with this message at 18:39 on May 11, 2019 |
# ? May 11, 2019 18:34 |
|
Dumb Lowtax posted:Every experienced programmer knows what a ternary expression is. My university teaches them in the intro courses too. They are incredibly useful shorthand in the hands of someone who knows how to write clean, readable code. Keep them (and most code) out of any other hands than those though. I think you're overselling programmer competence here.
|
# ? May 11, 2019 20:22 |
|
You can pry single line ternary statements out of my cold dead unreadable hands.code:
|
# ? May 11, 2019 20:32 |
|
the do statement is a kinda cool replacement for that. honestly though I wish I could just make a binding constant after a certain point:JavaScript code:
|
# ? May 11, 2019 23:49 |
|
Suspicious Dish posted:the do statement is a kinda cool replacement for that. honestly though I wish I could just make a binding constant after a certain point: Yeah, it's not terribly uncommon for me to be wishing for the same thing.
|
# ? May 12, 2019 02:23 |
|
Suspicious Dish posted:the do statement is a kinda cool replacement for that. honestly though I wish I could just make a binding constant after a certain point: JavaScript code:
|
# ? May 12, 2019 02:38 |
|
MrMoo posted:I think your JS is broken, there is nowhere you will see "8" and not "eight". I think my ability to copy/paste on a phone is not up to snuff.....
|
# ? May 12, 2019 03:03 |
|
tankadillo posted:I've been trying to debug a weird behavior in my React app and haven't had much luck so far. Read this: https://medium.com/simply/state-management-with-react-hooks-and-context-api-at-10-lines-of-code-baf6be8302c
|
# ? May 12, 2019 03:06 |
|
Roadie posted:
creates garbage on current v8, not suitable for hot loop
|
# ? May 12, 2019 16:22 |
|
Update to my React issue: after doing some (seemingly) unrelated refactoring in the reducer function last night, the problem has mysteriously disappeared. I guess something about the way the reducer was returning new states was causing unnecessary re-firing? Sometimes React seems too “magical.”
|
# ? May 12, 2019 16:49 |
|
Just for funzies, get chrome debugging set up in vscode, set a breakpoint on a random react lifecycle function or hook, then step into it.
|
# ? May 12, 2019 17:06 |
|
I'm building an app where one aspect of it is that people rate pieces of content in real time. One person's rating would affect others. I'm leaning towards doing this with websockets. Does this make sense? If so, what's the deal with authenticating a websocket connection? Google is telling me lots of different things. I've already got authentication setup with JWTs and Express I'm wondering if I can reuse the JWT somehow and add it to each websocket message sent or when the connection is established. Or should I be doing something else? Edit: Found the snippet below on https://devcenter.heroku.com/articles/websocket-security#authentication-authorization quote:When the client-side code decides to open a WebSocket, it contacts the HTTP server to obtain an authorization “ticket”. huhu fucked around with this message at 01:59 on May 13, 2019 |
# ? May 13, 2019 01:53 |
|
huhu posted:I'm building an app where one aspect of it is that people rate pieces of content in real time. One person's rating would affect others. I'm leaning towards doing this with websockets. Does this make sense? If so, what's the deal with authenticating a websocket connection? Google is telling me lots of different things. I've already got authentication setup with JWTs and Express I'm wondering if I can reuse the JWT somehow and add it to each websocket message sent or when the connection is established. Or should I be doing something else? SSE might be easier to deal with.
|
# ? May 13, 2019 02:19 |
|
huhu posted:I'm building an app where one aspect of it is that people rate pieces of content in real time. One person's rating would affect others. I'm leaning towards doing this with websockets. Does this make sense? If so, what's the deal with authenticating a websocket connection? Google is telling me lots of different things. I've already got authentication setup with JWTs and Express I'm wondering if I can reuse the JWT somehow and add it to each websocket message sent or when the connection is established. Or should I be doing something else? This is like the textbook example for firebase so i would definitely check that out. E: not that that helps with authentication, guess i should read entire posts
|
# ? May 13, 2019 03:01 |
|
|
# ? May 20, 2024 22:11 |
|
uncurable mlady posted:SSE might be easier to deal with. What does that stand for?
|
# ? May 13, 2019 03:05 |