Hi Tiago,

The compiler produces files ending in .cache.json
You can collect these and merge them together.

I've been doing this (thanks to Mike for suggesting) 
in http://github.com/timothypratley/power-turtle
if you wanted to do the same thing...
Here is how I am doing it:

I define a clojure task that collects the caches into a single file

(ns power-turtle.collect-caches
  (:require
    [clojure.java.io :as io]
    [clojure.string :as string]
    [cognitect.transit :as transit])
  (:import (java.io File)))

(defn collect-caches [caches-dir]
  (into {}
        (for [^File f (file-seq (io/file caches-dir))
              :when (.isFile f)
              :let [filename (.getName f)]
              :when (string/ends-with? filename ".cache.json")
              :let [cache (with-open [in (io/input-stream f)]
                            (transit/read
                              (transit/reader in :json)))]]
          [(symbol (:name cache)) cache])))

(defn -main [caches-dir output-cache-file]
  (println "Collect caches: Started")
  (let [mega-cache (collect-caches caches-dir)]
    (with-open [out (io/output-stream output-cache-file)]
      (transit/write
        (transit/writer out :json)
        mega-cache))
    (println "Collect caches: Done" (count mega-cache) "namespaces")))



Then I load that into the state:

(io/fetch-file!
  "aot/cache.json"
  (fn fetched [txt]
    (let [cache (transit/read (transit/reader :json) txt)]
      (swap! replumb-repl/st update :cljs.analyzer/namespaces merge cache)))))


and now you can call stuff.

I hope that helps.


Regards,
Timothy

On Sunday, July 23, 2017 at 5:31:58 AM UTC-7, Tiago Antão wrote:
>
> Hi,
>
> I am trying to prepare a state to be used under cljs.js/eval. Mostly of 
> what I want to do could be achieved with a loader, but I was wondering if 
> there is any documentation or example on how to prepare a state before 
> usage with eval? The only thing available is empty-state and I was not able 
> to find any documentation on how to change empty-state to add more stuff to 
> it.
>
> Most of my use cases are doing refers of namespaces.
>
> I would prefer to change the start state as in my case using the loader to 
> achieve what I need is actually a hack (I know from the very start all that 
> I want to add).
>
> Thanks,
> Tiago
>

-- 
Note that posts from new members are moderated - please be patient with your 
first post.
--- 
You received this message because you are subscribed to the Google Groups 
"ClojureScript" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojurescript+unsubscr...@googlegroups.com.
To post to this group, send email to clojurescript@googlegroups.com.
Visit this group at https://groups.google.com/group/clojurescript.

Reply via email to