I needed this for a project where I had a very dense hierarchy of components which was very expensive to emit data from the top down to the bottom which was only used in a very rare case and did not affect visual rendering.
So for this very specific case, I made a tiny module that lets me subscribe to a single value.
Sharing in case it’s useful or someone has done something similar and/or better.
It sounds like something you could also achieve with Thomas’s purescript-halogen-store. Though there’ll be more boilerplate to wire it up as it’s meant to scale beyond the single sender/receiver of your wormhole. (though, that said, it appears your project is on Halogen 5, and I’m 80% sure the Halogen Store library isn’t compatible until 6+ anyway).
But if you’re working with a project using Halogen 6.x, then you could use the following two methods to achieve the same thing. i.e.
Use updateStore in the component eval that’s sending the data.
In the initialize action of the component receiving the data, both
a. Use emitSelected to create an Emitter, then
b. Halogen.subscribe to it
And this will let you skip sending the data as input down through each node of the component hierarchy between the two points.
Definitely similar. My impl. re-uses the subscribe infra of halogen, which I’m already using for other tasks, and unsubscribe automatically works when the component is destroyed, which is nice. I’m not sure about the history but I thought that package was perhaps folded into Halogen at some point.
It is indeed.
Can you explain that?
Interesting, I’ll check that out! Thanks for sharing!
So there doesn’t seem to be any reason to use that package.
Perhaps in Halogen 6 they removed subscriptions or factored it out. If so, that might be the final nail in the coffin for me to move on from Halogen and just fork it. Can’t deal with the API churn.
In Halogen 6 the implementation for subscriptions moved to the halogen-subscriptions library and no longer uses coroutines. The changes I had to make to my applications were pretty small. You can see the changelog for the Halogen 6 release here, which includes advice on how to update your code:
Halogen 7 has no changes besides support for PureScript 0.15, so you’ll find the API is remaining stable through that release.
Thanks Thomas! I’m very slow and very conservative with my use of PureScript and its packages, but I’ll keep that in mind if I decide to upgrade. The migration guide is very appreciated in any case.