Skip to content

Commit

Permalink
add macros: action-> mutation-> ; bumo 0.8.6
Browse files Browse the repository at this point in the history
  • Loading branch information
tiye committed Jan 10, 2018
1 parent 3eaf951 commit c1ec2d5
Show file tree
Hide file tree
Showing 9 changed files with 131 additions and 290 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Respo: A virtual DOM library in ClojureScript
[![Respo](https://img.shields.io/clojars/v/respo/respo.svg)](https://clojars.org/respo/respo)

```clojure
[respo "0.8.5"]
[respo "0.8.6"]
```

* Home http://respo.site
Expand Down
2 changes: 1 addition & 1 deletion build.boot
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
:username "jiyinyiyong"
:password (read-password "Clojars password: ")}]))

(def +version+ "0.8.5")
(def +version+ "0.8.6")

(deftask deploy []
(comp
Expand Down
330 changes: 87 additions & 243 deletions coir.edn

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "respo",
"version": "0.1.0",
"description": "FIXME: description",
"description": "Virtual DOM library",
"main": "index.js",
"scripts": {
"tiye": "rsync -r dist/ repo.respo.site:repo/Respo/respo",
Expand Down Expand Up @@ -30,7 +30,7 @@
"dependencies": {},
"devDependencies": {
"http-server": "^0.10.0",
"shadow-cljs": "^2.0.125",
"shadow-cljs": "^2.0.129",
"source-map-support": "^0.5.0",
"ws": "^3.3.3"
}
Expand Down
8 changes: 8 additions & 0 deletions polyfill/respo/macros.clj
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,11 @@
([tag props children]
(assert (keyword? tag) "tag in list-> should be keyword")
`(respo.core/create-list-element ~tag ~props ~children)))

(defmacro action-> [op op-data]
`(fn [~'%e d!# m!#]
(d!# ~op ~op-data)))

(defmacro mutation-> [state]
`(fn [~'%e d!# m!#]
(m!# ~state)))
2 changes: 1 addition & 1 deletion shadow-cljs.edn
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
:devtools {:after-load respo.main/reload!
:preloads [shadow.cljs.devtools.client.hud]
:http-root "target"
:http-port 8080}
:http-port 7000}
:release {:output-dir "dist/"}}
:test {:target :node-script
:output-to "target/test.js"
Expand Down
14 changes: 4 additions & 10 deletions src/respo/app/comp/task.cljs
Original file line number Diff line number Diff line change
@@ -1,22 +1,16 @@

(ns respo.app.comp.task
(:require [respo.macros :refer [defcomp div input span button <>]]
(:require [respo.macros :refer [defcomp div input span button <> action-> mutation->]]
[hsl.core :refer [hsl]]
[respo.comp.space :refer [=<]]
[respo.comp.inspect :refer [comp-inspect]]
[respo.app.style.widget :as widget]))

(defn handle-done [task-id] (fn [e dispatch!] (dispatch! :toggle task-id)))

(defn handle-remove [task] (fn [e dispatch!] (dispatch! :remove (:id task))))

(defn on-text-change [task]
(fn [event dispatch!]
(let [task-id (:id task), text (:value event)]
(dispatch! :update {:id task-id, :text text}))))

(defn on-text-state [e dispatch! mutate!] (mutate! (:value e)))

(def style-done
{:width 32, :height 32, :outline :none, :border :none, :vertical-align :middle})

Expand All @@ -33,13 +27,13 @@
{:style (merge
style-done
{:background-color (if (:done? task) (hsl 200 20 80) (hsl 200 80 70))}),
:on-click (handle-done (:id task))})
:on-click (action-> :toggle (:id task))})
(=< 8 nil)
(input {:value (:text task), :style widget/input, :on-input (on-text-change task)})
(=< 8 nil)
(input {:value state, :style widget/input, :on-input on-text-state})
(input {:value state, :style widget/input, :on-input (mutation-> (:value %e))})
(=< 8 nil)
(div {:style widget/button, :on-click (handle-remove task)} (<> "Remove"))
(div {:style widget/button, :on-click (action-> :remove (:id task))} (<> "Remove"))
(=< 8 nil)
(div {} (<> state)))))

Expand Down
53 changes: 24 additions & 29 deletions src/respo/app/comp/todolist.cljs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@

(ns respo.app.comp.todolist
(:require [clojure.string :as string]
[respo.macros :refer [defcomp div span input <> cursor-> list->]]
[respo.macros
:refer
[defcomp div span input <> cursor-> list-> action-> mutation->]]
[hsl.core :refer [hsl]]
[respo.app.comp.task :refer [comp-task]]
[respo.comp.space :refer [=<]]
Expand All @@ -11,29 +13,12 @@
[respo.util.dom :refer [text-width]]
[respo.app.style.widget :as widget]))

(defn clear-done [e dispatch!] (println "dispatch clear-done") (dispatch! :clear nil))

(defn handle-add [state]
(fn [e dispatch! mutate!] (dispatch! :add (:draft state)) (mutate! (assoc state :draft ""))))

(def style-root
{:color :black,
:background-color (hsl 120 20 98),
:line-height "24px",
:font-size 16,
:padding 10,
:font-family "\"微软雅黑\", Verdana"})

(def style-list {:color :black, :background-color (hsl 120 20 98)})

(def style-toolbar
{:display :flex,
:flex-direction :row,
:justify-content :start,
:padding "4px 0",
:white-space :nowrap})
(def initial-state {:draft "", :locked? false})

(def style-panel {:display :flex, :margin-bottom 4})
(defn on-focus [e dispatch!] (println "Just focused~"))

(defn run-test! [dispatch! acc]
(let [started (.valueOf (js/Date.))]
Expand All @@ -49,14 +34,24 @@

(defn on-test [e dispatch!] (println "trigger test!") (run-test! dispatch! []))

(defn on-focus [e dispatch!] (println "Just focused~"))
(def style-list {:color :black, :background-color (hsl 120 20 98)})

(def initial-state {:draft "", :locked? false})
(def style-panel {:display :flex, :margin-bottom 4})

(defn on-text-change [state]
(fn [e dispatch! mutate!] (mutate! (assoc state :draft (:value e)))))
(def style-root
{:color :black,
:background-color (hsl 120 20 98),
:line-height "24px",
:font-size 16,
:padding 10,
:font-family "\"微软雅黑\", Verdana"})

(defn on-lock [state] (fn [e dispatch! mutate!] (mutate! (update state :locked? not))))
(def style-toolbar
{:display :flex,
:flex-direction :row,
:justify-content :start,
:padding "4px 0",
:white-space :nowrap})

(defcomp
comp-todolist
Expand All @@ -73,12 +68,12 @@
:style (merge
widget/input
{:width (max 200 (+ 24 (text-width (:draft state) 16 "BlinkMacSystemFont")))}),
:on-input (on-text-change state),
:on-input (mutation-> (assoc state :draft (:value %e))),
:on-focus on-focus})
(=< 8 nil)
(span {:style widget/button, :on-click (handle-add state)} (<> "Add"))
(=< 8 nil)
(span {:inner-text "Clear", :style widget/button, :on-click clear-done})
(span {:inner-text "Clear", :style widget/button, :on-click (action-> :clear nil)})
(=< 8 nil)
(div {} (div {:style widget/button, :on-click on-test} (<> "heavy tasks"))))
(list->
Expand All @@ -92,11 +87,11 @@
(div
{:spell-check true, :style style-toolbar}
(div
{:style widget/button, :on (if (:locked? state) {} {:click clear-done})}
{:style widget/button, :on (if (:locked? state) {} {:click (action-> :clear nil)})}
(<> "Clear2"))
(=< 8 nil)
(div
{:style widget/button, :on-click (on-lock state)}
{:style widget/button, :on-click (mutation-> (update state :locked? not))}
(<> (str "Lock?" (:locked? state))))
(=< 8 nil)
(comp-wrap (comp-zero))))
Expand Down
6 changes: 3 additions & 3 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1194,9 +1194,9 @@ [email protected]:
version "1.1.1"
resolved "https://registry.yarnpkg.com/shadow-cljs-jar/-/shadow-cljs-jar-1.1.1.tgz#5d74383f5aff8fba25a5d00ee3c3ad035a1bd7a3"

shadow-cljs@^2.0.125:
version "2.0.125"
resolved "https://registry.yarnpkg.com/shadow-cljs/-/shadow-cljs-2.0.125.tgz#99bf6cc783fb06035fd9a67748351f6b34d88db3"
shadow-cljs@^2.0.129:
version "2.0.129"
resolved "https://registry.yarnpkg.com/shadow-cljs/-/shadow-cljs-2.0.129.tgz#aa3781f955be4a29fc08d8d2a53d87a71246afc6"
dependencies:
babel-core "^6.26.0"
babel-preset-env "^1.6.0"
Expand Down

0 comments on commit c1ec2d5

Please sign in to comment.