How to swap the contents of a slot in Halogen

hyperisco [3:54 PM]
so, to change what is in a slot, I modify the state such that rendering gives me what I want in the slot, yes? rather than, say, a HalogenM’ effect which substitutes a slot

natefaubion [3:57 PM]
It depends on what you mean by “change what’s in the slot”

hyperisco [3:57 PM]
change the component wholesale

natefaubion [3:57 PM]
You should use different slots

hyperisco [3:57 PM]
huh? why?

natefaubion [3:58 PM]
a slot is a reference to a lifecycle. It’s a weak form of referential identity. Giving it a new “component” does not change the underlying component that’s running

hyperisco [3:58 PM]
wouldn’t it run the finalizer for the component?

natefaubion [3:58 PM]
No, because “components” are just a record of render + eval. It has no identity.

hyperisco [3:59 PM]
when is the finalizer ever run? I am confused now

natefaubion [3:59 PM]
The finalizer is run when a slot is removed
if you want to swap things out, you should give them unique slots

hyperisco [3:59 PM]
right, no identity, that’s right
okay then how do I add a slot and remove a slot? is that just render again?

natefaubion [4:01 PM]
Yes, whenever you render, it diffs the slots
slots that are new are initialized, slots that are removed are finalized, and slots that still exist are given a new input

hyperisco [4:02 PM]
can I move a slot without recreating the component?
I would think the diff wouldn’t work that way

natefaubion [4:03 PM]
Yes, you can move a slot anywhere within the parent component’s DOM
and it will relocate the element

hyperisco [4:03 PM]
oh okay

natefaubion [4:04 PM]
this is one advantage of using slots
the other being that constraints don’t affect identity (edited)

hyperisco [4:09 PM]
mkay this will be a bit jank but I can shuffle them around like a back buffer
I can use an incrementing integer as the position to invalidate the old slot

hyperisco [4:17 PM]
kind of annoying that… well it’d be nice to have a string which was in a string enum
and use that to index a slot
guess that doesn’t ordinarily work out because slots can have different types
@natefaubion is there a shortcut to lift f ~> HalogenM' to HalogenQ f ~> HalogenM'?

natefaubion [4:23 PM]
You mean if you don’t care about lifecycles or inputs?

hyperisco [4:23 PM]
yes

natefaubion [4:24 PM]
Not right now
https://github.com/slamdata/purescript-halogen/pull/576 @garyb added some stuff for that though I think
that is, having some sort of defaultEval record
so you can do defaultEval { request = k }

hyperisco [4:26 PM]
surprisingly clever
how can I render nothing? looking at HTML instances here and not obvious

natefaubion [4:31 PM]
H.text “”

hyperisco [4:31 PM]
mkay isn’t that a text node?

natefaubion [4:31 PM]
Yes

hyperisco [4:31 PM]
well that ain’t nothing
but it’ll do

natefaubion [4:32 PM]
You must return a node in render

hyperisco [4:32 PM]
what seems like the vast emptiness of space is actually a lot of “” text nodes
what you can’t see is the non-printable character in there, and that is what is pushing the stars apart
from the chronicles of “If Programmers Made The Universe”