Fork me on GitHub

I went through the and found it made a lot of sense. But when trying to write my own code using datascript, i'm running into a lot of confusion when trying to get the pulls to work correctly. Are there other examples out there of using datascript with om-next?


I have a feeling the problem I'm having has something to do with how the idents work, but I'm not sure. I'm trying to have these queries get a list of transactions, but I'm missing something when it comes to how the query and key come in

(defui Transaction
  static om/IQuery
  (query [this]
         [:transaction/date :transaction/account :transaction/payee
          :transaction/memo :transaction/outflow :transaction/inflow]) ...

(defui TransactionView
  static om/IQuery
  (query [this]
         [{:account/transaction (om/get-query Transaction)}]) ...

(defmulti read om/dispatch)
(defmethod read :account/transaction
  [{:keys [state query] :as env} _ _]
  (pprint/pprint [query])
  {:value (d/q '[:find [(pull ?e ?selector) ...]
                 :in $ ?selector
                 :where [?e :account/transaction]]
               (d/db state) query)})

;; And my datascript db, if that helps...
(def conn (d/create-conn {:account/transaction {:db/valueType :db.type/ref
                                                :db/cardinality :db.cardinality/many}}))

(d/transact! conn [{:db/id -1
                    :account/name "My Account"
                    :account/transaction [{:transaction/inflow "100.00"
                                           :transaction/date "yesterday"}
                                          {:transaction/outflow "13.00"
                                           :transaction/date "yesterday"}]}])


I put in a console.log for (om/get-props this) on the Transaction view and I get {:account/transaction [nil]}


Is something along these lines allowed?

(om/update! app-state {:foo bar :foobar baz})


Where it should mutate the current value if it exists in app-state or create the key value pair if it doesn’t exist.


@urbanslug: I think you're looking at a combination of swap! (mutate an atom) and assoc (update key in a map)

(defmethod mutate 'mutation/example
  [{:keys [state]} key params]
  {:action #(swap! state (fn [st]
                           (-> st
                               (assoc :foo :bar)
                               (assoc :foobaz :baz))))})


@urbanslug you could also do (swap! app-state merge {:foo :bar :foobar :baz})


@hkjels thanks! I didn't realize you could search github like that.


@mjhamrick: your welcome 😀


Figwheel + fix/continue with om/from-history never gets old 😌