diff --git a/README.md b/README.md index de8ad32..554d7c3 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# apintro2 +# apintro FIXME: Write a one-line description of your library/project. diff --git a/project.clj b/project.clj index d9cc1dd..87aae6a 100644 --- a/project.clj +++ b/project.clj @@ -1,14 +1,14 @@ -(defproject apintro2 "0.1.0-SNAPSHOT" +(defproject apintro "0.1.0-SNAPSHOT" :description "FIXME: write this!" :url "http://example.com/FIXME" :license {:name "Eclipse Public License" :url "http://www.eclipse.org/legal/epl-v10.html"} :dependencies [[org.clojure/clojure "1.7.0"] - [org.clojure/clojurescript "0.0-3297"] + [org.clojure/clojurescript "0.0-3308"] [org.clojure/core.async "0.1.346.0-17112a-alpha"] [freactive "0.2.0-SNAPSHOT"] - [bardo "0.1.2-SNAPSHOT"] + [cljs-http "0.1.37"] ] :plugins [[lein-cljsbuild "1.0.5"] @@ -22,17 +22,17 @@ :builds [{:id "dev" :source-paths ["src"] - :figwheel { :on-jsload "apintro2.core/on-js-reload" } + :figwheel { :on-jsload "apintro.core/on-js-reload" } - :compiler {:main apintro2.core + :compiler {:main apintro.core :asset-path "js/compiled/out" - :output-to "resources/public/js/compiled/apintro2.js" + :output-to "resources/public/js/compiled/apintro.js" :output-dir "resources/public/js/compiled/out" :source-map-timestamp true }} {:id "min" :source-paths ["src"] - :compiler {:output-to "resources/public/js/compiled/apintro2.js" - :main apintro2.core + :compiler {:output-to "resources/public/js/compiled/apintro.js" + :main apintro.core :optimizations :advanced :pretty-print false}}]} diff --git a/resources/public/index.html b/resources/public/index.html index ee1111c..bbfc352 100644 --- a/resources/public/index.html +++ b/resources/public/index.html @@ -36,6 +36,6 @@ table {border-collapse: collapse;border-spacing: 0;}
- + diff --git a/src/apintro2/core.cljs b/src/apintro/core.cljs similarity index 79% rename from src/apintro2/core.cljs rename to src/apintro/core.cljs index d0ff551..3ae80c1 100644 --- a/src/apintro2/core.cljs +++ b/src/apintro/core.cljs @@ -1,26 +1,29 @@ -(ns ^:figwheel-always apintro2.core - (:refer-clojure :exclude [atom]) +(ns apintro.core + ; (:refer-clojure :exclude [atom]) (:require [freactive.core :refer [atom cursor]] [freactive.dom :as dom] [freactive.animation :as animation] - [bardo.ease :refer [ease]] + [apintro.model :refer [init! sets gets swaps]] + [apintro.vgapi :as vgapi] ) (:require-macros [freactive.macros :refer [rx]]) ) (enable-console-print!) +;; INIT +(init! {:title "I'm the Title" + :vgapi "xxx" ; (vgapi/initial-state) + }) -;; define your app data so that it doesn't get over-written on reload -(defonce state (atom {:text "Hello world!"})) +; (vgapi/init) (defn on-js-reload [] ;; optionally touch your app-state to force rerendering depending on ;; your application ;; (swap! app-state update-in [:__figwheel_counter] inc) -) + ; (swaps [:figwheel_counter] inc) - -(defonce mouse-pos (atom nil)) + ) (def ease1 (animation/easer 0.0)) (def ease2 (animation/easer 1.0)) @@ -56,8 +59,11 @@ :color "rgba(255,255,255,0.9)" } :node/on-attached (fn [x] (complex-transition)) + ; :on-click (fn [x] (sets [:title] "Clicked!")) } - "Title"] + (gets [:title]) + ; "Title" + ] [anchor 0 "#subtitle" "Go to Sub Title ยป"]] [:div#subtitle {:style {:height "100vh" :background green @@ -81,10 +87,10 @@ {:width "100%" :height "100%" :style {:border "1px solid black"} - :on-mousemove (fn [e] (swap! state assoc-in [:mouse-pos] [(.-clientX e) (.-clientY e)])) + :on-mousemove (fn [e] (sets [:mouse-pos] [(.-clientX e) (.-clientY e)])) } - [:h1 (:text @state)] - [:p "Your mouse is at: " (rx (str (:mouse-pos @state)))] + [:h1 (gets [:text])] + [:p "Your mouse is at: " (rx (str (gets [:mouse-pos])))] ]) (dom/mount! (.getElementById js/document "root") (ease-view)) diff --git a/src/apintro/model.cljs b/src/apintro/model.cljs new file mode 100644 index 0000000..d946587 --- /dev/null +++ b/src/apintro/model.cljs @@ -0,0 +1,19 @@ +(ns ^:figwheel-always apintro.model + (:refer-clojure :exclude [atom]) + (:require [freactive.core :refer [atom]])) + +(defonce state (atom {})) + +(defn init! [v] + (reset! state v)) + +(defn sets [path value] + (swap! state assoc-in path value)) + +(defn gets [path] + (get-in @state path)) + +(defn swaps [path f] + (sets path (f (gets path)))) + + diff --git a/src/apintro/vgapi.cljs b/src/apintro/vgapi.cljs new file mode 100644 index 0000000..5cdf4c0 --- /dev/null +++ b/src/apintro/vgapi.cljs @@ -0,0 +1,96 @@ +(ns ^:figwheel-always apintro.vgapi + (:require-macros [cljs.core.async.macros :refer [go]] + [freactive.macros :refer [rx]]) + (:require + [apintro.model :refer [gets sets]] + [cljs-http.client :as http] + [cljs.core.async :refer [ Action -> State" + [state action] + (condp = action + :tick (into + state + {:color (mod (+ (:color state) 0.7) 255) + :angle + (+ (:angle state) (* 0.00005 (* (:volume state) (:volume state))))}) + state)) + + +;; ------------------------------------------------------------------------------ +;; View +;; ------------------------------------------------------------------------------ +(defn view-tweets [state] + [:div "tweets"]) + +(defn view-volume [state] + [:div "volume"]) + +(defn view [state] + [:div + [view-volume] + [view-tweets]])