Skip to content

Instantly share code, notes, and snippets.

@clyfe
Created January 9, 2020 11:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save clyfe/cdf93215fb29ffe1d034f8d53804c5a5 to your computer and use it in GitHub Desktop.
Save clyfe/cdf93215fb29ffe1d034f8d53804c5a5 to your computer and use it in GitHub Desktop.
ClojureScript Integrant REPL
(ns cljs.user
(:require-macros [x.macros :as m])
(:require [integrant.core :as ig]))
(enable-console-print!)
(def config (m/read-config "config.edn"))
(def system nil)
(defn- halt-system [system]
(when system (ig/halt! system)))
(defn- build-system [build wrap-ex]
(try
(build)
(catch ExceptionInfo ex
(if-let [system (:system (ex-data ex))]
(try
(ig/halt! system)
(catch ExceptionInfo halt-ex
(throw (wrap-ex ex halt-ex)))))
(throw ex))))
(defn- init-system [config]
(build-system
#(ig/init config)
#(ex-info "Config failed to init; also failed to halt failed system"
{:init-exception %1}
%2)))
(defn go []
(halt-system system)
(set! system (init-system config))
:initiated)
(defn halt []
(halt-system system)
(set! system nil)
:halted)
(defn reset []
(halt)
(go))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment