JavaScript

Topic: Anything JavaScript, ECMAScript including Node, React, ...
Nov 21, 2023 05:55
If you can't use GET/DELETE because you need to send along a body with Identifying information you have RPC (or something similar) and not REST
Nov 21, 2023 05:52
@MileMijatović the URI is the "Resource Identifier" and REST describes the structuring of operations on those Resources. So any ID must be part of the URI (f.e. /user/document with a body {user: 1, doc: 1} is no URI for the document of a user). HTTP GET/DELETE (and OPTION) don't have a request body.
Sep 29, 2023 14:05
typical it's caches from package managers or logfiles growing fast because of debug dumps
Sep 29, 2023 14:03
788
Q: Tracking down where disk space has gone on Linux?

Owen Fraser-GreenWhen administering Linux systems I often find myself struggling to track down the culprit after a partition goes full. I normally use du / | sort -nr but on a large filesystem this takes a long time before any results are returned. Also, this is usually successful in highlighting the worst offen...

Sep 19, 2023 16:00
yay
Sep 7, 2023 13:37
of course you could also use something like interface OperationResult {pending: boolean, success: boolean, item?: string}
Sep 7, 2023 13:35
It's only (a bit) more information for the type system so typescript can decide based on the discriminators success and pending and f.e. OperationResult does not allow pending = true and success = true or item being set when pending/failed.. so more typesafety.
Sep 7, 2023 13:21
like this you could use getString(): OperationResult<string> and return either PendingResult, FailedResult or SuccessResult with the string
Sep 7, 2023 13:20
interface SuccessResult<T> {
    pending: false;
    success: true;
    item: T
}

interface PendingResult {
    pending: true;
    success: false;
    item: null
}

interface FailedResult {
    pending: false;
    success: false;
    item: null;
}

type OperationResult<T> = FailedResult | PendingResult | SuccessResult<T>
Sep 7, 2023 13:20
@Wietlol normaly I'd do this the same way as in other languages: have one routine for getString(...) returning the string and null if it wasn't found and a second routine like isPending(...) for checking if it's loading or not and if that is not an option for whatever reason you can always create a result type with discriminator
Jul 11, 2023 10:45
hm true
Jul 11, 2023 10:43
@VLAZ-onstrike- out of curiousity, shouldn't it be flagged since AI generated answers are currently banned?
Jul 11, 2023 10:40
@salbeira This has nothing to do with "https"/security. HTTP is a plain text (message) protocol and for that it needs restrictions on strings/characters usable in "structured data" - like the Header key-value list - for parsing. To allow arbitrary strings at least for the password in Basic Auth it needs to be escaped/encoded. Base64 is a simple solution. Sending it plain text would break the protocol.
Jun 16, 2023 15:17
@KevinB ah, ok.. thx
Jun 16, 2023 15:13
Does anyone know why SO removed the ability to flag Offtopic questions as.. well.. Offtopic? At least it seems I can't do so anymore and I don't see any alternative for stuff that literally has nothing to do with either software/hardware development or tools.
May 26, 2023 09:20
so more something like that
May 26, 2023 09:20
function App() {
    return (
        <CustomContext.Provider>
            <Header />
            <Content />
            <Footer />
        </CustomContext.Provider>
    );
}

function Content() {
    const [ctxState, setCtxState] = useContext(CustomContext);
    const routes = useRoutes();
    useEffect(() => {
        // something with routes
        setCtxState({...})
    }, [routes, setCtxState])
    return <div>...</div>;
}

