Skip to content

Instantly share code, notes, and snippets.

@si14

si14/join.cljs Secret

Created July 31, 2016 20:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save si14/db0ed40123c14a28b6f5808e3a824c1d to your computer and use it in GitHub Desktop.
Save si14/db0ed40123c14a28b6f5808e3a824c1d to your computer and use it in GitHub Desktop.
(def PACKAGE-ID s/Int)
(def PACKAGE
{:id PACKAGE-ID
:url s/Str
:inner_title s/Str})
(def db-schema
{:package-ids [PACKAGE-ID]
:package/by-id {PACKAGE-ID PACKAGE}})
;; probably not that efficient (if I understand correctly)
(register-sub
:packages
(fn [db _]
(reaction (mapv (:package/by-id @db) (:packages @db)))))
;; should be better (mapv will not be run on each @db change)
;; ...trivial :package/by-id and :package-ids subscriptions...
(register-sub
:packages-better
(fn [db _]
(let [package-by-id (subscribe [:package/by-id)])
package-ids (subscribe [:package-ids])]
(reaction (mapv package-by-id package-ids))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment