cljfx

https://github.com/cljfx/cljfx
jlmr 2020-03-29T13:14:59.008100Z

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 ๐Ÿ™‚

vlaaad 2020-03-29T13:30:35.008600Z

Either way to ask is fine ๐Ÿ™‚

vlaaad 2020-03-29T13:31:18.009400Z

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

vlaaad 2020-03-29T13:31:39.009900Z

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

vlaaad 2020-03-29T13:32:09.010500Z

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

vlaaad 2020-03-29T13:33:32.011400Z

@jlmr ^

jlmr 2020-03-29T13:34:28.012200Z

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

jlmr 2020-03-29T13:39:07.013200Z

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

jlmr 2020-03-29T13:48:16.013700Z

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๐Ÿ‘