Skip to content

Commit

Permalink
Breaking: refactor states
Browse files Browse the repository at this point in the history
  • Loading branch information
tiye committed Mar 20, 2020
1 parent c50a06b commit cfef36d
Show file tree
Hide file tree
Showing 22 changed files with 839 additions and 894 deletions.
47 changes: 47 additions & 0 deletions .github/workflows/deploy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@

name: Deploy package

on:
release:
types: [created]

jobs:
deploy:
name: Deploy

runs-on: ubuntu-latest

steps:
- run: curl -O https://download.clojure.org/install/linux-install-1.10.1.507.sh && chmod +x linux-install-1.10.1.507.sh && sudo ./linux-install-1.10.1.507.sh

- uses: actions/checkout@v2

- name: Get yarn cache
id: yarn-cache
run: echo "::set-output name=dir::$(yarn cache dir)"

- uses: actions/cache@v1
name: Cache node modules of yarn
with:
path: ${{ steps.yarn-cache.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
- name: Cache Clojars
uses: actions/cache@v1
env:
cache-name: cache-clojars
with:
path: ~/.m2/repository
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('shadow-cljs.edn') }}
restore-keys: |
${{ runner.os }}-clojars
- name: run tests
run: 'yarn && yarn shadow-cljs compile client'

- run: echo Working on ${{ github.ref }}

- name: deploy to clojars
run: env CLOJARS_USERNAME=jiyinyiyong CLOJARS_PASSWORD=${{ secrets.CLOJARS_PASSWORD }} clojure -A:release
55 changes: 55 additions & 0 deletions .github/workflows/upload.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@

name: Upload Assets

on:
pull_request: {}
push:
branches:
- master

jobs:
upload-assets:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: docker://timbru31/java-node:latest

- name: Get yarn cache
id: yarn-cache
run: echo "::set-output name=dir::$(yarn cache dir)"

- uses: actions/cache@v1
name: Cache node modules of yarn
with:
path: ${{ steps.yarn-cache.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
- name: Cache Clojars
uses: actions/cache@v1
env:
cache-name: cache-clojars
with:
path: ~/.m2/repository
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('shadow-cljs.edn') }}
restore-keys: |
${{ runner.os }}-clojars
- run: yarn && yarn build
name: Build web assets

- name: Deploy to server
id: deploy
uses: Pendect/[email protected]
env:
DEPLOY_KEY: ${{secrets.rsync_private_key}}
with:
flags: '-avzr --progress'
options: ''
ssh_options: ''
src: 'dist/*'
dest: '[email protected]:/web-assets/repo/${{ github.repository }}'

- name: Display status from deploy
run: echo "${{ steps.deploy.outputs.status }}"
4 changes: 2 additions & 2 deletions 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.11.5"]
[respo "0.12.0-a1"]
```

* Home http://respo-mvc.org
Expand All @@ -21,7 +21,7 @@ DOM syntax
```clojure
(div {:class-name "demo-container"
:style {:color :red}
:on-click (fn [event dispatch! mutate!])}
:on-click (fn [event dispatch!])}
(div {}))
```

Expand Down
908 changes: 400 additions & 508 deletions calcit.cirru

Large diffs are not rendered by default.

12 changes: 11 additions & 1 deletion deps.edn
Original file line number Diff line number Diff line change
@@ -1,2 +1,12 @@

{:paths ["src" "macros"]}
{
:paths ["src" "macros"]
:aliases {
:release {
:extra-deps {
appliedscience/deps-library {:mvn/version "0.3.4"}
}
:main-opts ["-m" "deps-library.release"]
}
}
}
14 changes: 1 addition & 13 deletions macros/respo/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@
(merge respo.schema/component
{:args (list ~@params) ,
:name ~(keyword comp-name),
:render (fn [~@params]
(defn ~(symbol (str "call-" comp-name)) [~'%cursor] ~@body))})))
:render (fn [~@params] ~@body)})))

(def support-elements '[a body br button canvas code div footer
h1 h2 head header html hr i img input li link video audio
Expand Down Expand Up @@ -40,24 +39,13 @@
([content style] `(span {:inner-text ~content, :style ~style}))
([el content style] `(~el {:inner-text ~content, :style ~style})))

(defmacro cursor-> [k component states & args]
`(assoc (~component (get ~states ~k) ~@args) :cursor (conj ~'%cursor ~k)))

(defmacro list->
([props children]
`(respo.core/create-list-element :div ~props ~children))
([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)))

(defmacro defeffect [effect-name args params & body]
(assert (and (sequential? args) (every? symbol? args)) "args should be simple sequence")
(assert (and (sequential? params) (every? symbol? params)) "params supported to be [action el *local]")
Expand Down
9 changes: 0 additions & 9 deletions meyvn.edn

This file was deleted.

8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
"description": "Virtual DOM library",
"main": "index.js",
"scripts": {
"deploy": "clj -A:release",
"m2": "clj -A:release install",
"upload": "rsync -r dist/ repo.respo-mvc.org:repo/Respo/respo",
"html": "cp assets/* target/",
"html-dist": "cp assets/* dist/",
Expand All @@ -28,9 +30,9 @@
"homepage": "https://github.com/Respo/respo#readme",
"dependencies": {},
"devDependencies": {
"http-server": "^0.11.1",
"shadow-cljs": "^2.8.69",
"http-server": "^0.12.1",
"shadow-cljs": "^2.8.93",
"source-map-support": "^0.5.16",
"ws": "^7.2.0"
"ws": "^7.2.3"
}
}
6 changes: 6 additions & 0 deletions release.edn
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{:version "0.12.0-a1"
:group-id "respo"
:artifact-id "respo"
:skip-tag true
:description "Respo: A virtual DOM library in ClojureScript."
:scm-url "https://github.com/Respo/respo"}
3 changes: 1 addition & 2 deletions scripts/comp.clj
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
`(merge respo.schema/component
{:args (list ~@~params) ,
:name ~(keyword comp-name),
:render (fn [~@~params]
(defn ~~(symbol (str "call-" comp-name)) [~~'%cursor] ~@~body))})))
:render (fn [~@~params] ~@~body)})))

(defcomp comp-a [a] (div {}))

Expand Down
6 changes: 3 additions & 3 deletions src/respo/app/comp/container.cljs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

(ns respo.app.comp.container
(:require [respo.core :refer [defcomp div span <> cursor->]]
(:require [respo.core :refer [defcomp div span <> >>]]
[respo.app.comp.todolist :refer [comp-todolist]]))

(def style-global {:font-family "Avenir,Verdana"})
Expand All @@ -10,8 +10,8 @@
(defcomp
comp-container
(store)
(let [state (:states store)]
(let [states (:states store)]
(div
{:style style-global}
(cursor-> :todolist comp-todolist state (:tasks store))
(comp-todolist (>> states :todolist) (:tasks store))
(div {:style style-states} (<> (str "states: " (pr-str (:states store))))))))
35 changes: 18 additions & 17 deletions src/respo/app/comp/task.cljs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@

(ns respo.app.comp.task
(:require [respo.core
:refer
[defcomp div input span button <> action-> mutation-> defeffect]]
(:require [respo.core :refer [defcomp div input span button <> defeffect]]
[hsl.core :refer [hsl]]
[respo.comp.space :refer [=<]]
[respo.comp.inspect :refer [comp-inspect]]
Expand All @@ -12,18 +10,14 @@
effect-log
(task)
(action parent *local at-place?)
(js/console.log "Task effect" action at-place?)
(comment js/console.log "Task effect" action at-place?)
(case action
:mount (let [x0 (js/Math.random)] (swap! *local assoc :data x0) (println "Stored" x0))
:update (println "read" (get @*local :data))
:unmount (println "read" (get @*local :data))
:mount
(let [x0 (js/Math.random)] (swap! *local assoc :data x0) (comment println "Stored" x0))
:update (comment println "read" (get @*local :data))
:unmount (comment println "read" (get @*local :data))
(do)))

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

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

Expand All @@ -32,7 +26,7 @@
(defcomp
comp-task
(states task)
(let [state (or (:data states) "")]
(let [cursor (:cursor states), state (or (:data states) "")]
[(effect-log task)
(div
{:style style-task}
Expand All @@ -41,13 +35,20 @@
{:style (merge
style-done
{"background-color" (if (:done? task) (hsl 200 20 80) (hsl 200 80 70))}),
:on-click (action-> :toggle (:id task))})
:on-click (fn [e d!] (d! :toggle (:id task)))})
(=< 8 nil)
(input {:value (:text task), :style widget/input, :on-input (on-text-change task)})
(input
{:value (:text task),
:style widget/input,
:on-input (fn [e d!]
(let [task-id (:id task), text (:value e)] (d! :update {:id task-id, :text text})))})
(=< 8 nil)
(input {:value state, :style widget/input, :on-input (mutation-> (:value %e))})
(input
{:value state, :style widget/input, :on-input (fn [e d!] (d! cursor (:value e)))})
(=< 8 nil)
(div {:style widget/button, :on-click (action-> :remove (:id task))} (<> "Remove"))
(div
{:style widget/button, :on-click (fn [e d!] (d! :remove (:id task)))}
(<> "Remove"))
(=< 8 nil)
(div {} (<> state)))]))

Expand Down
34 changes: 11 additions & 23 deletions src/respo/app/comp/todolist.cljs
Original file line number Diff line number Diff line change
@@ -1,19 +1,7 @@

(ns respo.app.comp.todolist
(:require [clojure.string :as string]
[respo.core
:refer
[defcomp
div
span
input
textarea
<>
cursor->
list->
action->
mutation->
defeffect]]
[respo.core :refer [defcomp div span input textarea <> list-> defeffect >>]]
[hsl.core :refer [hsl]]
[respo.app.comp.task :refer [comp-task]]
[respo.comp.space :refer [=<]]
Expand All @@ -29,9 +17,6 @@
[action parent *local]
(js/console.log "todolist effect:" action))

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

(def initial-state {:draft "", :locked? false})

(defn on-focus [e dispatch!] (println "Just focused~"))
Expand Down Expand Up @@ -72,7 +57,7 @@
(defcomp
comp-todolist
(states tasks)
(let [state (or (:data states) initial-state)]
(let [cursor (:cursor states), state (or (:data states) initial-state)]
[(effect-focus)
(div
{:style style-root}
Expand All @@ -85,14 +70,16 @@
:style (merge
widget/input
{:width (max 200 (+ 24 (text-width (:draft state) 16 "BlinkMacSystemFont")))}),
:on-input (mutation-> (assoc state :draft (:value %e))),
:on-input (fn [e d!] (d! cursor (assoc state :draft (:value e)))),
:on-focus on-focus})
(=< 8 nil)
(span
{:style widget/button, :on-click (handle-add state)}
{:style widget/button,
:on-click (fn [e d!] (d! :add (:draft state)) (d! cursor (assoc state :draft "")))}
(span {:on-click nil, :inner-text "Add"}))
(=< 8 nil)
(span {:inner-text "Clear", :style widget/button, :on-click (action-> :clear nil)})
(span
{:inner-text "Clear", :style widget/button, :on-click (fn [e d!] (d! :clear nil))})
(=< 8 nil)
(div {} (div {:style widget/button, :on-click on-test} (<> "heavy tasks"))))
(list->
Expand All @@ -101,16 +88,17 @@
(reverse)
(map
(fn [task]
(let [task-id (:id task)] [task-id (cursor-> task-id comp-task states task)])))))
(let [task-id (:id task)] [task-id (comp-task (>> states task-id) task)])))))
(if (> (count tasks) 0)
(div
{:spell-check true, :style style-toolbar}
(div
{:style widget/button, :on (if (:locked? state) {} {:click (action-> :clear nil)})}
{:style widget/button, :on-click (if (:locked? state) (fn [e d!] (d! :clear nil)))}
(<> "Clear2"))
(=< 8 nil)
(div
{:style widget/button, :on-click (mutation-> (update state :locked? not))}
{:style widget/button,
:on-click (fn [e d!] (d! cursor (update state :locked? not)))}
(<> (str "Lock?" (:locked? state))))
(=< 8 nil)
(comp-wrap (comp-zero))))
Expand Down
Loading

0 comments on commit cfef36d

Please sign in to comment.