diff --git a/devcards/react_hitch/card/wrapper.cljs b/devcards/react_hitch/card/wrapper.cljs index 4ee7c1a..13a44e1 100644 --- a/devcards/react_hitch/card/wrapper.cljs +++ b/devcards/react_hitch/card/wrapper.cljs @@ -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]])) @@ -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)}) @@ -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}))))) diff --git a/src/react_hitch/curator/react_hook.cljs b/src/react_hitch/curator/react_hook.cljs index c751d56..00dacbd 100644 --- a/src/react_hitch/curator/react_hook.cljs +++ b/src/react_hitch/curator/react_hook.cljs @@ -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))) diff --git a/src/react_hitch/qui_tracker.cljs b/src/react_hitch/qui_tracker.cljs index 8eef0c8..419a4e2 100644 --- a/src/react_hitch/qui_tracker.cljs +++ b/src/react_hitch/qui_tracker.cljs @@ -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) @@ -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 diff --git a/src/react_hitch/scheduler.cljs b/src/react_hitch/scheduler.cljs index eb987dc..d44fb86 100644 --- a/src/react_hitch/scheduler.cljs +++ b/src/react_hitch/scheduler.cljs @@ -42,8 +42,7 @@ (defn run-commands [graph] (fn [] - - (set! scheduled? true) + (set! scheduled? false) (let [subs @hsubs] (vreset! hsubs {}) (reduce-kv