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
Osmosisch
Sep 9, 2007

I shall make everyone look like me! Then when they trick each other, they will say "oh that Coyote, he is the smartest one, he can even trick the great Coyote."



Grimey Drawer

Shibawanko posted:

i still don't understand why it kept working for the "top" value but not "bottom" when they have basically identical syntax
The reason is that the + operator also does string concatenation while the - operator does nothing to strings, and therefore doesn't give javascript the option to even try that.

In programming, "basically identical" !== "identical" :P

Adbot
ADBOT LOVES YOU

Osmosisch
Sep 9, 2007

I shall make everyone look like me! Then when they trick each other, they will say "oh that Coyote, he is the smartest one, he can even trick the great Coyote."



Grimey Drawer

Shibawanko posted:

so when it sees - and fails to cocatenate, it resorts to treating them like integers by default and therefore it still works?

What would the semantics of
code:
"foo" - "bar"
even be? The - operator is purely numerical, and the expression I wrote will resolve to NaN. It's just that JS has a "keep on trucking" mentality designed to make life superficially easier but actually massively more difficult in practice.

You can try all this out really easily in your browser console if you're curious.

Or you can read big ol' articles like this one and try to cram it into your head.

The basic lesson is to switch to TypeScript if you want your compiler to stop you from doing this kind of thing, or get really handy with debug logging and breakpoints to see what's messing you up.

Osmosisch
Sep 9, 2007

I shall make everyone look like me! Then when they trick each other, they will say "oh that Coyote, he is the smartest one, he can even trick the great Coyote."



Grimey Drawer

Peachfart posted:

Not sure if this is the correct thread, but my work wants me to learn Javascript to work with some automation software, and I have always wanted to learn it. But I haven't done any programming since high school. Is there a recommended online resource for learning Javascript?

Modern Javascript is pretty good.

That said, I would heartily recommend using Typescript from the get-go if at all possible, since its typing lets you avoid a lot of really irritating pitfalls caused by Javascript's loose typing and enables automated refactoring.

Osmosisch
Sep 9, 2007

I shall make everyone look like me! Then when they trick each other, they will say "oh that Coyote, he is the smartest one, he can even trick the great Coyote."



Grimey Drawer
I feel like people starting afresh might be better off with Next rather than create-react-app since the dev environment is so much more pleasant.

Osmosisch
Sep 9, 2007

I shall make everyone look like me! Then when they trick each other, they will say "oh that Coyote, he is the smartest one, he can even trick the great Coyote."



Grimey Drawer

Vino posted:

I'm having trouble figuring out coroutines. This is Typescript.

code:
		let command: any = yield; // error TS2322: Type 'undefined' is not assignable to type 'string'.
What's going on here?

I think you're trying to yield an undefined value - isn't that what 'yield' with no argument does?

Osmosisch
Sep 9, 2007

I shall make everyone look like me! Then when they trick each other, they will say "oh that Coyote, he is the smartest one, he can even trick the great Coyote."



Grimey Drawer
I would absolutely start with typescript, because strong typing is nice to have, especially when learning, since it helps guide your code, and makes exploring other code easier

Osmosisch
Sep 9, 2007

I shall make everyone look like me! Then when they trick each other, they will say "oh that Coyote, he is the smartest one, he can even trick the great Coyote."



Grimey Drawer
The problem there is more Jest than anything else, test with something else like mocha.

Osmosisch
Sep 9, 2007

I shall make everyone look like me! Then when they trick each other, they will say "oh that Coyote, he is the smartest one, he can even trick the great Coyote."



Grimey Drawer
Looping over 800 values is never enough to be something to cause the browser to be sluggish - you probably have some other expensive re-rendering in there.

Either way, if you just keep the cards in an object keyed by id instead of an array, and replace them by going


JavaScript code:

setcards({...cards, [updatedCard.id]: updatedCard})

You can be sure that the issue isn't the updating.

Osmosisch
Sep 9, 2007

I shall make everyone look like me! Then when they trick each other, they will say "oh that Coyote, he is the smartest one, he can even trick the great Coyote."



Grimey Drawer
Oh no, it wasn't meant as a final solution, more as a way of checking whether the updating was the issue. Sorry if that wasn't clear. I was only addressing that part of your post. The point being to update something without creating a new object/reference.

The real issue is of course like you said having a giant data blob as the root of state that causes everything to re-render if you're not careful. One main way to avoid unneccessary re-renders for child components is using useMemo where possible. Looks like splitAtom is also a really nice solution though, hiding the complexity.

Osmosisch
Sep 9, 2007

I shall make everyone look like me! Then when they trick each other, they will say "oh that Coyote, he is the smartest one, he can even trick the great Coyote."



Grimey Drawer
I think it's even clearer if you define the named outer function in the non-assignment way, like so:

TypeScript code:
 function publish (metrics) {
  return async function(input) {
    return metrics.someChainedFuncsThatPublishAMetric(input.exampleKey);
  };
};

Osmosisch
Sep 9, 2007

I shall make everyone look like me! Then when they trick each other, they will say "oh that Coyote, he is the smartest one, he can even trick the great Coyote."



Grimey Drawer
You can also just use the gh-pages module to automate the whole thing on github pages from a single repo.

Osmosisch
Sep 9, 2007

I shall make everyone look like me! Then when they trick each other, they will say "oh that Coyote, he is the smartest one, he can even trick the great Coyote."



Grimey Drawer
So you're just doing this as an exercise right? Because otherwise Sequelize exists and mostly does what you want, I think?

Adbot
ADBOT LOVES YOU

Osmosisch
Sep 9, 2007

I shall make everyone look like me! Then when they trick each other, they will say "oh that Coyote, he is the smartest one, he can even trick the great Coyote."



Grimey Drawer
I mean, in my opinion ORMs are cursed anyway, especially the ones that encourage active-record stuff. I think repository methods that do regular queries combined with proper result type checking with e.g. Zod are a cleaner way to interact with your DB, and have the added benefit of letting you already get out of db-land and into domain logic.

That said, even if it's an exercise I think you could probably get more guidance on your path by peeking at the source code for Sequelize and Zod than from me trying to parse what you're doing and giving targeted advice. Either way, respect for trying something out and posting about it, it's interesting to read!

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