Clojure, Web и золото – Старатели против карьеров



Clojure, Web и золото – Старатели против карьеров

0 0


sprug-2015-01-slides

SPRUG talk on the state of Clojure Web (in Russian)

On Github si14 / sprug-2015-01-slides

Clojure, Web и золото

Старатели против карьеров

Дмитрий Грошев (@lambdadmitry)

Clojure

Старые шахты

(defroutes user-routes
  (context "/user/:id{[0-9]+}" []
    (GET "/" [] ...)
    (GET "/profile" [] ...)
    (GET "/posts" [] ...)))

Золото!

hiccup

(defn foobar [...]
  [:div.top.container
   [:a {:href "/"}
       [:img {:src "/img/logo_small.png"
              :border "0"}]]
   [:div.links
    (if is-authorized?
      [:a {:href "/logout"} "Выйти"]
      [:a {:href "/login"} "Войти в аккаунт"])]
   [:div.clear]])

Graph

(def stats-graph
  {:n  (fnk [xs]   (count xs))
   :m  (fnk [xs n] (/ (sum identity xs) n))
   :m2 (fnk [xs n] (/ (sum #(* % %) xs) n))
   :v  (fnk [m m2] (- m2 (* m m)))})

Graph

fnhouse

(defnk $entries$:entry-id$GET
  "Get the entry at the given id"
  {:responses {200 schemas/ClientEntry}}
  [[:request [:uri-args entry-id :- Long]]
   [:resources guestbook]]
  {:body (safe-get @guestbook entry-id)})

NB: data > fn > macro

fnhouse

  (p/defnk post
    "Adds new foobar"
    {:responses  {201 s/Any
                  422 {:message s/Str}}
     :path       "/"
     :method     :post
     :auth-scope :auth-scopes/foobar-add}
    [[:request datomic-val oauth-token
      body :- (msext/fresh msext/Foobar)]
     [:resources datomic]]
    (let [foobar (adapter body)
          uuid (:foobar/uuid foobar)
          entity-url (mh/handler-var->url #'get-entity {:uuid uuid})]
      (case (md/assert-entity datomic foobar oauth-token)
        ...
        :not-an-entity
        {:status 422 :body {:message "reference consistency violation"}})))

React + персистентность + hiccup

(defn team [active? arrow-class score-class score]
  (let [offset (str (- (* 93 (/ score (:max-score config))) 93) "%")
        translation (str "translate3d(" offset ",0,0)")]
    [:div.team {:class (when-not active? "inactive")}
     [:div.arrow {:class arrow-class}
     [:span.icon-arrow-right]]
    [:div.score {:class score-class
                 :style {:-webkit-transform translation
                         :transform translation}}
     [:span.label score]]]))

Завтра?

for-GET

NB: controlflow DAG vs data DAG

Remote storage

NB: CAP, агенты, криптография

TODO: копать много и глубоко

Вопросы?

Слайды: si14.github.io/sprug-2015-01-slides

Твиттер: @lambdadmitry

Почта: lambdadmitry@gmail.com