From 8dd2bda51746fe96fb530f884a65a70244a8f593 Mon Sep 17 00:00:00 2001 From: Tyler Tallman Date: Wed, 22 Jan 2020 15:11:46 -0600 Subject: [PATCH] update hitch --- project.clj | 4 +- src/react_hitch/curator/react_hook.cljs | 73 +++++++++++++------------ test/react_hitch/common_test.cljs | 5 +- 3 files changed, 43 insertions(+), 39 deletions(-) diff --git a/project.clj b/project.clj index 1f4ebb9..78ba2c2 100644 --- a/project.clj +++ b/project.clj @@ -1,4 +1,4 @@ -(defproject com.breezeehr/react-hitch "0.4.2" +(defproject com.breezeehr/react-hitch "0.5.0-SNAPSHOT" :description "A Clojurescript library designed to manage and cache derived data." :url "https://github.com/Breezeemr/react-hitch" :license {:name "Eclipse Public License" @@ -10,7 +10,7 @@ ;[org.clojure/clojurescript "1.10.520" :scope "provided"] ;[com.google.javascript/closure-compiler-unshaded "v20190325"] ;[org.clojure/google-closure-library "0.0-20190213-2033d5d9"] - [com.breezeehr/hitch2 "0.3.5" :exclusions [org.clojure/clojurescript ]] + [com.breezeehr/hitch2 "0.4.0-SNAPSHOT" :exclusions [org.clojure/clojurescript ]] [crinkle "2.0.0" :exclusions [org.clojure/clojurescript ]] [thheller/shadow-cljs "2.8.74"] [com.breezeehr/quiescent "0.3.0" diff --git a/src/react_hitch/curator/react_hook.cljs b/src/react_hitch/curator/react_hook.cljs index 75aea90..7c364c0 100644 --- a/src/react_hitch/curator/react_hook.cljs +++ b/src/react_hitch/curator/react_hook.cljs @@ -146,44 +146,47 @@ (fn [curator-descriptor] initial-node) ::curator/apply-command - (fn [curator-descriptor graph-value node command] - (case (nth command 0) - :reset-component-parents - (let [[_ rc new-parents] command] - (reset-component-parents node rc new-parents)) - :hook-subs - (let [[_ sub-changes] command] - (handle-hook-subs node sub-changes)) - :gc - (-> node - do-gc - (assoc-in [:state :gc-scheduled?] false)))) + (fn [curator-descriptor] + (fn [graph-value node command] + (case (nth command 0) + :reset-component-parents + (let [[_ rc new-parents] command] + (reset-component-parents node rc new-parents)) + :hook-subs + (let [[_ sub-changes] command] + (handle-hook-subs node sub-changes)) + :gc + (-> node + do-gc + (assoc-in [:state :gc-scheduled?] false))))) ::curator/observed-value-changes - (fn [curator-descriptor graph-value node parent-descriptors] - (update-in node [:state :dirty-sels] into parent-descriptors)) + (fn [curator-descriptor] + (fn [graph-value node parent-descriptors] + (update-in node [:state :dirty-sels] into parent-descriptors))) ::curator/finalize - (fn [_ graph-value node] - (let [{:keys [dirty-sels - gc-scheduled? - gcable-sels]} - (-> node :state)] - (cond-> (assoc-in node [:state :dirty-sels] #{}) - (pos? (count dirty-sels)) - (update :outbox conj - [react-hitcher-process - {:type :rerender-components - :components (into [] - (mapcat (prep-rerender (-> node :state :sel->rc))) - dirty-sels)}]) - (and (not gc-scheduled?) - (not-empty gcable-sels)) - (-> - (update :outbox conj - [react-hitcher-process - {:type :schedule-gc - :when (-> gcable-sels peek :time)}]) - (assoc-in [:state :gc-scheduled?] true)))))}) + (fn [_] + (fn [graph-value node] + (let [{:keys [dirty-sels + gc-scheduled? + gcable-sels]} + (-> node :state)] + (cond-> (assoc-in node [:state :dirty-sels] #{}) + (pos? (count dirty-sels)) + (update :outbox conj + [react-hitcher-process + {:type :rerender-components + :components (into [] + (mapcat (prep-rerender (-> node :state :sel->rc))) + dirty-sels)}]) + (and (not gc-scheduled?) + (not-empty gcable-sels)) + (-> + (update :outbox conj + [react-hitcher-process + {:type :schedule-gc + :when (-> gcable-sels peek :time)}]) + (assoc-in [:state :gc-scheduled?] true))))))}) (reg/def-registered-descriptor Rreact-hook react-hook-spec react-hook-impl) diff --git a/test/react_hitch/common_test.cljs b/test/react_hitch/common_test.cljs index d608ad4..a2f95a4 100644 --- a/test/react_hitch/common_test.cljs +++ b/test/react_hitch/common_test.cljs @@ -5,8 +5,9 @@ [hitch2.descriptor-impl-registry :as reg] [hitch2.protocols.graph-manager :as g])) -(defn return-constant [gv-tracker v] - v) +(defn return-constant [ v] + (fn [gv-tracker] + v)) (def-descriptor-spec constant-spec :not-curator