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
lunar detritus
May 6, 2009


geeves posted:

Will your sign have the JavaScript equivalent of dead fetuses on it?

you mean coffeescript?

Adbot
ADBOT LOVES YOU

Nolgthorn
Jan 30, 2001

The pendulum of the mind alternates between sense and nonsense

Doom Mathematic posted:

$('.this-element-sure-as-heck-does-not-exist').click() just silently succeeding when it really, really would have been more helpful if it failed noisily.

In my last days with jQuery I would almost undo what it was doing.

code:
var ele = $('.this-element-sure-as-heck-does-not-exist');
if (ele[0]) {
    // etc
}

huhu
Feb 24, 2006
For anyone that works regularly with JS but has only ever done so via frameworks or libraries but wants to learn more about JS, https://www.udemy.com/understand-javascript/learn/v4/content is an awesome course. I'm about a third of the way through it and I understand so much more now.

Knifegrab
Jul 30, 2014

Gadzooks! I'm terrified of this little child who is going to stab me with a knife. I must wrest the knife away from his control and therefore gain the upperhand.
Is anyone well versed in Vue? I'm making the transition from React and am having some difficulties with some core concepts.

necrotic
Aug 2, 2005
I owe my brother big time for this!
Using custom attributes for view logic has always been a great idea, glad to see Vue carrying that forward.

Roadie
Jun 30, 2013

Knifegrab posted:

Is anyone well versed in Vue? I'm making the transition from React and am having some difficulties with some core concepts.

The big thing to keep in mind is that Vue syntax is templating rather than literally-the-JS-code like JSX, so every variable binding you do in it is pulling in that var as declared on the corresponding component class.

reversefungi
Nov 27, 2003

Master of the high hat!

huhu posted:

For anyone that works regularly with JS but has only ever done so via frameworks or libraries but wants to learn more about JS, https://www.udemy.com/understand-javascript/learn/v4/content is an awesome course. I'm about a third of the way through it and I understand so much more now.

Seconding this course. I went through it right before I started my bootcamp last year and the time spent watching it has paid itself forward quite nicely.

PaganGoatPants
Jan 18, 2012

TODAY WAS THE SPECIAL SALE DAY!
Grimey Drawer

huhu posted:

For anyone that works regularly with JS but has only ever done so via frameworks or libraries but wants to learn more about JS, https://www.udemy.com/understand-javascript/learn/v4/content is an awesome course. I'm about a third of the way through it and I understand so much more now.

Best course and teacher for Javascript imo. His Node course is really good too.

huhu
Feb 24, 2006
Why is Express the most popular backend solution for JS? At least from the documentation, coming from Flask and Django, Meteor looks much more like a backend solution than Express.

lunar detritus
May 6, 2009


huhu posted:

Why is Express the most popular backend solution for JS? At least from the documentation, coming from Flask and Django, Meteor looks much more like a backend solution than Express.

Express was the first to gain traction, that's it.

Meteor had the issue that it was really experimental when it first started (and _very_ opinionated on how to do things). I think it's not so bad nowadays but its credibility is kinda shot. It does have some hardcore fans though.

huhu
Feb 24, 2006

gmq posted:

Express was the first to gain traction, that's it.

Meteor had the issue that it was really experimental when it first started (and _very_ opinionated on how to do things). I think it's not so bad nowadays but its credibility is kinda shot. It does have some hardcore fans though.

Whelp. Does that mean there are standard ways to structure an Express project at least or does everyone kind of just build their own?

Happy Thread
Jul 10, 2005

by Fluffdaddy
Plaster Town Cop

huhu posted:

Whelp. Does that mean there are standard ways to structure an Express project at least or does everyone kind of just build their own?

Try visiting glitch.me, it immediately sets you up with one in a free sandbox

lunar detritus
May 6, 2009


