Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
smackfu
Jun 7, 2004

My least favorite JavaScript "typo" is when something wants you to make a variable either camel case or dash case depending on the context. So even though your JavaScript and your HTML have the same variable name, it's not correct and acts like your variable doesn't even exist.

Adbot
ADBOT LOVES YOU

smackfu
Jun 7, 2004

With new and different bugs.

smackfu
Jun 7, 2004

Does anyone have a good training video or such on RxJS and observables etc? Because they make me feel dumb and I am just copying and pasting code from the web to get stuff done. I just wrapped my head around promises and now they are old news.

smackfu
Jun 7, 2004

If I have an ES6 class, is there any difference between:

method(param) {
}

And

method = (param) => {
}

smackfu
Jun 7, 2004

Sounds like you could use a Partial here?

https://netbasal.com/getting-to-know-the-partial-type-in-typescript-ecfcfbc87cb6

smackfu
Jun 7, 2004

If you have an object coming from the backend as JSON would you make that a class or an interface in TypeScript? It seems like it’s basically just cast from the JSON so even if you make it a class you don’t get any class methods with it.

smackfu
Jun 7, 2004

Use WebStorm?

smackfu
Jun 7, 2004

huhu posted:

Each time a new image is passed to the Image component, I want its color value to be included in the theme which OtherComponent and BarView could import from. Would there be a best practice for achieving something like this?

If theme.js is just a non-component container for an object you are mutating, I’m not sure the sub components would re-render when you update it.

Is there a common parent to all the components that use the theme? Maybe you can put the theme as a prop on that?

smackfu fucked around with this message at 15:28 on Sep 3, 2018

smackfu
Jun 7, 2004

Our linting rules (which are generally in sync with AirBnb) require you to use the default export if there is only one export from a file. This seems well intentioned but in practice you often add another export in a future commit and then have to change everyplace the original default export was used. Argh.

smackfu
Jun 7, 2004

I know we have a lot of self taught JavaScript people who used to do Java and their understanding of JavaScript complexities is perhaps... lacking.

smackfu
Jun 7, 2004

Nolgthorn posted:

Even faster calculate the length ahead of time

code:
const j = bar.length;
for(let i = 0; i < j; i++) {
    const foo = bar[i];
}
But true, for..of is notoriously slow. I cannot get enough of it.

Reminds me of code from 20 years ago.

(Unless length is actually calculated on demand, doubtful this is an improvement at all.)

smackfu
Jun 7, 2004

necrotic posted:

Nah, map(Number) is great. Its equally explicit and easier to read.

I’m not a huge fan of the readability because it doesn’t look like a function with the uppercase.

smackfu
Jun 7, 2004

Nolgthorn posted:

Why does eslint "recommend" 2 space tabbing? Eslint's rules are insane based on that.

Of course you can change the default rules but what’s the problem with it?

smackfu
Jun 7, 2004

Roadie posted:

Don't forget the true galaxy brain approach:
JavaScript code:
[...new Set(a.map(JSON.stringify))].map(JSON.parse)

I actually saw some similar code yesterday in a package we are using.
code:
 const improvedSpec = JSON.parse(JSON.stringify(inputSpec));
https://github.com/Surnet/swagger-jsdoc/blob/master/lib/helpers/getSpecificationObject.js

What the heck?

smackfu
Jun 7, 2004

Interesting, I figured they were using stringify to validate the user-provided JSON but couldn’t figure out why they were then parsing and using the result.

smackfu
Jun 7, 2004

We have an internal dependency that takes a mandatory id parameter for one function. Currently, if you forget the parameter, it will error out randomly deep in the code when it calls toString on an undefined id.

What’s a typical way to handle this in JavaScript? Throw an error or console warn (or throw and warn)?

smackfu fucked around with this message at 01:13 on Feb 7, 2019

smackfu
Jun 7, 2004

The worst is when someone converts an ISO date into a date time of midnight UTC on that date (for instance by passing it to parse), then the local time zone is negative (like US ones) so the displayed date ends up one day earlier than you started with.

smackfu
Jun 7, 2004

A good date-time library allows you to choose whether you want a local date, a local time, or an absolute date time, since there are use cases for all of them.

smackfu
Jun 7, 2004

I think the suggestion was that Unix timestamp is sufficient for all problems but it would generally give the unexpected result for a repeating meeting after a DST change.

smackfu
Jun 7, 2004

One of our junior devs used parseInt on an iso date to get the year. How do you even come up with that?

smackfu
Jun 7, 2004


