Skip to content

Commit

Permalink
update hitch
Browse files Browse the repository at this point in the history
  • Loading branch information
dspiteself committed Jan 22, 2020
1 parent c1c4e4c commit 8dd2bda
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 39 deletions.
4 changes: 2 additions & 2 deletions project.clj
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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"
Expand Down
73 changes: 38 additions & 35 deletions src/react_hitch/curator/react_hook.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
5 changes: 3 additions & 2 deletions test/react_hitch/common_test.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 8dd2bda

Please sign in to comment.