Every time I have to make a project with a backend I check out what's out there in Javascript and... end up doing it in Rails. It's not that the javascript backend solutions are bad but you end up having to glue so many things together (and sometimes there's no third-party package that actually works so you have to make your own) that it ends up being very time consuming.

Thermopyle
Jul 1, 2003

...the stupid are cocksure while the intelligent are full of doubt. —Bertrand Russell

The good thing about express is it makes you appreciate real opinionated web frameworks.

huhu
Feb 24, 2006

Thermopyle posted:

The good thing about express is it makes you appreciate real opinionated web frameworks.

That was the conclusion I came to looking at the documentation. Could be a fun (awful) exercise. Maybe my next two projects should be a Python web server with sockets and an Express backend.

Blinkz0rz
May 27, 2001

MY CONTEMPT FOR MY OWN EMPLOYEES IS ONLY MATCHED BY MY LOVE FOR TOM BRADY'S SWEATY MAGA BALLS
Express is fine if all you need is a system to map a request to an endpoint and execute a chain of functions to get a response. If I was doing any serious work I wouldn't use it (or JavaScript tbh) because of how un-opinionated it is.

Thermopyle
Jul 1, 2003

...the stupid are cocksure while the intelligent are full of doubt. —Bertrand Russell

Another good thing about express is that if you're shaky on the fundamentals of how a web app server works it will help you understand how more opinionated frameworks work under the hood.

Roadie
Jun 30, 2013
The key thing with Express (and with other API copycat frameworks like Fastify) is that it makes it dead simple to set up a couple of routes that return whatever data or static files, while Meteor wants to make you jump through hoops to get started, has a whole elaborate pub/sub system it wants you to use instead of just making a JSON endpoint for the data generation you've already got, and it doesn't even help with the reasons you'd actually want Node on the server (like isomorphic page rendering).

Compare to, like, next.js, which is strongly opinionated but uses standard npm setup and gives you some real performance benefits for having a Node server.

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe
it's so unopinionated it doesn't even bother to provide basic http parsing outta the box, you gotta install some other poo poo middleware for that https://github.com/expressjs/body-parser

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe
like while i don't mind a modular unopinionated framework (i think django, on the other side of the scale, is worse), express.js showcases the worst trait in the node.js community: move as much random junk into dependencies so it can go unmaintained under someone else's github repo. of course all of these are constantly at v0.0.5 and break every two weeks because some new fad convinced them to rewrite the api.

huhu
Feb 24, 2006
Sounds like I'll broaden my backend knowledge to a language that isn't JavaScript.

Blinkz0rz
May 27, 2001

MY CONTEMPT FOR MY OWN EMPLOYEES IS ONLY MATCHED BY MY LOVE FOR TOM BRADY'S SWEATY MAGA BALLS

Suspicious Dish posted:

it's so unopinionated it doesn't even bother to provide basic http parsing outta the box, you gotta install some other poo poo middleware for that https://github.com/expressjs/body-parser

Meh, I've built a proxy using express and the lack of body parsing was kind of nice. Working with buffers by default can be pretty good.

Happy Thread
Jul 10, 2005

by Fluffdaddy
Plaster Town Cop
WebGL question. I've made a program that draws fine on computers but not on my iPhone. I get a shader linker error and unfortunately it's hiding the details from me.

At the end I get "false" for the linker status:

code:
gl.getProgramParameter( this.program, gl.LINK_STATUS)
(false)

But trying to ask about the problem just returns an empty string:

code:
gl.getProgramInfoLog( this.program )
("")

I have no idea where to go from here, since the debugger is unable to tell me where to start looking. I do get a real WebGLProgram object when I put the expression "this.program" into the Safari remote web inspector console so I know it's not that.

Here's a similar post: https://stackoverflow.com/questions/21803567/glgetshaderinfolog-returns-empty-string-but-shader-program-is-not-linked-correc

quote:

Found it. The reason were several varyings and uniforms that did not specify a precision qualifier:

varying vec4 vPosition;
instead of

varying lowp vec4 vPosition;
This happened on the iPhone 5 as well as in an iPhone simulator. Strange that this does not yield a statement in the log.

It may not be related though - they seem to have not tried using getProgramInfoLog. Both my shaders already say "precision mediump float;" at the beginning. Shouldn't that be enough to avoid confusion? Is iOS particularly fragile about this?

It feels like I'm just grasping at straws randomly because I have no linker error message. I don't know that precision is even what's wrong.

Happy Thread fucked around with this message at 02:08 on Apr 10, 2018

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe
post the sample

Happy Thread
Jul 10, 2005

by Fluffdaddy
Plaster Town Cop
It's http://encyclopediaofcode.glitch.me/. The relevant code trying to do the linking is in the Shader class and it throws, so the debugger will find it. The full source code can be viewed through the navigator at the bottom of the page.

edit: The GLSL / the actual shaders themselves are located in the Phong_Model class.

Happy Thread fucked around with this message at 05:15 on Apr 10, 2018

Knifegrab
Jul 30, 2014

Gadzooks! I'm terrified of this little child who is going to stab me with a knife. I must wrest the knife away from his control and therefore gain the upperhand.
So with async await and try catch making a comeback how do you guys handle variable scooping when assigning new values in a try catch?

I just declare a let variable right above the try block personally.

Tanners
Dec 13, 2011

woof

Knifegrab posted:

So with async await and try catch making a comeback how do you guys handle variable scooping when assigning new values in a try catch?

I just declare a let variable right above the try block personally.

This is what I've taken to doing, even though it is a little ugly/annoying.

Alternatively instead of using a try/catch block you can chain a .catch onto the method you're awaiting. If the catch runs, the variable will be set to whatever you return from the catch.

Its a matter of whatever you find more readable I guess.

Happy Thread
Jul 10, 2005

by Fluffdaddy
Plaster Town Cop
I've successfully combined promises and async-await without getting confused or seeing the need to switch back to try-catch and the weird scope-related considerations that come with it.

Inside an es6 class I do the following. Notice in the second half how I wrap the await usage in an Array.reduce() call to string the promises together and call each one after the previous finishes. This pattern works. It solved my race condition with promises writing to my database out of sequence.

code:
submit
  { const promise_maker = input =>				// Send and handle each individual request
      { return this.fetch_handler( url, JSON.stringify( input) )
          .then ( response_json => { .......success case.......... } )
          .catch(    error => {  document.querySelector("#submit_result").innerHTML += "Error " + error + " when trying to upload.<br>"  } )
      }
      			 // Synchronously await each request and let them each log their own success / failure in their own way
      return all_objects_that_need_to_send_requests.reduce( async ( promise, c ) => {
       await promise;
        return fetch_promise_maker( c );
      }, Promise.resolve());
  }
By the way, above I use the following little helper instead of calling fetch directly... otherwise fetch won't reject on something like a 400 or 500 error and you'd run the "success case" code instead of noticing the server is offline.

code:
fetch_handler( url, body )          // A general utility function for sending / receiving JSON, with error handling.
    { return fetch( url, {
        body: body, method: body === undefined ? 'GET' : 'POST', 
        headers: { 'content-type': 'application/json'  } 
      }).then( response =>
        { if ( response.ok )  return Promise.resolve( response.json() )
          else                return Promise.reject ( response.status )
        } )
    }
This helper assumes that you're always getting back and (optionally) sending a JSON object with each request/response pair. Except on error, when you receive the status string instead.

Happy Thread fucked around with this message at 22:43 on Apr 10, 2018

Happy Thread
Jul 10, 2005

by Fluffdaddy
Plaster Town Cop
Regarding my other post, I guess there might not be too many WebGL people on board who target iOS. I think I might start breaking the code behind my URL above soon (to try to see what triggers the error) if no one else who might know the answer will be needing to see it anymore.

Joda
Apr 24, 2010

When I'm off, I just like to really let go and have fun, y'know?

Fun Shoe
Is it possible in TypeScript to have a namespace defined in multiple different files, and have them just add to that namespace as you import? I.e. how C++ does it.

Specifically I want to have an application specific namespace e.g. MyNamespace and then do

TypeScript code:

import MyNamespace from file
import MyNamespace from file2

MyNamespace.fileModule.x();
MyNamespace.file2Module.y();

This is mostly to avoid type clashes on module names, for instance.

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

Dumb Lowtax posted:

Regarding my other post, I guess there might not be too many WebGL people on board who target iOS. I think I might start breaking the code behind my URL above soon (to try to see what triggers the error) if no one else who might know the answer will be needing to see it anymore.

My eyes just start kind of glazing over at that layout, sorry.

Love Stole the Day
Nov 4, 2012
Please give me free quality professional advice so I can be a baby about it and insult you

Joda posted:

Is it possible in TypeScript to have a namespace defined in multiple different files, and have them just add to that namespace as you import? I.e. how C++ does it.

Specifically I want to have an application specific namespace e.g. MyNamespace and then do

TypeScript code:
import MyNamespace from file
import MyNamespace from file2

MyNamespace.fileModule.x();
MyNamespace.file2Module.y();
This is mostly to avoid type clashes on module names, for instance.

Off the top of my head, it might make more sense to do something like this:

TypeScript code:
import MyNamespace as MyNamespace1 from "./file1";
import MyNamespace as MyNamespace2 from "./file2";
Another idea would be to just do something like...

TypeScript code:
// I didn't test this, I'm just bullshitting here but it'd something like this	
type MyNamespace = MyNamespace1 & MyNamespace2;

Skandranon
Sep 6, 2008
fucking stupid, dont listen to me

Joda posted:

Is it possible in TypeScript to have a namespace defined in multiple different files, and have them just add to that namespace as you import? I.e. how C++ does it.

Specifically I want to have an application specific namespace e.g. MyNamespace and then do

TypeScript code:
import MyNamespace from file
import MyNamespace from file2

MyNamespace.fileModule.x();
MyNamespace.file2Module.y();
This is mostly to avoid type clashes on module names, for instance.

You can't import Namespaces. Namespaces are the new name for what TypeScript previously called "internal modules", which is contrasted with "external modules". External modules are CommonJS type modules where you would explicitly export them. Internal modules are something TypeScript assumes just exists via some mechanism (script tag loading, concatnation, etc). You can not use Namespace and External modules at the same time.

From how you want to use them, it sounds like you want to create files with external modules, using "import * as blah from './file1'". However, I don't think you can combine them with import statements, nor should you really. If you have some library that is a thing, you should use something like Rollup to combine your multiple files together, and then import it again in your app.

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.

Skandranon
Sep 6, 2008
fucking stupid, dont listen to me

smackfu posted:

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.

Yes you should make an interface out of it.

It's not cast in the usual sense, the object is parsed from the JSON. Making an interface out of it just tells the TypeScript compiler that the object TOTALLY LOOKS LIKE THIS TRUST ME. It makes no difference in the actual execution of your code. The reason you don't get methods is you can't encode methods in JSON, as that would be a huge security hole. If you want this item you are transmitting to be a class, create an interface for the fields you want transmitted, then make your class take that interface in the constructor and use it to initialize itself.

Happy Thread
Jul 10, 2005

by Fluffdaddy
Plaster Town Cop

smackfu posted:

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.

I ran into this problem (not with Typescript) but these answers were informative, especially kiewic's. I just ended up going with writing a different custom class object parser for the object in the code of each client page though.

Love Stole the Day
Nov 4, 2012
Please give me free quality professional advice so I can be a baby about it and insult you

smackfu posted:

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.

I just make it a type rather than an interface but for this purpose it really doesn't make any difference, I don't think.

porksmash
Sep 30, 2008
Is there any sort of advanced object filtering library I can leverage instead of rolling my own? I have to implement something on the level of Newegg's Power Search, but also with user selectable comparisons or value ranges, dates and date ranges. I basically want the ability to dynamically generate SQL WHERE clauses and run it against an array of objects.

Bruegels Fuckbooks
Sep 14, 2004

Now, listen - I know the two of you are very different from each other in a lot of ways, but you have to understand that as far as Grandpa's concerned, you're both pieces of shit! Yeah. I can prove it mathematically.

porksmash posted:

Is there any sort of advanced object filtering library I can leverage instead of rolling my own? I have to implement something on the level of Newegg's Power Search, but also with user selectable comparisons or value ranges, dates and date ranges. I basically want the ability to dynamically generate SQL WHERE clauses and run it against an array of objects.

The easiest way I've seen it done in any platform is to leverage the LINQ expression builder in C#, and make the JS just post an object consisting of the set of sorts and filters and having the server do everything.

The server side code looks like this:
https://gist.github.com/afreeland/6733381

Adbot
ADBOT LOVES YOU

Munkeymon
Aug 14, 2003

Motherfucker's got an
armor-piercing crowbar! Rigoddamndicu𝜆ous.



If your data isn't too big, you could do that all client-side with lodash. It can be made to do basically anything LINQ can, but with more awkward syntax.

There's also straight up LINQ ports in JS https://github.com/mihaifm/linq

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