|
| 1 | +; Copyright (c) Rich Hickey. All rights reserved. |
| 2 | +; The use and distribution terms for this software are covered by the |
| 3 | +; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) |
| 4 | +; which can be found in the file epl-v10.html at the root of this distribution. |
| 5 | +; By using this software in any fashion, you are agreeing to be bound by |
| 6 | +; the terms of this license. |
| 7 | +; You must not remove this notice, or any other, from this software |
| 8 | + |
1 | 9 | (ns cljs.loader
|
| 10 | + (:require-macros cljs.loader) |
2 | 11 | (:require [goog.object :as gobj])
|
3 | 12 | (:import [goog.module ModuleLoader]
|
4 | 13 | [goog.module ModuleManager]))
|
|
33 | 42 | (.setAllModuleInfo *module-manager* (to-js module-infos))
|
34 | 43 | (.setModuleUris *module-manager* (to-js module-uris))
|
35 | 44 |
|
36 |
| -(defn load |
| 45 | +(defn loaded? |
| 46 | + "Return true if modules is loaded. module-name should be a keyword matching |
| 47 | + a :modules module definition." |
| 48 | + [module-name] |
| 49 | + (assert (contains? module-infos module-name) |
| 50 | + (str "Module " module-name " does not exist")) |
| 51 | + (let [mname (-> module-name name munge) |
| 52 | + module (.getModuleInfo *module-manager* mname)] |
| 53 | + (when (some? module) |
| 54 | + (.isLoaded module)))) |
| 55 | + |
| 56 | +(defn load* |
37 | 57 | "Load a module. module-name should be a keyword matching a :modules module
|
38 | 58 | definition."
|
39 | 59 | ([module-name]
|
40 |
| - (load module-name nil)) |
41 |
| - ([module-name cb] |
| 60 | + (throw (js/Error. "Invalid load call, must provide loader argument"))) |
| 61 | + ([module-name loader] |
| 62 | + (load* module-name loader nil)) |
| 63 | + ([module-name loader cb] |
42 | 64 | (assert (contains? module-infos module-name)
|
43 | 65 | (str "Module " module-name " does not exist"))
|
| 66 | + (assert (loaded? loader) |
| 67 | + (str "Module " loader " not fully loaded, but attempted to " |
| 68 | + "load module " module-name)) |
44 | 69 | (let [mname (-> module-name name munge)]
|
45 | 70 | (if-not (nil? cb)
|
46 | 71 | (.execOnLoad *module-manager* mname cb)
|
|
60 | 85 | (.setLoaded *module-manager* (munge-kw x)))
|
61 | 86 | (.setLoaded *module-manager* (munge-kw module-name))))
|
62 | 87 |
|
63 |
| -(defn loaded? |
64 |
| - "Return true if modules is loaded. module-name should be a keyword matching |
65 |
| - a :modules module definition." |
66 |
| - [module-name] |
67 |
| - (assert (contains? module-infos module-name) |
68 |
| - (str "Module " module-name " does not exist")) |
69 |
| - (let [mname (-> module-name name munge) |
70 |
| - module (.getModuleInfo *module-manager* mname)] |
71 |
| - (when (some? module) |
72 |
| - (.isLoaded module)))) |
73 |
| - |
74 | 88 | (defn prefetch
|
75 | 89 | "Prefetch a module. module-name should be a keyword matching a :modules
|
76 | 90 | module definition. Will download the module but not evaluate it. To
|
|
0 commit comments