Skip to content

Instantly share code, notes, and snippets.

@zalky
Created October 26, 2017 20:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zalky/47dd7ee21f713b532fcb45093956d7c1 to your computer and use it in GitHub Desktop.
Save zalky/47dd7ee21f713b532fcb45093956d7c1 to your computer and use it in GitHub Desktop.
More on code splitting
{:closure-warnings {:non-standard-jsdoc :off}
:optimizations :advanced
:source-map true
:pseudo-names true
:parallel-build true
:output-dir "js/compiled"
:asset-path "js/compiled"
:modules {:core {:entries #{re-demo.core}
:output-to "js/compiled/app.js"
:depends-on #{:vendor}}
:data {:entries #{re-demo.data}
:output-to "js/compiled/data.js"
:depends-on #{:vendor}}
:vendor {:entries #{reagent.core}
:output-to "js/compiled/vendor.js"}}}
(ns re-demo.core
(:require [cljs.loader :as loader]
[reagent.core :as r]))
(def state
(r/atom {:input "Hello, world!"}))
(defn event->value
[e]
(-> e .-target .-value))
(defn input-handler
[app e]
(let [value (event->value e)]
(loader/load :data
(fn []
((resolve 're-demo.data/update-input) app value)))))
(defn root
[app]
[:input {:value (:input @app)
:on-change (partial input-handler app)}])
(defn init!
[]
(r/render [root state]
(.getElementById js/document "container")))
(defonce _
(loader/set-loaded! :core))
(ns re-demo.data
(:require [cljs.loader :as loader]
[reagent.core :as r]))
(def state
(r/atom {}))
(defn update-input
[app value]
(swap! app assoc :input value))
(loader/set-loaded! :data)
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="">
</head>
<body>
<div id="container"></div>
<script src="js/compiled/cljs_base.js" type="text/javascript"></script>
<script src="js/compiled/app.js" type="text/javascript"></script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment