|
LifeLynx posted:Alright, here it is: https://codepen.io/LyfeLynx/pen/ExgdmoM Not necessarily your problem, but if you want to increment a loop that circles back on itself: code:
|
# ? Jan 14, 2021 16:28 |
|
|
# ? Jun 4, 2024 03:13 |
|
LifeLynx posted:Newer code: Looks a lot better. Just one more comment: code:
One more thing: you should always use "use strict"; IMO Edit: Oh, on the order thing LifeLynx posted:It seems to work well. The only problem I have is that the order keeps going up and up. It assigns every item an order number at the start, and keeps incrementing the flex order by 1 every two seconds. The easiest thing I can think of is to periodically reset it by fading the carousel out, say if the flex order reaches 3000 because no one's looking at this for six minutes, doing the prepareCarousel, and then fading back in. I guess what you want is for the current item to have the largest index. You can do that like this (replacing theCarousel.children[currentTarget].style.order = carIndex;): code:
HappyHippo fucked around with this message at 20:17 on Jan 14, 2021 |
# ? Jan 14, 2021 20:02 |
|
Is there anyway to pass a variable from a .try to a .catch? Should I even do that? Basically in Expressjs I'm running a pg-promise call, but I want the error to call the data returned from the pg call, if that makes sense. here's my code: code:
|
# ? Jan 16, 2021 02:04 |
|
Put a let someVar before the promise starts and then reassign it as needed.
|
# ? Jan 16, 2021 02:48 |
|
sweet thanks
|
# ? Jan 16, 2021 02:51 |
|
is there anyway to access the Dom and do javascript css manipulation with Express/Node? Like say I want to have a conditional on a form, if you check this box open up these two fields from display:none to whatever? I think I might be hitting a point in my project where PUG needs to be replaced with a full on front end system? Thanks!
|
# ? Jan 17, 2021 02:40 |
|
Empress Brosephine posted:is there anyway to access the Dom and do javascript css manipulation with Express/Node? If the user is interacting with the page, it is out of express’ hands. You want to use the original intent of JS, running in the browser.
|
# ? Jan 18, 2021 05:26 |
|
Yeah that's a bummer but not unexpected. Thanks!
|
# ? Jan 18, 2021 12:45 |
Empress Brosephine posted:is there anyway to access the Dom and do javascript css manipulation with Express/Node? That's frontend js stuff, unless you do all your rendering server side in which case you'd send the state of the page back to the server for every action and get fresh html. Probably more complicated for a small use case than just having some frontend js
|
|
# ? Jan 18, 2021 13:16 |
|
If all I want to do is a conditional form id be better just doing a small frontend script then installing something like react or vue right?
|
# ? Jan 18, 2021 14:31 |
|
Empress Brosephine posted:If all I want to do is a conditional form id be better just doing a small frontend script then installing something like react or vue right? tbh something like that is pretty solidly in the react wheelhouse. if it were ten years ago I would say do vanilla js, but there are actually enough ways to gently caress up conditional forms in vanilla js (wrt input sanitization) that you might actually want to use react for this.
|
# ? Jan 18, 2021 14:41 |
|
I'll do that then probably. I need to make a simple search page for accessing a database so the extra functionality might not hurt. Or maybe it'll be time to check out Svelte. Thanks everyone.
|
# ? Jan 18, 2021 14:45 |
|
Empress Brosephine posted:I'll do that then probably. I need to make a simple search page for accessing a database so the extra functionality might not hurt. Or maybe it'll be time to check out Svelte. If you've already got an Express backend, you may want to look at using Next.js, which lets you get a working React frontend right out of the box (no need to gently caress around with Webpack, etc) and includes Express-like server functionality so you can do everything with a single dev server.
|
# ? Jan 22, 2021 22:56 |
|
Ill probably do that; I guess most people when using react just use express as a API generator and work off of that?
|
# ? Jan 23, 2021 00:11 |
|
My last project queried Azure Functions, but otherwise, yes. It doesn’t really matter what you use as your backend. Django Rest Framework is popular too.
|
# ? Jan 23, 2021 00:18 |
|
yeah, I think my broke brain just loves express and I don't know why. Nothing else clicks except for this, but I also enjoy doing CRUD operations a lot too. I think I have a future in mediocrity but that's a-ok with me. I'll probably try nextjs then especially if it easily integrates with PG-Promise, otherwise I guess I can build a api using express but that sounds like twice the work imho
|
# ? Jan 23, 2021 01:47 |
|
Anyone know how Set ended up implemented the way it is in javascript? I am quite baffled by Set.keys() vs Set.values() vs Set.entries(). It also appears union, intersection and difference weren't actually implemented, you need to convert to an array? Edit: And also Maps. "The keys of an Object are Strings, where they can be any value for a Map. " Why is this useful? huhu fucked around with this message at 19:19 on Jan 23, 2021 |
# ? Jan 23, 2021 19:04 |
|
huhu posted:Anyone know how Set ended up implemented the way it is in javascript? I am quite baffled by Set.keys() vs Set.values() vs Set.entries(). It also appears union, intersection and difference weren't actually implemented, you need to convert to an array? Set's keys and values are for looking up whatever the set contains efficiently, it might be a very complex object. If you find you need to iterate through it or keep track of keys and values, maybe it's not the right data structure for the job. I don't know how it ended up as it is, but it's fair to say it's not a native thing since day 1 so there's bound to be a bit of scaffolding. While I'm sure there are plenty of libraries with union functions etc if it isn't standard, a union or an intersection isn't a property of one set, therefore it doesn't make that much sense to have that function belong to the set itself. Whereas the entries do, so set.entries() does. As for maps, I guess it might be useful if you would otherwise have to write a hashcode for whatever it is that you use to look up values with. There are other advantages to using maps over objects outlined here: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map Hashmaps are one of my favorite data structures, so I'd probably use it just to feel cool. Ola fucked around with this message at 19:50 on Jan 23, 2021 |
# ? Jan 23, 2021 19:43 |
|
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.
|
# ? Jan 24, 2021 01:43 |
|
huhu posted:Anyone know how Set ended up implemented the way it is in javascript? I am quite baffled by Set.keys() vs Set.values() vs Set.entries(). It also appears union, intersection and difference weren't actually implemented, you need to convert to an array? I assume somebody somewhere must know but when Gary Bernhardt wondered the same thing about a year ago nobody could offer a reasonable explanation. Set.keys() and Set.entries() are quite useless in practice, but I guess if you have some cursed code that treats sets and arrays the same it could maybe somehow come in handy. The lack of set operators is also quite bizarre. As for Map, there's plenty of use cases for keying a dictionary by things that aren't strings - most obvious would be object instances or functions, but you can also use types or classes for example. In most cases you could probably achieve the same thing by just stringifying the key, but it's nice to not have to bother. Ola posted:While I'm sure there are plenty of libraries with union functions etc if it isn't standard, a union or an intersection isn't a property of one set, therefore it doesn't make that much sense to have that function belong to the set itself. Whereas the entries do, so set.entries() does. Set.entries() makes no sense though (it returns an array of [value, value] for each member of the set, mimicking what Array.entries() does, except a set doesn't actually have keys so the result is nonsense). Also, in basically every other major language the set operations are instance methods on instances of the Set type, as in someSet.intersectWith(otherSet). Off the top of my head, Python, C#, Rust and Java sets all work like this, and the proposed implementation smackfu linked to also does the same. You could of course implement standalone set operators as functions that take sets, but most set operators other than union/intersection aren't commutative so I don't think it'd be any improvement in readability to do that. Having a Set type without the set operators is a glaring omission. TheFluff fucked around with this message at 15:58 on Jan 24, 2021 |
# ? Jan 24, 2021 15:50 |
|
TheFluff posted:Having a Set type without the set operators is a glaring omission. ES is a tiny language surrounded by glaring omissions, so same as it ever was, I guess.
|
# ? Jan 25, 2021 20:03 |
|
Hey goons hoping one of you can help out. I’m trying to get this for loop under the ArrayCheck function to run and add values, but pg-promise skips right over it and I’m not sure why. Heres my entire express code. I’m not even sure if im doing this right. Basically I have 7 line items that I need to see if there’s a value in and then push the value to the array so I can insert it into a DB Everything works except for the arrayCheck call, and even when I had it outside a array PG Promise would still ignore it Thanks for all the help code:
|
# ? Jan 25, 2021 21:06 |
|
Empress Brosephine posted:Hey goons hoping one of you can help out. I’m trying to get this for loop under the ArrayCheck function to run and add values, but pg-promise skips right over it and I’m not sure why. Heres my entire express code. I’m not even sure if im doing this right. Basically I have 7 line items that I need to see if there’s a value in and then push the value to the array so I can insert it into a DB Everything works except for the arrayCheck call, and even when I had it outside a array PG Promise would still ignore it Your function is trying to use a bunch of things that don't exist in the function's scope and so will get undefined or immediately die to trying-to-access-a-property-of-undefined errors, and arrayInsert is going to be a Promise for undefined because arrayInsert doesn't return anything and it's not an async function. Also, your isEmpty check is always going to be false because you're adding a stringified number to what you're checking. It's really unclear what you're even trying to do here. Roadie fucked around with this message at 21:27 on Jan 25, 2021 |
# ? Jan 25, 2021 21:21 |
|
Yeah I changed them to this type of syntax if (isEmpty(req.body[`goal${x}`])) I’m just being lazy and don’t want to write out 100 if (req.body.goal1.length > 0) if (req.body.goal2.length > 0) if statements
|
# ? Jan 25, 2021 21:28 |
|
You might start by writing arrayCheck to take all the values it cares about as parameters because, as-is, it's hard to reason about what it's operating on.
|
# ? Jan 25, 2021 21:50 |
|
Thanks for the tip. Tried it but still no go. It’s like PG-Promise refuses to call the function
|
# ? Jan 25, 2021 22:08 |
|
Empress Brosephine posted:Thanks for the tip. Tried it but still no go. It’s like PG-Promise refuses to call the function Are you actually returning a value from it?
|
# ? Jan 25, 2021 22:22 |
|
Yeah , I think the error lies within pg-promise as it refuses to call the function, even if all thats in the function is console.log('hi'). I’m wondering if the solution is to just run a transaction sql insert twice here’s the updated code: code:
|
# ? Jan 25, 2021 22:25 |
|
im the worlds dumbest loving idiot, my for loop was backwards I was doing x >= 7 instead of x<=7
|
# ? Jan 26, 2021 00:43 |
|
Empress Brosephine posted:im the worlds dumbest loving idiot, my for loop was backwards I was doing x >= 7 instead of x<=7 This is why you should map/forEach or for...of whenever possible. Can't have errors with manual loops (taps forehead) if you don't have manual loops. Stuff like: JavaScript code:
Roadie fucked around with this message at 01:24 on Jan 26, 2021 |
# ? Jan 26, 2021 01:17 |
|
Roadie posted:This is why you should map/forEach or for...of whenever possible. Can't have errors with manual loops (taps forehead) if you don't have manual loops. I totally agree with not using regular for loops unless it's absolutely necessary. That said, foreach has a couple of problems: 1) Break/continue doesn't work. Only way to short circuit is to throw an exception. 2) It has GC pressure issues on many platforms because an object is created for every property in the object. Not super well implemented. I'd also recommend not using for ... in because it does weird poo poo if you try to iterate arrays. For ... of is currently the least lovely way to foreach imo.
|
# ? Jan 26, 2021 01:59 |
|
I thought I read you can't use map over objects
|
# ? Jan 26, 2021 02:06 |
|
Empress Brosephine posted:Yeah , I think the error lies within pg-promise as it refuses to call the function, even if all thats in the function is console.log('hi'). and Empress Brosephine posted:im the worlds dumbest loving idiot, my for loop was backwards I was doing x >= 7 instead of x<=7 are describing very different things. Did you put the log call in the for loop and conclude it wasn't running the function from that?
|
# ? Jan 26, 2021 16:54 |
|
Yeah the log call was in the loop and then I put a log call outside the loop, saw it was being called and that's what clicked in my monkey brain. About 7 hours later
|
# ? Jan 26, 2021 16:57 |
|
Empress Brosephine posted:I thought I read you can't use map over objects you can't but you can create an array of the object's keys or values and map over those JavaScript code:
|
# ? Jan 27, 2021 00:14 |
|
What makes mithril a framework instead of a library? I feel like it has more in common with jQuery than Vue.
|
# ? Jan 27, 2021 18:01 |
|
It looks like a virtual Dom system which is way more like Vue or React than jQuery.
|
# ? Jan 27, 2021 19:00 |
|
Grump posted:you can't but you can create an array of the object's keys or values and map over those I figured they were talking about Map
|
# ? Jan 27, 2021 19:03 |
|
Empress Brosephine posted:I thought I read you can't use map over objects In addition to the already mentioned Object.keys() and Object.values(), Lodash provides _.mapKeys() and _.mapValues(), which are super handy for the pretty common case where you want to apply some kind of transformation to each of an object's keys or values but you don't want to mutate the object in place. So, for a trivial example, code:
|
# ? Jan 28, 2021 13:39 |
|
|
# ? Jun 4, 2024 03:13 |
|
Oh that's sweet, these are some cool tools thanks goons. I hope to be able to share my finished project
|
# ? Jan 28, 2021 13:41 |