Created
January 9, 2020 11:42
-
-
Save clyfe/cdf93215fb29ffe1d034f8d53804c5a5 to your computer and use it in GitHub Desktop.
ClojureScript Integrant REPL
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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