From 9e111a1194debb997f447193d1d6f70029d6beb9 Mon Sep 17 00:00:00 2001 From: Mikhail Kuzmin Date: Wed, 19 Feb 2020 22:07:20 +0400 Subject: [PATCH] expose state --- src/darkleaf/multidecorators.cljc | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/darkleaf/multidecorators.cljc b/src/darkleaf/multidecorators.cljc index 04b2d70..a790430 100644 --- a/src/darkleaf/multidecorators.cljc +++ b/src/darkleaf/multidecorators.cljc @@ -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] @@ -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))