Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Grouped components with repetitive config #72

Open
SevereOverfl0w opened this issue Apr 8, 2019 · 1 comment
Open

Grouped components with repetitive config #72

SevereOverfl0w opened this issue Apr 8, 2019 · 1 comment

Comments

@SevereOverfl0w
Copy link
Contributor

Might be worth exploring this space

@SevereOverfl0w
Copy link
Contributor Author

Patch for doing this:

From 494f4226e4dfda65c1b73c4260964113aef9ab6a Mon Sep 17 00:00:00 2001
From: Dominic Monroe <[email protected]>
Date: Mon, 8 Apr 2019 15:32:55 +0100
Subject: [PATCH] Experiment with expanding keysets

---
 lib/edge.system/src/edge/system.clj | 98 +++++++++++++++++++++++++++++
 1 file changed, 98 insertions(+)

diff --git a/lib/edge.system/src/edge/system.clj b/lib/edge.system/src/edge/system.clj
index bff5043..c2ddd48 100644
--- a/lib/edge.system/src/edge/system.clj
+++ b/lib/edge.system/src/edge/system.clj
@@ -12,6 +12,104 @@
 (defmethod aero/reader 'ig/ref [_ _ value]
   (ig/ref value))
 
+(let [expand-keyset (fn [keyset]
+                      (condp #(%1 %2) keyset
+                        vector? (zipmap keyset (repeat {}))
+                        map? keyset))]
+  (defmethod aero/reader 'edge/TBD [_ _ value]
+    (let [[common & keysets] value
+          system (reduce
+                   (fn [system keyset]
+                     (merge system (expand-keyset keyset)))
+                   {}
+                   keysets)]
+      (merge-with merge system (zipmap (keys system) (repeat common))))))
+
+(let [expand-key (fn [k]
+                   (condp #(%1 %2) k
+                     map? k
+                     {k {}}))]
+  (defmethod aero/reader 'edge/TBD2 [_ _ value]
+    (let [[common & ks] value
+          system (reduce
+                   (fn [system k]
+                     (merge system (expand-key k)))
+                   {}
+                   ks)]
+      (merge-with merge system (zipmap (keys system) (repeat common))))))
+
+(let [expand-key (fn [k]
+                   (condp #(%1 %2) k
+                     map? k
+                     {k {}}))]
+  (defmethod aero/reader 'edge/TBD3 [_ _ value]
+    (let [[common ks] value
+          system (reduce
+                   (fn [system k]
+                     (merge system (expand-key k)))
+                   {}
+                   ks)]
+      (merge-with merge system (zipmap (keys system) (repeat common))))))
+
+(aero/reader {} 'edge/TBD [{:foo 1}
+                           [:a :b :c]
+                           {:d {:some-opts 10}}])
+
+#edge/TBD
+
+[{:foo 1}
+ [:a :b :c]
+ {:d {:some-opts 10}}]
+
+(aero/reader {} 'edge/TBD2 [{:foo 1}
+                            :a
+                            :b
+                            :c
+                            {:d {:some-opts 10}}])
+
+#edge/TBD2 [{:foo 1}
+            :a
+            :b
+            :c
+            {:d {:some-opts 10}}]
+
+(aero/reader {} 'edge/TBD3 [{:foo 1}
+                            [:a
+                             :b
+                             :c
+                             {:d {:some-opts 10}}]])
+
+#edge/system-shorthand
+[{:session #ig/ref :session
+  :foo {:a #ig/ref :session}}
+ [:index-resource
+  :foobar-resource
+  {:foobar-resource {:some-opts 10}}]]
+
+(let [expand-key (fn [k]
+                   (condp #(%1 %2) k
+                     map? k
+                     {k {}}))]
+  (defmethod aero/reader 'edge/expand-keys [_ _ value]
+    (let [ks value
+          system (reduce
+                   (fn [system k]
+                     (merge system (expand-key k)))
+                   {}
+                   ks)]
+      system))
+
+  (defmethod aero/reader 'edge/merge-all [_ _ value]
+    (let [[common m] value]
+      (merge-with merge (zipmap (keys m) (repeat common)) m))))
+
+(aero/reader nil 'edge/merge-all
+             [{:foo 1 :bar :a} (aero/reader nil 'edge/expand-keys [:a :b :c {:d {:foo :a :baz :bosh}}])])
+
+#edge/merge-all [{:foo 1 :bar :a}
+                 #edge/expand-keys [:a :b :c {:d {:foo :a}}]]
+
+
 (let [lock (Object.)]
   (defn- load-namespaces
     [system-config]
-- 
2.21.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant