RFC: A new cold-event-only version of hyrule

Over the past n days, I’ve been working on fantasy-land branch of hyrule based on two major changes:

I’ve so far made accompanying branches for bolson and deku and the results are quite nice: https://github.com/mikesol/purescript-deku/blob/fantasy-land/test/Test/Main.purs.

  • There are less ways to do things, which means that patterns are more predictable.
  • It’s impossible to introduce arbitrary side effects via useEffect, which makes tracing effects back to their triggers easier.
  • There are more overloaded functions, so it’s just text and click, no more ie text_ and click_.

I’m currently in the middle of migrating the Deku docs. It’s a large project, and I’m noticing that the size of the framework has shrunk by around 20% and entire sections can now be deleted. For example, you can’t just sneak in random numbers anymore using useEffect, so you wind up using classics like Behavior and Free to accomplish the same thing. One really nice result is that the backend-optimizer winds up consolidating all of the side effects in one place if you inline enough, which is a prerequisite in my “Grand Plan” to write a WebGPU framework that straddles the GPU and CPU using just Event and Behavior.

Hot-only events is a major breaking change to hyrule that requires big rewrites if side effects are spread out over lots of cold events. If you’re a hyrule user and you use pure or any other cold event constructors, please respond here or on Discord & we can discuss more. If I get mostly positive sentiment (or if no one cares), my goal is to merge this and a few other outstanding PRs next week.

3 Likes

I wish there was deku-native (implemented like react-native)

P.S. GitHub - Emurgo/yoroi: Yoroi is using react-native

1 Like

I just read Events are best served hot - DEV Community and I feel like this “hot” and “cold” distinction is really important but it’s going to take me some time to digest it.

1 Like

Not sure if this is true. My understanding of the difference is based on something I read a long time ago. Per that article, think the distinction came down to what happens when one subscribes to an event-emitter for the first time:

  • Hot: subscriber’s callback is called once for every new event emitted. Any events emitted in the past are ignored.
  • Cold: subscriber’s callback is immediately called once for every event ever emitted in the past, and then called once for every new event emitted

For example

Time: ---a----b---c---*--d---e--f---->

If * represents “Now” and events a, b, and c are events that fired in the past and d, e, and f are events that will be fired sometime in the future, then

  • Cold: gets a, b, and c immediately and eventually gets d, e, and f.
  • Hot: eventually gets d, e, and f.
2 Likes

This could very well be what Cold means in Rx. For the purposes of hyrule, I mean something similar but a bit different.

Taking your example below, Cold in hyrule before this change was your Cold plus the ability to emit random stuff whenever. So it could be:

  • Cold: never gets a, gets b immediately, gets c some time in the future, and gets x, y and z at random times even though nothing emitted them.

Your example of something emitting all previous values in addition to future ones is actually achievable with folds on Posts (I talk about this a bit here). Cold events in the old hyrule were much more evil - in addition to emitting values, they could execute arbitrary side effects any time after subscription.

1 Like