cljfx

2023-10-25T13:52:46.505439Z

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?

vlaaad 2023-10-25T14:27:33.418039Z

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

vlaaad 2023-10-25T14:28:42.250739Z

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

vlaaad 2023-10-25T14:29:02.602929Z

Just a renderer and mount/unmount is enough

2023-10-25T14:30:53.638429Z

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?

vlaaad 2023-10-25T14:32:59.766559Z

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

vlaaad 2023-10-25T14:35:58.498929Z

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

vlaaad 2023-10-25T14:40:15.724079Z

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

vlaaad 2023-10-25T14:41:37.016569Z

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

vlaaad 2023-10-25T14:41:54.266319Z

that’s the approach I use in reveal

vlaaad 2023-10-25T14:43:00.851659Z

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

vlaaad 2023-10-25T14:44:01.820369Z

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

vlaaad 2023-10-25T14:45:30.931239Z

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

2023-10-25T14:49:54.710529Z

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?

vlaaad 2023-10-25T14:50:35.196319Z

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