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

Pull queries do not update if their nested entities change #26

Open
seantempesta opened this issue Apr 30, 2017 · 7 comments
Open

Pull queries do not update if their nested entities change #26

seantempesta opened this issue Apr 30, 2017 · 7 comments

Comments

@seantempesta
Copy link

Ran into this bug today. I had a (pull conn '[*] eid) that wasn't updating when a nested entity within that pull changed. I'm guessing it's because the datom match pattern is just for the specified eid (and not all returned entities)?

Anyway, I setup an example showing the bug here:
https://github.com/seantempesta/posh-bug

The jist of it is this:

(def schema {;; Contact component (shared across entities)
             :contact/email {:db/cardinality :db.cardinality/one}
             :contact/phone {:db/cardinality :db.cardinality/one}

             ;; Users
             :user/username {:db/unique      :db.unique/identity
                             :db/cardinality :db.cardinality/one}
             :user/contact  {:db/valueType   :db.type/ref
                             :db/cardinality :db.cardinality/one
                             :db/isComponent true}})
(def conn (d/create-conn schema))
(posh! conn)


(transact! conn [{:db/id         -1
                  :user/username "seantempesta"
                  :user/contact  {:db/id         -2
                                  :contact/phone "555-5555"
                                  :contact/email "[email protected]"}}])



;; -------------------------
;; Views

(defn home-page []
  (let [user (pull conn '[*] [:user/username "seantempesta"])
        phone (pull conn '[*] 2)]
    [:div [:h2 "Welcome to posh-bug!"]

     [:div [:h4 {} "User Entity"]
      [:h5 {} @user]]

     [:div [:h4 {} "Phone Entity"]
      [:h5 {} @phone]]

     [:input {:type     "button" :value "Remove phone number"
              :on-click #(transact! conn [[:db/retract 2 :contact/phone "555-5555"]])}]]))

screen shot 2017-04-30 at 11 44 37 am

@seantempesta
Copy link
Author

So, I'm really not familiar enough with Posh's internals to fix this. I thought I saw somewhere that Posh might bring back manual specification of listen patterns? At least then I could work around this bug.

@seantempesta
Copy link
Author

Temporary workaround. I found if you explicitly expand isComponent pull patterns the pull analyze picks up the changes.

So, in the example above, you'd have to do something like this:

(pull conn '[:db/id, :user/username, {:user/contact [:db/id, :contact/email, :contact/phone]}] 2)

@metasoarous
Copy link
Collaborator

Yes; it should certainly be looking at isComponent attributes. I'm flagging as bug. Thanks for reporting.

@eoliphan
Copy link

@seantempesta was that all you had to do? I've tried the explicit expansion, still no joy for my reactions

@seantempesta
Copy link
Author

seantempesta commented Nov 30, 2017

@eoliphan: It worked for my scenario at that time. No idea if it's working now as I'm no longer using Posh.

@eoliphan
Copy link

@seantempesta ok, thanks. Yeah, i'm looking at alternatives as well, I really wanted to use DS as I've got Datomic on the server, but probably will just go with specter and maps, etc. for now until I can maybe look at figuring out the posh code and doing some hacking.

@tkachenko1503
Copy link

Hello guys! I've got the same issue with nested components. Are there some ways to solve this issue? I can try to help with it if someone has an idea how to fix this bug.

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

No branches or pull requests

4 participants