cljfx 2020-03-29

Hi @vlaaad, I have a subscription that looks like this:

(defn sub-current-page
  [context]
  (println "fire!")
  (let [db (fx/sub context :db)
        eid (fx/sub context :eid)]
    (d/entity db eid)))
The :dbkey contains the latest value of a https://github.com/replikativ/datahike/ database, which I swap! to the latest db value every time a transaction occurs. (Based on your example of the datascript db). However, the subscription only fires when :eid changes, not when :db changes. Any ideas why this could be happening? Also let me know if youโ€™d rather get these questions as GH issues ๐Ÿ™‚

Either way to ask is fine ๐Ÿ™‚

Could it be that datahike returns true for (= old-db new-db) ?

At least I know it has these kinds of problems in it's entity API

which defines equality only based on id, but not db, which is very very wrong...

Thanks, will look at that. Youโ€™re probably right

Hm:

(defn transact
  [conn tx-data]
  (let [report (d/transact conn tx-data)]
    (swap! *context fx/swap-context assoc-in [:db] (:db-after report))
    (= (:db-before report) (:db-after report))))
Returns false for any transaction

Ok changing the subscription to this:

(defn sub-current-page
  [context]
  (let [db (fx/sub context :db)
        eid (fx/sub context :eid)]
    (d/pull db '[*] eid)))
Fixes it!

๐Ÿ‘ 1