Fork me on GitHub
#clojurescript
<
2018-12-22
>
borkdude15:12:19

Is there a reason why :preloads only works with none and not simple? I want to move a require out of my code, so people can control what specs they loads using cljs.main

dnolen16:12:47

@borkdude it's only there for dev tooling stuff

dnolen16:12:56

no other usage is supported, and no plans to change that

dnolen16:12:14

if somebody wants to manage what specs they load they should just use the normal require mechanisms

borkdude17:12:44

@dnolen sure, that’s fine. just asking. if this would be supported, then people wouldn’t have to make another project for it

dnolen17:12:52

yeah, can't use :preloads for this

richiardiandrea19:12:15

@borkdude the way I have been told to do this is by using different entry namespaces - loading spec instrumentation as you see fit. You could also use a dynamic var initialized by a goog.define...i don't know iyou can get very creative 😃

john19:12:26

@borkdude what about something like:

;; some clj impl namespace
(defn if-env [[if-str? then? else?]]
  (if (-> env/*compiler* deref :options :closure-defines (get if-str?))
    then?
    else?))

john19:12:49

@richiardiandrea beat me to it 😉

richiardiandrea19:12:20

Lol not by much and your has an example so you win 😅

john19:12:27

Then, in your cljs namespace, just do something like:

(ns my.core
  #my/if  ["ensure.load/pp"
           (:require [cljs.pprint :as pp]
                     [cljs.reader :as reader])
           (:require [cljs.reader :as reader])])

borkdude19:12:50

the problem is more like: I make a lib. this lib does something with specs. the user can provide those specs. which specs are provided, I don’t care.

borkdude19:12:40

but now the user must make a separate project to use my lib, instead of just loading my lib with some preloads they can set. not a problem, just more work

borkdude19:12:46

@john cool, how does that work…, is that a reader macro?

john20:12:16

Yeah, put something like {my/if my.impl/if-env} in your data_readers.cljc

john20:12:46

Then in your cljs edn file, something like :closure-defines {ensure.load/pp true}

john20:12:35

Yeah, useful when you want to mess with the namespace declaration, mostly. Otherwise you could probably just use a macro, I suppose.