This repository has been archived by the owner on Jun 4, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 84
/
common.cljs
47 lines (41 loc) · 1.91 KB
/
common.cljs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
(ns lumo.common
(:require [cognitect.transit :as transit]
[lazy-map.core :refer [lazy-map]]
[cljs.js :as cljs]))
;; =============================================================================
;; Analysis cache
(def ^:private ^:const JSON_EXT ".json")
(defn transit-json->cljs
[json]
(let [rdr (transit/reader :json)]
(transit/read rdr json)))
(defn cljs->transit-json
[x]
(let [wtr (transit/writer :json)]
(transit/write wtr x)))
(defn- load-core-analysis-cache
[state eager? ns-sym file-prefix]
(let [keys [:rename-macros :renames :use-macros :excludes :name :imports
:requires :uses :defs :require-macros :cljs.analyzer/constants :doc]]
(letfn [(load-key [key]
(let [resource (js/$$LUMO_GLOBALS.load (str file-prefix (munge key) JSON_EXT))]
(transit-json->cljs resource)))]
(cljs/load-analysis-cache! state ns-sym
(if eager?
(zipmap keys (map load-key keys))
(lazy-map
{:rename-macros (load-key :rename-macros)
:renames (load-key :renames)
:use-macros (load-key :use-macros)
:excludes (load-key :excludes)
:name (load-key :name)
:imports (load-key :imports)
:requires (load-key :requires)
:uses (load-key :uses)
:defs (load-key :defs)
:require-macros (load-key :require-macros)
:cljs.analyzer/constants (load-key :cljs.analyzer/constants)
:doc (load-key :doc)}))))))
(defn load-core-analysis-caches [state eager?]
(load-core-analysis-cache state eager? 'cljs.core "cljs/core.cljs.cache.aot.")
(load-core-analysis-cache state eager? 'cljs.core$macros "cljs/core$macros.cljc.cache."))