Skip to content

Commit

Permalink
expose state
Browse files Browse the repository at this point in the history
  • Loading branch information
darkleaf committed Feb 19, 2020
1 parent 38cecf5 commit 9e111a1
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions src/darkleaf/multidecorators.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,16 @@
(distinct acc))))

(defn multi [dispatch initial]
(let [registry (atom {})]
(let [iregistry (atom {})]
(fn
([] registry)
([] {:type :dynamic
:iregistry iregistry
:dispatch dispatch
:initial initial})
([obj & args]
(let [tag (apply dispatch obj args)
tags (reversed-me-and-ancestors tag)
reg @registry
reg @iregistry
f (reduce (fn [acc tag]
(if-some [decorator (reg tag)]
(fn [obj & args]
Expand All @@ -37,5 +40,7 @@
(apply f obj args))))))

(defn ^{:style/indent :defn} decorate [multi tag decorator]
(swap! (multi) assoc tag decorator)
multi)
(let [state (multi)
iregistry (:iregistry state)]
(swap! iregistry assoc tag decorator)
multi))

0 comments on commit 9e111a1

Please sign in to comment.