Clojurians
# om

This page is not created by, affiliated with, or supported by Slack Technologies, Inc.

mjhamrick 05:15:34

I went through the https://github.com/omcljs/om/wiki/DataScript-Integration-Tutorial 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?

mjhamrick 05:24:35

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"}]}]) ```

mjhamrick 05:31:28

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

hkjels 09:31:43

@mjhamrick https://github.com/search?utf8=✓&q=om.next+datascript+extension%3Acljs There’s quite a few :slightly_smiling_face:

urbanslug 12:43:17

Is something along these lines allowed?

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

urbanslug 12:43:58

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

iwankaramazow 13:27:18

@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))))})

tmulvaney 15:32:06

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

mjhamrick 17:59:54

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

hkjels 20:35:00

@mjhamrick: your welcome :grinning:

iwankaramazow 22:19:16

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