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
Haystack
Jan 23, 2005





So, I'm learning typescript, and want to know if this is a sane way to define a class:

TypeScript code:
interface iItem {
    id: string,
    title: string,
    cost: number,
    quantity?: number,
    target?: string
    sale?: number
}

class Item implements iItem{
    id!: string
    quantity!: 1
    title!: string
    cost!: number
    target?: string
    sale?: number
    constructor(item: iItem) {
        Object.assign(this, item);
    }
}

//The general idea being that I could do something like this
let pants = new Item({id: "pants", title: "pants", cost: 2.99})

It seems to work ok, I'm mostly just wondering if there's a cleaner way to do this. I also wonder if there's a way to get rid of the non-null assertion operators (eg quantity!: 1) on the class definition.

Haystack fucked around with this message at 03:53 on Aug 30, 2023

Adbot
ADBOT LOVES YOU

Haystack
Jan 23, 2005





Sorry nerds, HTMX means that the backend is the frontend now :dealwithit:

Haystack
Jan 23, 2005





HTMX seems like it'd be a decent for, like, a Django/Rails/etc app that already has good serverside templating and minimal dynamic stuff on the frontend.

Haystack
Jan 23, 2005





The truth is in the middle: use tildes instead of carets

Haystack
Jan 23, 2005





HaB posted:

Does anyone know why a <form> with method POST and a url will succeed while an XHR post of the same data to the same url does not?

I assume it's CORS related, since that's what the error was, but is there some structural difference in how the requests are made that makes one fail on the preflight, but the other not?

What's the server's response to your XHR request?

Haystack
Jan 23, 2005





HTMX seems fine for document-driven sorts of webpages that need some light UI elements,. However, it doesn't do any of the heavy state management and reactivity that modern javascript frameworks offer and will probably get in the way if you end up needing that down the line.

That being said, gently caress learning modern javascript frameworks. I had to scratch-build a drop-in shopping cart as a Vue application, and holy gently caress is was that a lot of goddamn layers to learn and evaluate and configure. Just to bitch a bit, I had to:
  • Setup a new IDE with nodejs and whatnot , guessing the correct language features to target along the way. gently caress you, node, I hate you. Commonjs can go burn in hell.
  • Get Vite set up and configured. This was after I tried Parcel first and found out that it was so opinionated as to be useless. Vite was decent, comparatively. A lot, mind you, but genuinely decent.
  • Learn and setup Typescript. Technically optional, but Typescript is nice! Fairly easy to learn, integrates with Vite nicely, makes me code less stupid, and makes my IDE smarter. Thumbs up.
  • Learn all of the new vanilla javascript paradigms that have cropped up since the jQuery era. loving async, man. Why the hell isn't await a top level keyword? Stop poisoning my functions. I hate it. It beats callback hell, I guess.
  • Learn Vue (and associated libraries) and actually code the app. Actually fairly pleasant, compared to the above. It took me longer than I'd care to admit to figure out how get a value out of a ref in the same scope.
Once you get going it's fine, but whoo boy is that a steep learning curve.

Adbot
ADBOT LOVES YOU

Haystack
Jan 23, 2005





Do your complied .js files have associated .map files? Eg, something like assets/appName-[content hash].js.map. Map files let you source code in the debugger for compiled file, as if it weren't compiled, letting you set breakpoints, loggers, etc.

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