This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2024-04-28
Channels
- # announcements (2)
- # babashka (21)
- # beginners (24)
- # calva (9)
- # cider (7)
- # clj-kondo (12)
- # clojure (116)
- # clojure-europe (5)
- # clojure-korea (2)
- # clojure-norway (3)
- # clojure-poland (1)
- # clojure-spec (5)
- # clojurescript (12)
- # cursive (12)
- # datomic (8)
- # google-cloud (4)
- # honeysql (16)
- # java (18)
- # lsp (10)
- # missionary (14)
- # polylith (12)
- # re-frame (13)
- # releases (4)
- # shadow-cljs (10)
- # sql (10)
- # testify (2)
Hi everyone, starting a new cljs project and we're looking to use helix or uix. Wondering if anyone could recommend state management solutions. Have been reading up on reseda and refx. Also, if anyone has experience with using js state management like jotai, and what the conversion to and from js to clojure data is like. Thank you.
Hi @az. I am using helix and refx as its state managment solutation for an Expo/React Native app. I find it very effective, although it is not a full port of re-frame because re-frame has evolved since refx was created. I don’t know about reseda. I used re-frame and reagent in a previous incarnation of the app, so I was already pretty familiar with re-frame.
Thank you @UGNMGFJG3 glad you brought it up, actually leaning towards refx as well. Happy to hear it's working well for you. Any things to watch out for with refx?
I'm going through a similar exercise at the moment. Started out using uix and refx, but switched over to re-frame the other week, purely to play with re-frame-10x. If you want to keep your options open while you evaluate, it's straightforward to switch between them via a facade, something like the below (n.b. cljserial.utils.uix-reframe just contains the uix-reframe integration helpers from the uix docs https://pitch-io.github.io/uix/docs/interop-with-reagent.html). And then use dbfx/dispatch dbfx/use-sub etc. rather than re-frame/refx directlyh.
(ns cljserial.utils.dbfx
"Facade to allow switching between refx and re-frame for app state management.
Probably don't want to do this long term, but keeping options open for now.
Re-frame is more actively maintained and has some nice dev tooling (re-frame 10x etc).
refx is an adaptation to use more recent react conventions.
Might want to do comparative performance evaluation at some point (though likely a non-issue for our level of complexity). "
(:require [refx.alpha :as refx]
[refx.interceptor]
[refx.interceptors]
[re-frame.core :as rf]
[cljserial.utils.uix-reframe :as rf-utils]))
(defonce impl :re-frame)
(if (= impl :refx)
(do ;; refx aliases
(def reg-sub refx/reg-sub)
(def use-sub refx/use-sub)
(def dispatch refx/dispatch)
(def dispatch-sync refx/dispatch-sync)
(def reg-fx refx/reg-fx)
(def reg-cofx refx/reg-cofx)
(def reg-event-fx refx/reg-event-fx)
(def reg-event-db refx/reg-event-db)
(def inject-cofx refx/inject-cofx)
(def path refx.interceptors/path)
(def after refx.interceptors/after))
(do ;; re-frame aliases
(def reg-sub rf/reg-sub)
(def use-sub rf-utils/use-subscribe)
(def dispatch rf/dispatch)
(def dispatch-sync rf/dispatch-sync)
(def reg-fx rf/reg-fx)
(def reg-cofx rf/reg-cofx)
(def reg-event-fx rf/reg-event-fx)
(def reg-event-db rf/reg-event-db)
(def inject-cofx rf/inject-cofx)
(def path rf/path)
(def after rf/after)))
Good to know @U05TB5C7MDF. My main motivation for using refx and helix was to avoid reagent and use React hooks in my code. Now most of my logic is in the UI code with refx playing more of a supporting role.
Yeah - I'm still using uix rather than reagent. Reagent is installed as a dependency of re-frame, but not actually in use within my codebase. There may be some performance advantage to using refx over re-frame due to it using react hooks under the hood (I haven't done any profiling, nor seen any benchmarks), but my app is pretty simple, and the developer tooling for re-frame is very nice.
Never used Helix but uix is a very straight API to React with some linting attached, it has absolutely no opinion on state management besides whats already provided with React
At work we migrated from re-frame to helix and refx and have been mostly content with the results
@U0479UCF48H thanks, curious if there are things that are less than ideal with this setup vs reframe. Did you and your team look at other solutions for state mgmt?
At one point we considered jotai, a pure JS state management library. It exposes an API near identical to reagent. But really we just wanted to move to a React wrapper that made interop easier and provided marginal performance boosts. The biggest advantage of Helix over Reagent is ease of interop and hooks usage. Reagent does support emitting functional components but they come with additional overhead (benchmarks demonstrating this are buried somewhere in the reagent docs)
I think the biggest downside of refx vs re-frame is having to be comfortable setting up shadow-cljs to alias re-frame.core to refx.alpha for deps that work with both libraries. We use martian-re-frame and the library is fully compatible with refx, but we need to alias namespaces in order to use the library.
Thank you @U0479UCF48H! You opened my eyes. I have converted my refx dependencies to re-frame and now I can use re-frisk-remote again.