what the fuck
I’m still working on wasteof.money for snap(.berkeley), but because I know how to use the wasteof api, I have came to the realization that I now have to create a mod with custom blocks (which i am very skilled at)
The .then
statements will only run when the fetch is finished. This is very likely not done when res
is being returned, so it’s still "undefined"
. Does Snap handle promises? If it does, you can either use async/await
(preferred) or just return the promise without the res
part. If not, then you can’t really use fetch
in a Snap block.
This ^
yet another reason to not use javascript
async/await
makes this a lot better
yeah, I'm just saying JavaScript is a mess (said by toadpond)
DreamBerd's true purpose is to make fun of people who make fun of JavaScript. Just look at this abomination:
Just look at this abomination.
typeof NaN === "number"
Yeah, you read that right. JavaScript thinks that 'not a number' is a 'number'. You probably didn't know this.
Yeah, you read that right. They think that 'not a number' is 'not a number'. But 'not a number' is a 'number' as part of the IEFFFF spec. You probably didn't know this.
That's the kind of high level satire you can expect from DreamBerd.
Except... That's not the truth. Here's the real truth:
:)))))
thats a nice opinion.
except for the fact its literally programmed in javascript
Does Snap handle promises?
Yes
use
async/await
(preferred)
ok
return the promise without the
res
part
wait how
return fetch("https://api.wasteof.money/session", requestOptions).then(response => response.text)
But async/await
is still the better option.
It’s returning [object Promise], can you send me some code with async/await?
async/await would do the same thing, it's just syntactic sugar for promises. Snap doesn't seem to support promises, then.
You’re returning a promise there, that’s told to get the text when its done. You’d have to put the alert
inside the then statement, so it only gets called when the promise is actually done. There’s a lot of callback hell involved with dealing with promises as they are. async
/await
solves a lot of that. I’d recommend reading more about promises to understand what they are and how they work: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Using_promises
wait rq can you give me an example of using async/await with this?
const token = await (await fetch(...)).text;
And the function it's wrapped in has to be async, e.g.
// my favorite
const func = async () => {}
// or
const func = async function() {}
// or
async function func() {}