mirror of https://github.com/status-im/reagent.git
Use cljsjs/react and require clojurescript >= 2740
This means that old style :preamble inclusion is deprecated.
This commit is contained in:
parent
54e0790d73
commit
0b97403d1b
|
@ -9,3 +9,4 @@ outsite/public/js
|
||||||
outsite/public/news
|
outsite/public/news
|
||||||
outsite/public/css
|
outsite/public/css
|
||||||
out
|
out
|
||||||
|
figwheel_server.log
|
||||||
|
|
|
@ -3,34 +3,33 @@ var fs = require("fs");
|
||||||
var vm = require("vm");
|
var vm = require("vm");
|
||||||
var path = require("path");
|
var path = require("path");
|
||||||
|
|
||||||
|
var run = function (src) {
|
||||||
|
global.require = require;
|
||||||
|
vm.runInThisContext(fs.readFileSync(src), src);
|
||||||
|
}
|
||||||
|
|
||||||
var loadSrc = function (mainFile, outputDir, devModule) {
|
var loadSrc = function (mainFile, outputDir, devModule) {
|
||||||
var src = fs.readFileSync(mainFile);
|
|
||||||
var googDir = path.join(outputDir, "goog");
|
var googDir = path.join(outputDir, "goog");
|
||||||
var optNone = false;
|
var optNone = false;
|
||||||
if (outputDir) {
|
if (outputDir) {
|
||||||
optNone = fs.existsSync(path.join(googDir, "deps.js"));
|
optNone = fs.existsSync(path.join(googDir, "deps.js"));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (optNone) {
|
if (optNone) {
|
||||||
var cwd = process.cwd();
|
var cwd = process.cwd();
|
||||||
if (!global.goog) global.goog = {};
|
if (!global.goog) {
|
||||||
|
global.goog = {};
|
||||||
|
}
|
||||||
global.CLOSURE_IMPORT_SCRIPT = function (src) {
|
global.CLOSURE_IMPORT_SCRIPT = function (src) {
|
||||||
require(path.resolve(path.resolve(
|
var s = path.resolve(path.resolve(cwd, path.join(googDir, src)));
|
||||||
cwd, path.join(googDir, src))));
|
run(s);
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
|
|
||||||
var f = path.join(googDir, "base.js");
|
run(path.join(googDir, "base.js"));
|
||||||
vm.runInThisContext(fs.readFileSync(f), f);
|
run(path.join(outputDir, "cljs_deps.js"));
|
||||||
require(path.resolve(cwd, mainFile));
|
|
||||||
goog.require(devModule);
|
goog.require(devModule);
|
||||||
} else {
|
} else {
|
||||||
global.globalNodeRequire = require;
|
run(mainFile);
|
||||||
|
|
||||||
vm.runInThisContext("(function (require) {"
|
|
||||||
+ src
|
|
||||||
+ "\n})(globalNodeRequire);", mainFile);
|
|
||||||
}
|
}
|
||||||
return optNone;
|
return optNone;
|
||||||
};
|
};
|
||||||
|
|
|
@ -8,8 +8,6 @@
|
||||||
[reagentdemo.news :as news]
|
[reagentdemo.news :as news]
|
||||||
[reagent.debug :refer-macros [dbg println]]))
|
[reagent.debug :refer-macros [dbg println]]))
|
||||||
|
|
||||||
(i/import-react)
|
|
||||||
|
|
||||||
(def test-results-comp (atom nil))
|
(def test-results-comp (atom nil))
|
||||||
|
|
||||||
(def github {:href "https://github.com/reagent-project/reagent"})
|
(def github {:href "https://github.com/reagent-project/reagent"})
|
||||||
|
@ -43,7 +41,6 @@
|
||||||
[tools/page-content]
|
[tools/page-content]
|
||||||
[github-badge]])
|
[github-badge]])
|
||||||
|
|
||||||
|
|
||||||
(defn start! [{:keys [test-results]}]
|
(defn start! [{:keys [test-results]}]
|
||||||
(reset! test-results-comp test-results)
|
(reset! test-results-comp test-results)
|
||||||
(tools/start! {:body (fn [] [demo])
|
(tools/start! {:body (fn [] [demo])
|
||||||
|
|
|
@ -13,8 +13,6 @@
|
||||||
(enable-console-print!))
|
(enable-console-print!))
|
||||||
|
|
||||||
(declare page-content)
|
(declare page-content)
|
||||||
(declare prefix)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
;;; Configuration
|
;;; Configuration
|
||||||
|
@ -56,7 +54,7 @@
|
||||||
(assert (ifn? f) (str "couldn't resolve ppage " p))
|
(assert (ifn? f) (str "couldn't resolve ppage " p))
|
||||||
(assert (string? p))
|
(assert (string? p))
|
||||||
[:a (assoc props
|
[:a (assoc props
|
||||||
:href (prefix p)
|
:href p
|
||||||
:on-click (if (:has-history @page-state)
|
:on-click (if (:has-history @page-state)
|
||||||
(fn [e]
|
(fn [e]
|
||||||
(.preventDefault e)
|
(.preventDefault e)
|
||||||
|
@ -166,9 +164,8 @@
|
||||||
(defn html-template [{:keys [title body timestamp page-conf
|
(defn html-template [{:keys [title body timestamp page-conf
|
||||||
opt-none req]}]
|
opt-none req]}]
|
||||||
(let [c @config
|
(let [c @config
|
||||||
base (prefix (str (:js-dir c) "/goog/base.js"))
|
main (str (:js-file c) timestamp)
|
||||||
main (str (prefix (:js-file c)) timestamp)
|
css-file (:css-file c)
|
||||||
css-file (prefix (:css-file c))
|
|
||||||
opt-none (:opt-none c)]
|
opt-none (:opt-none c)]
|
||||||
(reagent/render-to-static-markup
|
(reagent/render-to-static-markup
|
||||||
[:html
|
[:html
|
||||||
|
@ -176,6 +173,7 @@
|
||||||
[:meta {:charset "utf-8"}]
|
[:meta {:charset "utf-8"}]
|
||||||
[:meta {:name 'viewport
|
[:meta {:name 'viewport
|
||||||
:content "width=device-width, initial-scale=1.0"}]
|
:content "width=device-width, initial-scale=1.0"}]
|
||||||
|
[:base {:href (prefix "")}]
|
||||||
[:link {:href (str css-file timestamp) :rel 'stylesheet}]
|
[:link {:href (str css-file timestamp) :rel 'stylesheet}]
|
||||||
[:title title]]
|
[:title title]]
|
||||||
[:body
|
[:body
|
||||||
|
@ -184,11 +182,7 @@
|
||||||
(danger :script (str "var pageConfig = " (-> page-conf
|
(danger :script (str "var pageConfig = " (-> page-conf
|
||||||
clj->js
|
clj->js
|
||||||
js/JSON.stringify)))
|
js/JSON.stringify)))
|
||||||
(if opt-none
|
[:script {:src main :type "text/javascript"}]]])))
|
||||||
[:script {:src base :type "text/javascript"}])
|
|
||||||
[:script {:src main :type "text/javascript"}]
|
|
||||||
(if opt-none
|
|
||||||
(danger :script "goog.require('devsetup');"))]])))
|
|
||||||
|
|
||||||
(defn gen-page [page-name timestamp]
|
(defn gen-page [page-name timestamp]
|
||||||
(reset! page page-name)
|
(reset! page page-name)
|
||||||
|
|
19
project.clj
19
project.clj
|
@ -5,8 +5,9 @@
|
||||||
:description "A simple ClojureScript interface to React"
|
:description "A simple ClojureScript interface to React"
|
||||||
|
|
||||||
:dependencies [[org.clojure/clojure "1.6.0"]
|
:dependencies [[org.clojure/clojure "1.6.0"]
|
||||||
[org.clojure/clojurescript "0.0-2342"]]
|
[org.clojure/clojurescript "0.0-2740"]
|
||||||
:plugins [[lein-cljsbuild "1.0.3"]]
|
[cljsjs/react "0.12.2-5"]]
|
||||||
|
:plugins [[lein-cljsbuild "1.0.4"]]
|
||||||
:resource-paths ["vendor"]
|
:resource-paths ["vendor"]
|
||||||
:source-paths ["src"]
|
:source-paths ["src"]
|
||||||
|
|
||||||
|
@ -24,15 +25,16 @@
|
||||||
{:client {:source-paths ["test"]}}}}
|
{:client {:source-paths ["test"]}}}}
|
||||||
|
|
||||||
:dev-base {:dependencies
|
:dev-base {:dependencies
|
||||||
[[figwheel "0.1.7-SNAPSHOT"]]
|
[[figwheel "0.2.2-SNAPSHOT"]]
|
||||||
:plugins [[lein-figwheel "0.1.7-SNAPSHOT"]]
|
:plugins [[lein-figwheel "0.2.2-SNAPSHOT"]]
|
||||||
:source-paths ["demo"] ;; for lighttable
|
:source-paths ["demo"] ;; for lighttable
|
||||||
:resource-paths ["site" "outsite"]
|
:resource-paths ["site" "outsite"]
|
||||||
:figwheel {:css-dirs ["site/public/css"]}
|
:figwheel {:css-dirs ["site/public/css"]}
|
||||||
:cljsbuild {:builds
|
:cljsbuild {:builds
|
||||||
{:client
|
{:client
|
||||||
{:source-paths ["env/dev"]
|
{:source-paths ["env/dev"]
|
||||||
:compiler {:source-map true
|
:compiler {:main "devsetup"
|
||||||
|
:source-map true
|
||||||
:optimizations :none
|
:optimizations :none
|
||||||
:output-dir
|
:output-dir
|
||||||
"outsite/public/js/out"}}}}}
|
"outsite/public/js/out"}}}}}
|
||||||
|
@ -48,7 +50,8 @@
|
||||||
{:cljsbuild {:builds
|
{:cljsbuild {:builds
|
||||||
{:client
|
{:client
|
||||||
{:source-paths ["env/prod"]
|
{:source-paths ["env/prod"]
|
||||||
:compiler {:optimizations :advanced
|
:compiler {:main "prodsetup"
|
||||||
|
:optimizations :advanced
|
||||||
:elide-asserts true
|
:elide-asserts true
|
||||||
:pretty-print false
|
:pretty-print false
|
||||||
:output-dir "target/client"}}}}}]
|
:output-dir "target/client"}}}}}]
|
||||||
|
@ -65,7 +68,9 @@
|
||||||
|
|
||||||
:cljsbuild {:builds
|
:cljsbuild {:builds
|
||||||
{:client {:compiler
|
{:client {:compiler
|
||||||
{:output-to "outsite/public/js/main.js"}}}}
|
{:output-to "outsite/public/js/main.js"
|
||||||
|
:asset-path "js/out"}}}}
|
||||||
|
|
||||||
:figwheel {:http-server-root "public" ;; assumes "resources"
|
:figwheel {:http-server-root "public" ;; assumes "resources"
|
||||||
|
:repl false
|
||||||
:server-port 3449})
|
:server-port 3449})
|
||||||
|
|
|
@ -10,13 +10,9 @@
|
||||||
<h1>Run "lein figwheel", and open
|
<h1>Run "lein figwheel", and open
|
||||||
<a href="http://localhost:3449">http://localhost:3449</a></h1>
|
<a href="http://localhost:3449">http://localhost:3449</a></h1>
|
||||||
</div>
|
</div>
|
||||||
<script src="js/out/goog/base.js" type="text/javascript"></script>
|
|
||||||
<script src="js/main.js" type="text/javascript"></script>
|
|
||||||
<script>
|
<script>
|
||||||
var pageConfig = {"allow-html5-history": false};
|
var pageConfig = {"allow-html5-history": false};
|
||||||
if (typeof goog != 'undefined') {
|
|
||||||
goog.require('devsetup');
|
|
||||||
}
|
|
||||||
</script>
|
</script>
|
||||||
|
<script src="js/main.js" type="text/javascript"></script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
|
|
||||||
(ns reagent.core
|
(ns reagent.core
|
||||||
(:refer-clojure :exclude [partial atom flush])
|
(:refer-clojure :exclude [partial atom flush])
|
||||||
(:require [reagent.impl.template :as tmpl]
|
(:require [cljsjs.react]
|
||||||
|
[reagent.impl.template :as tmpl]
|
||||||
[reagent.impl.component :as comp]
|
[reagent.impl.component :as comp]
|
||||||
[reagent.impl.util :as util]
|
[reagent.impl.util :as util]
|
||||||
[reagent.impl.batching :as batch]
|
[reagent.impl.batching :as batch]
|
||||||
|
|
Loading…
Reference in New Issue