#Why can I return a function from onMount?

1 messages · Page 1 of 1 (latest)

civic plover
#

Quick question:
I'm allowed to (as in "TypeScript allows me to") return a function from the function I declare inside onMount.
The docs does not comment on this (https://docs.solidjs.com/reference/lifecycle/on-mount), so what does it do? When is the returned function run?

Example:

    onMount(() => {
        const subscriptionID = props.plexer.subscribe(PLAYER_MOVE_EVENT, (event) => {
            if (
                event.playerID === props.backend.localPlayer.id
                && event.locationID === props.colonyLocation.locationID
            ) {
                setUserIsHere(true);
            }
        });

        return () => {
            props.plexer.unsubscribe(subscriptionID);
        }
    })

chrome niche
#

Nothing

civic plover
chrome niche
#

You could add the onCleanup to your onMount?

#

I'm not sure if this will be added tbh

civic plover
#

Is that a thing? I.e.:

onMount(() => {
   onCleanup(()=>{});
})

It feels wrong for some reason

chrome niche
#

You can put onCleanup generally wherever

civic plover
#

Man. I thought I had an incling of how those tracking scopes where implemented. But not anymore. That's for sure

chrome niche
#

fun fact, you can also do effects within effects

civic plover
#

Now, that's illegal

#

Or. At least should be. Sounds ripe for OOM and other crashes

chrome niche
#

Yeah probably, I haven't found a usecase for them but I'm pretty sure it's used in the wild by someone

#

might even be used in solid-primitives somewhere

civic plover
#

People are so concerned with whether they could - they didn't stop to think on whether they should