Oh yeah, a stack overflow question and answer from 2010. That’s probably good JavaScript advice in TYOOL 2019.

quote:

using the Date object is just an overkill, and should be avoided since the ISO-8601 format is not widely supported -yet-,

quote:

Hint: Try it on IE8 or below, and even in old Firefox versions, it simply will not work..

smackfu
Jun 7, 2004

Tip posted:

I wasn't saying, "it's the top answer on stack overflow, therefore the most correct!"

Didn’t think that at all, I was just rolling my eyes at the whole stack overflow page. Advice not to use a standard does not age well.

smackfu
Jun 7, 2004

Isn’t arguments more like an array than an object?

smackfu
Jun 7, 2004

Isn’t your use case extraordinarily rare?

smackfu
Jun 7, 2004


WebStorm loves to give syntax errors related to labels when you have a random typo like missing braces. I have never used labels so it’s really barking up the wrong tree.

smackfu
Jun 7, 2004

IAmKale posted:

Some people run ESLint and Prettier side-by-side and I still don't "get it". Isn't ESLint with a sane ruleset like Airbnb's sufficient for ensuring code quality? What does Prettier do that eslint --fix won't?

I think there’s an eslint confit that turns off all the formatting rules for that situation, so they don’t fight.

smackfu
Jun 7, 2004

roomforthetuna posted:

These recent React questions certainly made me feel that way. Everything except Typescript which is pretty okay.

Heh, and I see the TypeScript questions about fighting with the type system for no apparent gains and feel the same way.

smackfu
Jun 7, 2004

And no one noticed until it broke.

smackfu
Jun 7, 2004

I can’t help but feel like hooks are making this more complicated than the old way of doing it.

smackfu
Jun 7, 2004

Osmosisch posted:

No, yarn is superior last i checked.

Also I've never heard of a nodejs installation that doesn't come with npm, interesting.

Yeah, I’m guessing it’s just only available bundled in node and not standalone.

I’m surprised yarn is available as a stand-alone download for that matter, isn’t it just another node package?

smackfu
Jun 7, 2004

The Dark Wind posted:

Does anyone know what could possibly be causing this? Is there some sort of weird IT setting to prevent XSS or something that doesn't allow cookies to be sent through?
We had a similar issue caused by an ad blocker. Despite the user denying they were using one.

smackfu
Jun 7, 2004

Was thinking it would be neat to just have a window with a JavaScript console running all the time, rather than opening Chrome dev tools. Does that exist?

I guess a terminal running node would do the job actually.

smackfu
Jun 7, 2004

There’s a tc39 proposal to add the set theory operators for Set: https://github.com/tc39/proposal-set-methods

Page contains links to polyfills too.

Sets were only added in ES6.

smackfu
Jun 7, 2004

If I have a POST request that seems to follow the rules for being a simple request and doesn’t trigger a CORS OPTIONS preflight, why would it still be blocked by CORS in chrome? It seems like it still wants an Access-Control-Allow-Origin header from the server, but I thought the whole point of “simple requests” was that they are backward compatible with services that predate CORS.

I’m almost surely going to have to wrap this old service in a CORS supporting wrapper, so this is mainly just curiosity.

smackfu
Jun 7, 2004

Thanks, that makes it clearer.

I spent way too long banging my head against this because I thought an existing system was making the request I wanted to make, but it turns out they were running the request from an iframe so it wasn’t cross origin.

smackfu
Jun 7, 2004

fireraiser posted:

Given how with Next.js, you're tied into their routing and data-fetching system, it'd be pretty hard to gently caress it up in the way that you're describing.

Still pretty easy to make a button that switches to another view that is not navigable to.

smackfu
Jun 7, 2004

It’s pretty easy to go around to big “real” websites and see how many of them just send plaintext credentials in their login forms.

For instance, Chase and Citibank have no problem with it. They post username and password as form data. OTOH, Amazon does send an encrypted password.

smackfu
Jun 7, 2004

It does feel annoying that CORS came up around the same time that people decided that you shouldn’t host your UI and your APIs on the same server, so everything is cross-origin now.

Also, the amount of time wasted by Chrome’s CORS error that suggests the “no-cors” option is surely immeasurable.

smackfu
Jun 7, 2004

Oops, yeah. Mixed up cause and effect.

Adbot
ADBOT LOVES YOU

smackfu
Jun 7, 2004

It’s not like React is that complicated a mental model either. The render function has some inputs, some state, and an output. If you want a page that changes what it displays based on something, you just write some basic if-then code that does that.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply