Skip to content

Commit

Permalink
add another dev cards test
Browse files Browse the repository at this point in the history
  • Loading branch information
dspiteself committed Dec 11, 2019
1 parent 8268a0e commit 968966a
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 7 deletions.
31 changes: 30 additions & 1 deletion devcards/react_hitch/card/wrapper.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,12 @@
[breeze.quiescent :as q :refer-macros [defcomponent]]
[breeze.quiescent.dom :as d]
[hitch2.curator.mutable-var :refer [mutable-var]]
["react" :as react]
[react-hitch.graph :refer [GraphContext-Provider GraphContext]]
[react-hitch.hooks :refer [useSelected]]
[hitch2.graph :as h]
[hitch2.graph-manager.atom :as g]
[crinkle.component :as c :refer [CE RE]]
[hitch2.descriptor-impl-registry :as reg
:refer [registry-resolver]])
(:require-macros [devcards.core :refer [defcard]]))
Expand Down Expand Up @@ -34,6 +38,28 @@
"clear")
(Hitch-Aware mv-sel services)))


(defn
Hitch-Aware-hook
[{:keys [mv-sel] :as props}]
(let [val (useSelected mv-sel)]
(d/div nil "loaded val: " (pr-str val))))


(defn Loader-hook
[{:keys [mv-sel] :as props}]
(let [graph (react/useContext GraphContext)]
(d/div nil
(d/button {:onClick (fn [e]
(swap! value inc)
(h/apply-commands graph [[mv-sel [:set-value @value]]]))}
"inc")
(d/button {:onClick (fn [e]
(reset! value 0)
(h/apply-commands graph [[mv-sel [:clear]]]))}
"clear")
(CE Hitch-Aware-hook props))))

(defn get-services []
{:graph (g/make-gm registry-resolver)})

Expand All @@ -47,4 +73,7 @@

(defcard app-card
"Example card"
state)
(fn [_ _]
(let [services (get-services)]
(RE GraphContext-Provider #js {:value (:graph services)}
(CE Loader-hook {:mv-sel mv-sel})))))
4 changes: 2 additions & 2 deletions src/react_hitch/curator/react_hook.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@
(recur (assoc sel->rc dtor rcs) tounload toload (rest subs))
(recur (dissoc sel->rc dtor) (conj tounload dtor) toload (rest subs))))
(-> node
(assoc :sel->rc sel->rc)
(update :change-focus into toload)
(assoc-in [:state :sel->rc] sel->rc)
(update :change-focus into (map (fn [x] [x true])) toload)
(update :gcable-sels into
(map (fn [x]
(->timedunload t x)))
Expand Down
4 changes: 2 additions & 2 deletions src/react_hitch/qui_tracker.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

(defn forceUpdate [graph-value c]
(if (instance? hook-dtor c)
((:h c) (:dtor c))
((:h c) (get graph-value (:dtor c) sched/LOADING))
(when (some? (.-__graph c))
(.forceUpdate c)))
nil)
Expand All @@ -34,7 +34,7 @@
unstable_batchedUpdates."
[{:keys [components graph-value] :as rerender-component-effect}]
(let [it (iter components)]
(js/ReactDOM.unstable_batchedUpdates forceUpdate-all it graph-value)))
(js/ReactDOM.unstable_batchedUpdates (fn [] (forceUpdate-all it graph-value)))))

(def react-hitcher-process
{:hitch2.descriptor.impl/kind
Expand Down
3 changes: 1 addition & 2 deletions src/react_hitch/scheduler.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@

(defn run-commands [graph]
(fn []

(set! scheduled? true)
(set! scheduled? false)
(let [subs @hsubs]
(vreset! hsubs {})
(reduce-kv
Expand Down

0 comments on commit 968966a

Please sign in to comment.