mount

theequalizer73 2024-09-16T18:45:39.040329Z

Hi Friends, I’m refactoring a codebase and need to move one mount state to another namespace (to avoid circular reference), but in order to do it, I need to change many files in the application and the PR will be huge (mostly fixing clj-kondo warnings). So what I’m trying to do is to create a new state (mount/defstate…) in the new namespace, with all the functionality from the old state, but I would like to keep the old state in the old namespace (referenced everywhere in the code). The state I’m trying to move is a database connectable with connection pool, so i cannot have 2 of the same. How can I refactor my old state, to point to the new one?

tolitius 2024-09-17T18:02:00.075059Z

(ns new)

(defstate database-connection
          :start (start-db (-> env/config [:db]))
          :stop (stop-db db))
this:
(ns old
  (:require [new]))

(defstate database-connection :start new/database-connection)
or (if you good with just a var)
(ns old
  (:require [new]))

(def database-connection new/database-connection)

theequalizer73 2024-09-17T21:15:22.230649Z

I tried both options yesterday but something didn’t work. I was using next.jdbc and sometimes the code couldn’t get a datasource from the old state, so I decided to update all the code base to reference the new state. Thank you though. 🙂

tolitius 2024-09-18T14:11:30.702349Z

> I decided to update all the code base to reference the new state. yep, that’s the best! metal