another working version
This commit is contained in:
parent
3b0c4c2e50
commit
d1f110f706
6 changed files with 143 additions and 22 deletions
|
@ -1,4 +1,4 @@
|
|||
# apintro2
|
||||
# apintro
|
||||
|
||||
FIXME: Write a one-line description of your library/project.
|
||||
|
||||
|
|
16
project.clj
16
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}}]}
|
||||
|
||||
|
|
|
@ -36,6 +36,6 @@ table {border-collapse: collapse;border-spacing: 0;}
|
|||
</head>
|
||||
<body>
|
||||
<div id="root"></div>
|
||||
<script src="js/compiled/apintro2.js" type="text/javascript"></script>
|
||||
<script src="js/compiled/apintro.js" type="text/javascript"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
@ -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))
|
19
src/apintro/model.cljs
Normal file
19
src/apintro/model.cljs
Normal file
|
@ -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))))
|
||||
|
||||
|
96
src/apintro/vgapi.cljs
Normal file
96
src/apintro/vgapi.cljs
Normal file
|
@ -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 [<!]]))
|
||||
|
||||
;; ------------------------------------------------------------------------------
|
||||
;; MODEL
|
||||
;; ------------------------------------------------------------------------------
|
||||
(def initial-state
|
||||
{:color 0
|
||||
:angle 0
|
||||
:volume 1
|
||||
;; :project-id "vgteam-star_wars"
|
||||
:project-id "vigiglobe-Microsoft"
|
||||
:msg "Nothing done yet."})
|
||||
|
||||
;; ------------------------------------------------------------------------------
|
||||
;; Tasks
|
||||
;; ------------------------------------------------------------------------------
|
||||
(defn smart-si [f n]
|
||||
(f)
|
||||
(js/setInterval f n))
|
||||
|
||||
(defn get-datas-every [route params interval action]
|
||||
(smart-si
|
||||
(fn []
|
||||
(go (let [now (.getTime (new js/Date))
|
||||
from (.toISOString (new js/Date (- now (+ interval (* 60 1000)))))
|
||||
to (.toISOString (new js/Date (- now (* 60 1000))))
|
||||
response (<! (http/get (str "http://dev.api.vigiglo.be/api" route)
|
||||
{:query-params (into {:project_id (gets :project-id)
|
||||
:timeFrom from
|
||||
:timeTo to}
|
||||
params)}))]
|
||||
(when (= 200 (:status response))
|
||||
(action
|
||||
(get-in response [:body :data]))))))
|
||||
interval))
|
||||
|
||||
(defn get-volume []
|
||||
(get-datas-every
|
||||
"/statistics/v1/volume" {} 1000
|
||||
(fn [res]
|
||||
(let [new-size (second (first (:messages res)))]
|
||||
(sets [:msg] (str new-size))
|
||||
(sets [:volume] new-size)))))
|
||||
|
||||
(defn get-messages []
|
||||
(let [interval 1000]
|
||||
(get-datas-every
|
||||
"/content/v1/messages" {:limit (* 20 (/ interval 100))} interval
|
||||
(fn [res]
|
||||
(let [now (.getTime (new js/Date))]
|
||||
(sets [:msg-time] now)
|
||||
(sets [:msg-refresh] (+ interval now))
|
||||
(sets [:messages] res))))))
|
||||
|
||||
;; ------------------------------------------------------------------------------
|
||||
;; Init
|
||||
;; ------------------------------------------------------------------------------
|
||||
(defn init []
|
||||
(get-volume)
|
||||
(get-messages)
|
||||
{})
|
||||
|
||||
;; ------------------------------------------------------------------------------
|
||||
;; Update
|
||||
;; ------------------------------------------------------------------------------
|
||||
(defn update-state
|
||||
"update-state :: State -> 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]])
|
Loading…
Reference in a new issue