From 942619cfcf8a3632aab7e958df2c1c066c336d76 Mon Sep 17 00:00:00 2001 From: Frederic Merizen Date: Fri, 19 Feb 2016 09:46:21 +0100 Subject: [PATCH] Switch from cljx to cljc This forces to upgrade to a newer version of codox --- project.clj | 20 +-- .../reagi/core.cljx => cljc/reagi/core.cljc} | 140 +++++++++--------- 2 files changed, 73 insertions(+), 87 deletions(-) rename src/{cljx/reagi/core.cljx => cljc/reagi/core.cljc} (84%) diff --git a/project.clj b/project.clj index e06432e..b351eef 100644 --- a/project.clj +++ b/project.clj @@ -6,22 +6,12 @@ :dependencies [[org.clojure/clojure "1.7.0"] [org.clojure/core.async "0.2.374"] [org.clojure/clojurescript "1.7.228"]] - :plugins [[codox "0.6.7"] - [lein-cljsbuild "1.1.2"] - [com.keminglabs/cljx "0.3.2"]] - :source-paths ["src/clojure" "src/cljs"] + :plugins [[lein-codox "0.9.4"] + [lein-cljsbuild "1.1.2"]] + :source-paths ["src/cljc"] :test-paths ["test/clojure"] - :hooks [cljx.hooks] - :cljx - {:builds [{:source-paths ["src/cljx"] - :output-path "target/classes" - :rules :clj} - {:source-paths ["src/cljx"] - :output-path "target/classes" - :rules :cljs}]} - :codox {:sources ["target/classes"]} :cljsbuild - {:builds [{:source-paths ["target/classes"] + {:builds [{:source-paths ["src/cljc"] :compiler {:output-to "target/main.js" :optimizations :whitespace}}]} :profiles @@ -33,7 +23,7 @@ :test {:plugins [[com.cemerick/clojurescript.test "0.3.0"]] :dependencies [[clj-async-test "0.0.3"]] :cljsbuild - {:builds ^:replace [{:source-paths ["target/classes" "test/cljs"] + {:builds ^:replace [{:source-paths ["src/cljc" "test/cljs"] :compiler {:output-to "target/test.js" :optimizations :whitespace}}] :test-commands {"unit-tests" ["phantomjs" :runner "target/test.js"]}}}} diff --git a/src/cljx/reagi/core.cljx b/src/cljc/reagi/core.cljc similarity index 84% rename from src/cljx/reagi/core.cljx rename to src/cljc/reagi/core.cljc index 296ab79..75c7922 100644 --- a/src/cljx/reagi/core.cljx +++ b/src/cljc/reagi/core.cljc @@ -2,17 +2,13 @@ "Functions and types for functional reactive programming." (:refer-clojure :exclude [constantly count cycle deliver filter flatten map mapcat merge reduce remove time]) - #+clj - (:import [clojure.lang IDeref IFn IPending]) - #+clj - (:require [clojure.core :as core] - [clojure.core.async :as a :refer [go go-loop ! !!]]) - #+cljs - (:require [cljs.core :as core] - [cljs.core.async :as a :refer [!]]) - #+cljs - (:require-macros [reagi.core :refer [behavior]] - [cljs.core.async.macros :refer [go go-loop]])) + #?@(:clj [(:import [clojure.lang IDeref IFn IPending]) + (:require [clojure.core :as core] + [clojure.core.async :as a :refer [go go-loop ! !!]])] + :cljs [(:require [cljs.core :as core] + [cljs.core.async :as a :refer [!]]) + (:require-macros [reagi.core :refer [behavior]] + [cljs.core.async.macros :refer [go go-loop]])])) (defprotocol ^:no-doc Signal (complete? [signal] @@ -30,7 +26,7 @@ Boxed (unbox [_] x)) -#+clj (ns-unmap *ns* '->Completed) +#?(:clj (ns-unmap *ns* '->Completed)) (defn completed "Wraps x to guarantee that it will be the last value in a behavior or event @@ -46,24 +42,24 @@ x (reify Boxed (unbox [_] x)))) -#+clj -(extend-protocol Boxed - Object (unbox [x] x) - nil (unbox [x] x)) +#?(:clj + (extend-protocol Boxed + Object (unbox [x] x) + nil (unbox [x] x))) -#+cljs -(extend-protocol Boxed - default - (unbox [x] x)) +#?(:cljs + (extend-protocol Boxed + default + (unbox [x] x))) (deftype Behavior [func cache] IDeref - (#+clj deref #+cljs -deref [behavior] + (#?(:clj deref :cljs -deref) [behavior] (unbox (swap! cache #(if (instance? Completed %) % (func))))) Signal (complete? [_] (instance? Completed @cache))) -#+clj (ns-unmap *ns* '->Behavior) +#?(:clj (ns-unmap *ns* '->Behavior)) (defn behavior-call "Takes a zero-argument function and yields a Behavior object that will @@ -84,8 +80,8 @@ (def time "A behavior that tracks the current time in seconds." - #+clj (behavior (/ (System/nanoTime) 1000000000.0)) - #+cljs (behavior (/ (.getTime (js/Date.)) 1000.0))) + #?(:clj (behavior (/ (System/nanoTime) 1000000000.0)) + :cljs (behavior (/ (.getTime (js/Date.)) 1000.0)))) (defn delta "Return a behavior that tracks the time in seconds from when it was created." @@ -145,39 +141,39 @@ (recur))))) m)) -#+clj -(defn- peek!! [mult time-ms] - (let [ch (a/chan)] - (a/tap mult ch) - (try - (if time-ms - (first (a/alts!! [ch (a/timeout time-ms)])) - (!! ch (box msg)) stream)) - #+cljs (-invoke [stream msg] (do (go (>! ch (box msg))) stream)) + #?(:clj (invoke [stream msg] (do (>!! ch (box msg)) stream)) + :cljs (-invoke [stream msg] (do (go (>! ch (box msg))) stream))) Observable (port [_] ch) @@ -217,16 +213,16 @@ (dispose [_] (doseq [d @disposers] (d)) (a/close! ch)) (on-dispose [_ d] (swap! disposers conj d)) - #+clj Object - #+clj (finalize [stream] (dispose stream))) + #?@(:clj [Object + (finalize [stream] (dispose stream))])) -#+clj (ns-unmap *ns* '->Events) +#?(:clj (ns-unmap *ns* '->Events)) (defn- no-op []) (def ^:private no-value - #+clj (Object.) - #+cljs (js/Object.)) + #?(:clj (Object.) + :cljs (js/Object.))) (defn- no-value? [x] (identical? x no-value)) @@ -402,8 +398,8 @@ (reduce #(%2 %1) init stream)) (def ^:private empty-queue - #+clj clojure.lang.PersistentQueue/EMPTY - #+cljs cljs.core.PersistentQueue.EMPTY) + #?(:clj clojure.lang.PersistentQueue/EMPTY + :cljs cljs.core.PersistentQueue.EMPTY)) (defn buffer "Buffer all the events in the stream. A maximum buffer size may be specified, @@ -443,8 +439,8 @@ (map first))) (defn- time-ms [] - #+clj (System/currentTimeMillis) - #+cljs (.getTime (js/Date.))) + #?(:clj (System/currentTimeMillis) + :cljs (.getTime (js/Date.)))) (defn- throttle-ch [timeout-ms in out] (go-loop [t0 0] @@ -470,8 +466,8 @@ (let [[_ port] (a/alts! [stop (a/timeout interval)])] (when (not= port stop) (let [val @ref] - #+clj (>! out (box val)) - #+cljs (when-not (undefined? val) (>! out (box val))) + #?(:clj (>! out (box val)) + :cljs (when-not (undefined? val) (>! out (box val)))) (when-not (and (signal? ref) (complete? ref)) (recur)))))) (a/close! out)))