Fork me on GitHub
#luminus
<
2016-11-20
>
Pablo Fernandez14:11:34

@yogthos what’s blahlblah.handler.init-app state supposed to do?

yogthos14:11:33

for a standalone app it doesn't do anything by default, for a war it runs some initialization

yogthos14:11:16

the init/stop functions live in the blahblah.env namespace found under env/dev/clj/blahblah/env.clj and env/prod/clj/blahblah/env.clj respectively

yogthos14:11:42

so you can add custom initialization code for dev/prod environments

yogthos14:11:32

the default functions just log what mode the app is running in, so the dev one has:

(def defaults
  {:init
   (fn []
     (parser/cache-off!)
     (log/info "\n-=[memory_hole started successfully using the development profile]=-"))
   :stop
   (fn []
     (log/info "\n-=[memory_hole has shut down successfully]=-"))
   :middleware wrap-dev})
and the prod one:
(ns memory-hole.env
  (:require [clojure.tools.logging :as log]))

(def defaults
  {:init
   (fn []
     (log/info "\n-=[memory_hole started successfully]=-"))
   :stop
   (fn []
     (log/info "\n-=[memory_hole has shut down successfully]=-"))
   :middleware identity})

Pablo Fernandez14:11:40

@yogthos do you know if I can access the return value of the start function in the stop function/

Pablo Fernandez14:11:55

Or do I have to handle it myself, storing it in an atom for example.

yogthos14:11:52

that's how db state is setup for example:

(defstate ^:dynamic *db*
  :start (conman/connect! {:jdbc-url (env :database-url)})
  :stop (conman/disconnect! *db*))
the start function creates a connection, and the stop function stops it

Pablo Fernandez14:11:17

The db! of course 🙂 Thanks.

Pablo Fernandez14:11:38

BTW, I’m really glad you added a component system to Luminus and mount looks better than component 👍