Skip to content

Commit

Permalink
Obviate need for provider IDs in two places using (resolve)
Browse files Browse the repository at this point in the history
Somewhat more maintainable
  • Loading branch information
dhleong committed Feb 11, 2019
1 parent a911d8c commit c3190b1
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
2 changes: 0 additions & 2 deletions src/cljs/wish/providers.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
[wish.util :refer [>evt]]
[wish.views.widgets :as widgets]))

; NOTE: If you add a provider, make sure to also add
; its IDs to wish.providers.util/provider-id?
(def ^:private providers
{:gdrive
{:id :gdrive
Expand Down
15 changes: 12 additions & 3 deletions src/cljs/wish/providers/util.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,19 @@
:doc "Providers util"}
wish.providers.util)

; lazy resolve to avoid circular dependencies;
; we need to know if a keyword is a provider-id for, eg checking if a
; keyword value is a sheet ID in subs-util, but all sorts of things depend
; on subscriptions—including wish.providers (indirectly) so to prevent
; circular dependencies, we resolve it (and memoize the result) at runtime.
; We *could* just hard-code the provider IDs here, but that duplication
; seems unnecessarily dumb
(def ^:private get-info-ref (delay (resolve 'wish.providers/get-info)))

(defn provider-id?
"Check if the given keyword is the ID of a provider"
[kw]
(when kw
(contains?
#{:gdrive :wish}
kw)))
(not (nil?
(@get-info-ref
kw)))))

0 comments on commit c3190b1

Please sign in to comment.