Skip to content

Commit

Permalink
add util function for simplifying states; alpha release
Browse files Browse the repository at this point in the history
  • Loading branch information
tiye committed Mar 22, 2020
1 parent 498b982 commit 05d0056
Show file tree
Hide file tree
Showing 10 changed files with 169 additions and 127 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.12.0"]
[respo "0.12.1-a1"]
```

* Home http://respo-mvc.org
Expand Down
243 changes: 140 additions & 103 deletions calcit.cirru

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion release.edn
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{:version "0.12.0"
{:version "0.12.1-a1"
:group-id "respo"
:artifact-id "respo"
:skip-tag true
Expand Down
2 changes: 1 addition & 1 deletion src/respo/app/comp/container.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@
(let [states (:states store)]
(div
{:style style-global}
(comp-todolist (>> states :todolist) (:tasks store))
(comp-todolist states (:tasks store))
(div {:style style-states} (<> (str "states: " (pr-str (:states store))))))))
2 changes: 1 addition & 1 deletion src/respo/app/comp/todolist.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
(defcomp
comp-todolist
(states tasks)
(let [cursor (:cursor states), state (or (:data states) initial-state)]
(let [cursor (or (:cursor states) []), state (or (:data states) initial-state)]
[(effect-focus)
(div
{:style style-root}
Expand Down
4 changes: 1 addition & 3 deletions src/respo/app/core.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@

(defn dispatch! [op op-data]
(comment println op op-data)
(if (vector? op)
(recur :states [op op-data])
(let [op-id (get-id!), store (updater @*store op op-data op-id)] (reset! *store store))))
(let [store (updater @*store op op-data (get-id!))] (reset! *store store)))

(defn handle-ssr! [mount-target]
(realize-ssr! mount-target (comp-container @*store) dispatch!))
Expand Down
7 changes: 3 additions & 4 deletions src/respo/app/updater.cljs
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@

(ns respo.app.updater (:require [clojure.string :as string]))
(ns respo.app.updater
(:require [clojure.string :as string] [respo.cursor :refer [updater-states]]))

(defn updater [store op-type op-data op-id]
(comment println (pr-str store) (pr-str op-type) (pr-str op-data))
(case op-type
:states
(let [[cursor new-state] op-data]
(assoc-in store (concat [:states] cursor [:data]) new-state))
:states (updater-states store op-data)
:add
(update store :tasks (fn [tasks] (conj tasks {:text op-data, :id op-id, :done? false})))
:remove
Expand Down
8 changes: 6 additions & 2 deletions src/respo/controller/resolve.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,13 @@
(defn build-deliver-event [*global-element dispatch!]
(fn [coord event-name simple-event]
(let [target-element (find-event-target @*global-element coord event-name)
target-listener (get (:event target-element) event-name)]
target-listener (get (:event target-element) event-name)
dispatch-wrap (fn [op data]
(cond
(vector? op) (dispatch! :states [op data])
:else (dispatch! op data)))]
(if (some? target-listener)
(do
(comment println "listener found:" coord event-name)
(target-listener simple-event dispatch!))
(target-listener simple-event dispatch-wrap))
(comment println "found no listener:" coord event-name)))))
5 changes: 5 additions & 0 deletions src/respo/cursor.cljs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

(ns respo.cursor )

(defn updater-states [store [cursor new-state]]
(assoc-in store (concat [:states] cursor [:data]) new-state))
21 changes: 10 additions & 11 deletions src/respo/render/expand.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,23 @@

(declare render-markup)

(defn render-markup [markup coord comp-coord old-element]
(defn render-markup [markup coord old-element]
(cond
(and (component? markup) (component? old-element))
(render-component markup coord old-element)
(and (component? markup) (or (element? old-element) (nil? old-element)))
(render-component markup coord nil)
(and (element? markup) (element? old-element))
(render-element markup coord comp-coord old-element)
(and (element? markup) (element? old-element)) (render-element markup coord old-element)
(and (element? markup) (or (component? old-element) (nil? old-element)))
(render-element markup coord comp-coord nil)
(render-element markup coord nil)
:else
(do
(js/console.log "Markup:" markup)
(throw (js/Error. (str "expects component or element!"))))))

(defn render-element [markup coord comp-coord old-element]
(defn render-element [markup coord old-element]
(let [children (:children markup)
child-elements (render-children children coord comp-coord (:children old-element))]
child-elements (render-children children coord (:children old-element))]
(comment js/console.log "children should have order:" children child-elements markup)
(assoc markup :coord coord :children child-elements)))

Expand All @@ -55,20 +54,20 @@
(merge
markup
{:coord coord,
:tree (render-markup markup-tree new-coord new-coord (:tree old-element)),
:tree (render-markup markup-tree new-coord (:tree old-element)),
:local local})
(sequential? markup-tree)
(let [node-tree (filter-first (fn [x] (or (component? x) (element? x))) markup-tree)
effects-list (->> markup-tree (filter effect?) (vec))]
(merge
markup
{:coord coord,
:tree (render-markup node-tree new-coord new-coord (:tree old-element)),
:tree (render-markup node-tree new-coord (:tree old-element)),
:effects effects-list,
:local local}))
:else (do (js/console.warn "Unknown markup:" markup) nil)))))

(defn render-children [children coord comp-coord old-children]
(defn render-children [children coord old-children]
(comment println "render children:" children)
(let [mapped-cache (into {} old-children)]
(doall
Expand All @@ -82,7 +81,7 @@
(do (println "old child:" coord (some? old-child))))
[k
(if (some? child-element)
(render-markup child-element (conj coord k) comp-coord old-child)
(render-markup child-element (conj coord k) old-child)
nil)])))))))

(defn render-app [markup old-element] (render-markup markup [] [] old-element))
(defn render-app [markup old-element] (render-markup markup [] old-element))

0 comments on commit 05d0056

Please sign in to comment.