function Footer() {
    return (
        <div>
            <CustomContext.Consumer>...</CustomContext.Consumer>
May 26, 2023 09:20
@Wietlol ye, consumer and useContext hooks need to be called inside components which are "inside" the provider
Mar 29, 2023 13:44
@JamesBot me too James, me too
Dec 21, 2022 09:16
@DamodaraSahu didn't test it but documentation says you can set data-type="module" dataset attribute for babel 7.10.0+
Dec 20, 2022 13:34
@illiteratewriter const { innerRef = React.useRef(null) } = props would break the react hook rules (conditional calling a react hook) since React.useRef(null) will only be called when props has no innerRef, so more like const newRef = React.useRef(null); const { innerRef = newRef } = props;
Oct 16, 2022 21:20
const documentRef = useRef<JSX.Element>(null) and use documentRef.current instead of documentRef. Not sure if it's a good idea to create and assign a ReactElement inside a callback.. might blow up, not sure tho
Oct 16, 2022 21:15
Pretty much what the previous and this error tell you to do. documentRef is the reference, documentRef.current is the property which should contain your element
Sep 19, 2022 12:28
:thumbs_up:
Sep 19, 2022 12:23
doesn't that simply return \func_get_args() and the rest is dead code?
Sep 19, 2022 12:21
but there is no rebinding
Sep 19, 2022 12:21
that should call apply on $this->wrapped with given args
Sep 19, 2022 12:20
in that case uhm.. \call_user_func_array([$this->wrapped, "apply"], \func_get_args());
Sep 19, 2022 12:18
ye hehe
Sep 19, 2022 12:17
it expects a method name and "$this->wrapped" does not seem to be one
Sep 19, 2022 12:16
ye
Sep 19, 2022 12:16
ah
Sep 19, 2022 12:12
but dunno
Sep 19, 2022 12:12
@icecub Ah ok, at least it LOOKS ok'ish, maybe $args = \func_get_args(); call_user_func_array([$this->wrapped, $args[0]], array_shift($args))?
Sep 19, 2022 12:00
@icecub well, your solution looks more modern sooo, I'd stick with that
Sep 19, 2022 11:58
ye, not sure if apply is overrideable, also if it's a port from a functional language it might not have an actual intention and is just something that was ported like that and Function.object.apply(...) would be better
Sep 19, 2022 11:55
Sep 19, 2022 11:55
let x = {
    name: "x",
    fun: function() { console.log(`AHHH from ${this.name}`) }
}
let y = {
    name: "y",
    fun: function() { console.log(`WHOO from ${this.name}`) }
}

x.fun.apply.apply(y...
Sep 19, 2022 11:54
@VLAZ try typescript
Sep 19, 2022 11:51
@icecub not sure, not doing much meta programming in php, I remember there is something like call user func array which can be used to call a method on an object with custom arguments
Sep 19, 2022 11:33
just think call by call: Apply calls a method with this and arguments so this.wrapped.apply.apply(this.wrapped, arguments); calls the method (this.wrapped.apply) with this.wrapped as this and arguments as arguments which in turn is: (this.wrapped.apply)(...arguments)
Sep 14, 2022 12:59
So if you have problems with specific width values it is much more likely that either your debounce is faulty or the code which handles the width.
Sep 14, 2022 12:58
As far as I see, there are 2 problems in that code. First: The if statement doesn't belong there. Yes it's highly unlikely that typeof window === 'undefined' and typeof window !== 'undefined' in the same engine BUT the correct and not hacky way would be to do the check in useEffect. The second is the missing dependency on setWindowSize, which shouldn't be much of a problem either.
Sep 2, 2022 08:57
ok, guess that is true
Sep 2, 2022 08:55
@Cerbrus is he? it simply says console.log is called multiple times ("over 40") which is inside a keydown handler handling Tab and I don't see any debouncing/repeatition handling in the code.
Sep 2, 2022 08:45
keyup should only fire once
Sep 2, 2022 08:44
@Cerbrus see docs, there is a repeat flag for that and the deprecation note for keypressed which states to use keydown instead
Sep 2, 2022 08:40
also, it's normal for "keydown" to fire multiple times but "over 40 times" is just so weird specific that it's sounds like a problem in code
Sep 2, 2022 08:39
js object like 'let obj = ' + JSON.stringify(Merged) + ';' or 'let jsonString = \'' + JSON.stringify(JSON.stringify(Merged)) +'\';'??
 

Trash can

Like the recycle bin, but trashier.
Sep 19, 2022 11:55
```tsx
let x = {
name: "x",
fun: function() { console.log(`AHHH from ${this.name}`) }
}
let y = {
name: "y",
fun: function() { console.log(`WHOO from ${this.name}`) }
}

x.fun.apply.apply(y...
```

[Playground Link](https://www.typescriptlang.org/play?#code/DYUwLgBAHhC8EG8ICgJogOwIYFsQC4IAiKIgGlXQDMBXDQ2jAYzAEsB7DACgEpEImnAM7tQAOmDsA5lwAGAQQASyiFQBO7HBAAkCMAAtWQsdjwBfWXzMozyUJACecRJTSmCxB+Veq6DOiwc3HxIghgi4pIysgDqigDy8aoaWroGRia4IBZWyLbIUGKMYlgADqXADiXllVxVjGQQANpQjU0Auu08ANwFRXTVFVVlQ1yFDc0ObZ09yEA)