|
Boosh! posted:I am moving my Contentful API calls from my React app to my Express API, merely wrapping my Contentful calls in routes: Your code is conspicuously missing a handler for when the promise chain rejects. My suspicion is that either client.getEntries(...) is failing, or response can't be converted to JSON for some reason. I suggest adding a .catch block to properly handle the error case - this may make it easier to diagnose the issue. Doom Mathematic fucked around with this message at 20:51 on May 7, 2020 |
# ? May 7, 2020 20:10 |
|
|
# ? May 15, 2024 08:08 |
|
Doom Mathematic posted:Your code is conspicuously missing a handler for when the promise chain rejects. My suspicion is that either client.getEntries(...) is failing, or response can't be converted to JSON for some reason. I suggest adding a .catch block to properly handle the error case - this may make it easier to diagnose the issue. Sorry I just left it off here, I have in the code. The getEntries call hasn't failed yet; I am able to console log the response every time from my API: Seems like once the getEntries payload is over 60k (it works for anything under) it sends nothing. On the client side, I'm getting this error: GET https://api.mysite.com/getAll net::ERR_EMPTY_RESPONSE I can work around this creating a new, trim object with only the data I need, but I'm still curious as to why this is happening. Boosh! fucked around with this message at 21:57 on May 7, 2020 |
# ? May 7, 2020 21:54 |
|
Logging to console is not the same as serializing to json. Try to JSON.stringify it and see if that fails.
|
# ? May 7, 2020 23:05 |
|
necrotic posted:Logging to console is not the same as serializing to json. Try to JSON.stringify it and see if that fails. That failed too. I copied the JSON.stringified of it and just tried to res.send it with all the Contentful logic removed and still nothing. code:
|
# ? May 8, 2020 00:16 |
|
I've got no clue why this would be happening but some things I would try to gather more data: * Make sure res.json/res.send isn't throwing some kind of exception which you're not seeing, by putting console.log lines after it * Binary chopping your 55kB JSON string down until you have two strings: one which sends, and one, exactly 1 byte longer, which fails. Then see if there's anything weird at that boundary marker, or the size of those two strings * Send something other than JSON but equivalent in size * Skip Express and manually res.write the JSON or whatever in discrete chunks, and see if that works * Double-check the client-size code, maybe post it, and if you're using something high-level, drop down to something lower-level which gives more information about what's happening
|
# ? May 8, 2020 00:57 |
|
That's weird. My only explanation here would be that you have some additional Express middleware that's causing this issue somewhere. From what I've seen on SO, try listing all your routes and check which middleware could be running and try taking them out one-by-one until it works. Here's apparently how you can list the routes (which should include middleware)code:
|
# ? May 8, 2020 09:56 |
|
Thanks guys. I’ll try those out and report back.
|
# ? May 8, 2020 12:34 |
|
Boosh! posted:Thanks guys. I’ll try those out and report back. If you’re using body-parser, you could try upping the limit with code:
You could also try: code:
plasticbugs fucked around with this message at 12:24 on May 9, 2020 |
# ? May 9, 2020 12:11 |
|
plasticbugs posted:If you’re using body-parser, you could try upping the limit with The incoming request is being handled okay. It's the response which they're having problems with.
|
# ? May 9, 2020 12:23 |
|
Does anyone know of a decent library to handle parsing numbers into english words? 10 to ten for example. My research has only turned up sketchy looking libraries but this feels like a common enough problem that there should be a standard.
|
# ? May 12, 2020 16:18 |
|
The obvious one is number-to-text in npm, did you try that? idk, this stackoverflow just updated with an answer and a new package too: https://stackoverflow.com/questions/14766951/convert-digits-into-words-with-javascript MrMoo fucked around with this message at 16:31 on May 12, 2020 |
# ? May 12, 2020 16:29 |
|
MrMoo posted:idk, this stackoverflow just updated with an answer and a new package too: https://stackoverflow.com/questions/14766951/convert-digits-into-words-with-javascript I like the code base of that one. mm,
|
# ? May 12, 2020 17:18 |
|
Nolgthorn posted:I like the code base of that one. mm, God that looks so ugly in javascript. Behold the superior c# solution to the problem code:
|
# ? May 12, 2020 18:34 |
|
I have objects. Some of these objects contain properties which are functions, and these functions return arrays. What I want is an array of objects which has 'expanded out' all of these functions.code:
|
# ? May 12, 2020 23:00 |
|
Bruegels Fuckbooks posted:God that looks so ugly in javascript. Behold the superior c# solution to the problem How dare you, how, dare, you.
|
# ? May 13, 2020 21:41 |
|
Newf posted:I have objects. Some of these objects contain properties which are functions, and these functions return arrays. What I want is an array of objects which has 'expanded out' all of these functions. That's a head scratcher. The first thing to do would be ignore the functions part of it, that's irrelevant, and think about having a `base` and set of arrays to work with. code:
Posting because I tried to do it for a little bit.
|
# ? May 13, 2020 22:20 |
|
Nolgthorn posted:Posting because I tried to do it for a little bit. Thanks for giving me something to start with. I'm pretty inexperienced with Javascript, but if shallow copies of objects are enough, here's a kinda-functional approach that I think works: code:
dirby fucked around with this message at 01:32 on May 14, 2020 |
# ? May 14, 2020 01:28 |
|
Newf posted:Any suggestions? I'm having a hard time wrapping my head around this but I'm certain there's ONE WEIRD RECURSION TRICK that will make this not-too-painful. code:
|
# ? May 14, 2020 02:41 |
|
dirby posted:I tried to do away with wrap which I only call once. Can anyone explain why the line I commented out doesn't work in place of the line that calls wrap? In the wrap() version you capture the value of obj[key] as a parameter, and then return a function that returns that value, and make obj[key] into that function. You could do what you wanted without wrap() by doing code:
roomforthetuna fucked around with this message at 01:58 on May 15, 2020 |
# ? May 15, 2020 01:56 |
|
This was a fun problem! Here is what I came up with, I hope it's legible:JavaScript code:
|
# ? May 16, 2020 20:30 |
|
What's missing from that function assuming it works is a disclaimer mentioning that it is not for humans to understand and never touch it.
|
# ? May 16, 2020 22:41 |
|
Which part do you have trouble understanding?
|
# ? May 16, 2020 23:17 |
|
It's returning an array, I think. Ah, I see you've reduced every value to an array, just a single item for ones that aren't arrays. But then your initial value is an array containing an empty object, assumedly more objects are being added to that array, so why does one need to be included. I don't think an empty object is meant to be a possible result. And I don't see where permutations are coming from. Basically I just can't follow the code. It doesn't adhere to the "clean code" methodology, written by that guy that one time. I'm supposed to be able to make sense of each part of what it's doing at a glance. Nolgthorn fucked around with this message at 01:53 on May 17, 2020 |
# ? May 17, 2020 01:39 |
|
Apologies! So, here is code which does exactly the same as the above but doesn't abuse array methods so heavily. This also means the comments appear in a more logical order.JavaScript code:
code:
|
# ? May 17, 2020 02:12 |
|
Nolgthorn posted:But then your initial value is an array containing an empty object, assumedly more objects are being added to that array, so why does one need to be included.
|
# ? May 17, 2020 02:12 |
|
I am familiar with reduce. If I wasn't it would have been the first thing I looked up as it was being used........ ?
|
# ? May 17, 2020 03:51 |
|
Sorry, I was falling asleep and wasn't very clear. I guess I meant something like "This seems like a reasonable/normal way to use reduce. Rather than explaining this code in particular, other similar examples/tutorials of reduce may help you see at a glance how this code is getting all the permutations."
dirby fucked around with this message at 17:33 on May 17, 2020 |
# ? May 17, 2020 13:02 |
|
I am happy that my problem made you scratch your big fat heads. Do not put them away. Here is my new problem. Less computer-scientific and more engineering. I'm using webmidi.js to ... listen to midi devices. The problem is that users (read: I) often load the page while plugging my device in. The midi init (which runs on page load) has failed, errors follow, and I have to reload the page so that it picks up the device. The midi library's `enable` itself takes a callback. My usage is inside Vue components, and I've wrapped the webmidi library inside a singleton, since components that want access to it keep popping in and out of existence (but never exist simultaneously). JavaScript code:
|
# ? May 21, 2020 18:27 |
|
I made this for people who want their computer to alert them about the Roman numeral equivalent of a number:code:
code:
Kraus fucked around with this message at 20:25 on May 21, 2020 |
# ? May 21, 2020 20:07 |
|
Newf posted:This is the async init() function called by my own singleton's constructor. What is best practice for 'waiting' for a device connection here? code:
roomforthetuna fucked around with this message at 01:02 on May 22, 2020 |
# ? May 22, 2020 00:52 |
|
i dont know much about webmidi.js wrapper but raw webmidi api provides an onstatechange event you can connect to to know when devices hotplug in or out
|
# ? May 23, 2020 01:55 |
|
roomforthetuna posted:Given that the connect function is presumably not async, I'd just do something like (I can't be bothered to look up the JS specific objects for this right now): Yes, I think I'll do a timed retry type thing. Will post a trip report over the weekend. Suspicious Dish posted:i dont know much about webmidi.js wrapper but raw webmidi api provides an onstatechange event you can connect to to know when devices hotplug in or out hot drat e: no, really. it's just to toss my midi init thingy into that onstatechange event if it fails in the first place. Who would have thought to look at the actual browser APIs? Newf fucked around with this message at 04:34 on May 23, 2020 |
# ? May 23, 2020 04:31 |
|
FUN FACT 1: the MIDIAccess object returned by navigator.requestMIDIAccess is not a singleton, so when you are setting it's onstatechange handler you'd better not assume that you'll be overwriting the existing onstatechange handler. Instead, you are adding more and more handlers! FUN FACT 2: A web browser can query USB devices / ports heavily enough that the computer (Windows 10) stops recognizing the insertion or removal of any usb device from any port! The computer will then take ~40 minutes of shut down only to arrive at a BSOD (driver_power_state_failure) who stalls at 0% in its information gathering phase overnight. Happily, the computer seems fine after a hard boot.
|
# ? May 23, 2020 21:40 |
|
Sorry for what is likely a stupid question. I am totally new to JS. I have an array of strings which contain HTML (comes in via a variable in Django). What is the best way to list them (and have the HTML work, if possible)? I tried just doing a for loop through the array that appended them all to a list, but couldn't get it to display anything.
|
# ? May 24, 2020 08:46 |
|
Tuxedo Gin posted:Sorry for what is likely a stupid question. I am totally new to JS. I have an array of strings which contain HTML (comes in via a variable in Django). What is the best way to list them (and have the HTML work, if possible)? I tried just doing a for loop through the array that appended them all to a list, but couldn't get it to display anything. The really dead simple version: JavaScript code:
The 'good' way (which is also the approach used by various rich text editors these day) is to have the data instead be an array of JSON objects that you can parse for specific output: HTML code:
Take this approach a bit further and you get HyperScript (which is philosophically doing basically the same thing as above, just with way more helpers and abstraction), and then take HyperScript further and you get React, which adds more abstraction layers and the power of state management but still basically centers around parsing arrays and turning them into sets of HTML node objects. Roadie fucked around with this message at 11:01 on May 24, 2020 |
# ? May 24, 2020 10:57 |
|
Roadie posted:The really dead simple version: Thank you for the reply. I've got a lot to read up on and learn from.
|
# ? May 25, 2020 02:55 |
|
Hey guys, should I submit this to ECMA as an improvement to JavaScript?code:
|
# ? May 25, 2020 20:58 |
|
what?
|
# ? May 25, 2020 21:49 |
|
Better to make it an npm package with 5 dependencies
|
# ? May 25, 2020 23:06 |
|
|
# ? May 15, 2024 08:08 |
|
Kraus posted:Hey guys, should I submit this to ECMA as an improvement to JavaScript? to be a true js professional, you need one of the following methods in every single line of code - map, reduce, or filter e.g. code:
|
# ? May 26, 2020 06:51 |