Fork me on GitHub
#cljfx
<
2023-10-25
>
Zach Raines13:10:46

Is there a way to specify lifecycle opts when using create-app or is the expected workflow to just create the render manually at that point?

vlaaad14:10:33

create-app is basically an example of how you compose different pieces of cljfx together, not THE way to do apps

vlaaad14:10:42

I never use it, and after using cljfx for a long time I now also don't use context, effects and co-effects

vlaaad14:10:02

Just a renderer and mount/unmount is enough

Zach Raines14:10:53

That makes sense. What sort of effect model do you use now? Just bind event handlers directly to the events and explicitly pass state down the tree?

vlaaad14:10:59

I use event maps with handler functions in them: {:fn my-handler} The opt map event handler is usually something like #((:fn %) %)

vlaaad14:10:58

there is usually a state though, and usually the handler updates the state. If all handlers are safe to retry, the map event handler function looks like this: #(swap! the-state (:fn %) %) , and actual handlers used in descs receive two args — state and event object, and return new state, which is semantically very nice

vlaaad14:10:15

There might be situations though where it’s not safe to retry event handlers. In this case, I use a slightly different approach: the map event handler is #(swap! the-state ((:fn %) %)) — the handler is invoked only once, and it has to return a function that will then be used to change the app state, and that returned function is retryable

vlaaad14:10:37

so doing side effects without any changes to the app state is done by performing the side effect in the handler, and returning identity

vlaaad14:10:54

that’s the approach I use in reveal

vlaaad14:10:00

wait no, I don’t use this approach in reveal 😄

vlaaad14:10:01

Instead of {:fn my-handler} , I use {:type ::my-kw} with multi-method dispatching on :type

vlaaad14:10:30

but it’s basically the same with extra layer of indirection via keyword+multimethod. If I was making reveal from scratch again, I’d use :fn approach

Zach Raines14:10:54

Thanks! And thanks for the library. It’s been very nice to use once it clicked. And what do you use instead of context? Just explicitly pass state between components?

vlaaad14:10:35

yes, just let the data flow from the root to the leaves