Skip to content

Commit

Permalink
runtime: land support for :preloads
Browse files Browse the repository at this point in the history
  • Loading branch information
darwin committed Aug 19, 2016
1 parent 52db308 commit 3285648
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 10 deletions.
13 changes: 4 additions & 9 deletions src/runtime/dirac/runtime/core.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,18 @@
(:require [dirac.project :refer [get-current-version]]
[dirac.runtime.repl :as repl]
[dirac.runtime.util :refer [display-banner-if-needed! install-feature! resolve-features!]]
[dirac.runtime.prefs :as prefs]
[dirac.runtime.prefs :as prefs :refer [feature-groups known-features]]
[goog.labs.userAgent.browser :as ua-browser]
[goog.labs.userAgent.platform :as ua-platform]))

(def known-features [:repl])
(def default-features [:repl])
(def feature-groups {:all known-features
:default default-features})

; -- CORE API ---------------------------------------------------------------------------------------------------------------

(defn is-feature-available? [feature]
(case feature
:repl (repl/available?)))

(defn available?
([] (available? :default))
([] (available? (prefs/pref :features-to-install)))
([features-desc]
(let [features (resolve-features! features-desc feature-groups)]
(if (empty? features)
Expand All @@ -31,15 +26,15 @@
:repl (repl/installed?)))

(defn installed?
([] (installed? :default))
([] (installed? (prefs/pref :features-to-install)))
([features-desc]
(let [features (resolve-features! features-desc feature-groups)]
(if (empty? features)
false
(every? is-feature-installed? features)))))

(defn install!
([] (install! :default))
([] (install! (prefs/pref :features-to-install)))
([features-desc]
(let [features (resolve-features! features-desc feature-groups)]
(display-banner-if-needed! features feature-groups)
Expand Down
9 changes: 8 additions & 1 deletion src/runtime/dirac/runtime/prefs.cljs
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
(ns dirac.runtime.prefs
(:require-macros [dirac.runtime.prefs :refer [gen-static-prefs]]))

(def known-features [:repl])
(def default-features [:repl])
(def feature-groups {:all known-features
:default default-features})

(def default-prefs
{:dont-display-banner false
{; you can specify a list/vector of features from known-features or a keyword from feature-groups
:features-to-install :default
:dont-display-banner false
:safe-print-level 1
:safe-print-length 10
:agent-host "localhost"
Expand Down
8 changes: 8 additions & 0 deletions src/runtime/dirac/runtime/preload.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
(ns dirac.runtime.preload)

(defn read-config []
(if cljs.env/*compiler*
(get-in @cljs.env/*compiler* [:options :external-config :dirac.runtime/config]))) ; https://github.com/bhauman/lein-figwheel/commit/80f7306bf5e6bd1330287a6f3cc259ff645d899b

(defmacro gen-config []
(or (read-config) {}))
14 changes: 14 additions & 0 deletions src/runtime/dirac/runtime/preload.cljs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
(ns dirac.runtime.preload
(:require-macros [dirac.runtime.preload :refer [gen-config]])
(:require [dirac.runtime.prefs :as prefs]
[dirac.runtime.core :as core]))

; this namespace is intended to be included in cljs compiler :preloads
; overrides for default configuration can be specified in :external-config > :dirac.runtime/config

(def config (gen-config))

(prefs/merge-prefs! config)

(if-not (prefs/pref :suppress-preload-install)
(core/install!))
1 change: 1 addition & 0 deletions test/browser/transcripts/expected/suite01-runtime-api.txt
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ scenario => (:agent-auto-reconnect
:context-availability-total-time-limit
:dont-display-banner
:eval-time-limit
:features-to-install
:install-check-eval-time-limit
:install-check-next-trial-waiting-time
:install-check-total-time-limit
Expand Down

0 comments on commit 3285648

Please sign in to comment.