This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2016-09-05
Channels
- # bangalore-clj (4)
- # boot (196)
- # chestnut (1)
- # cider (4)
- # clara (3)
- # cljs-dev (23)
- # cljsjs (28)
- # cljsrn (1)
- # clojure (79)
- # clojure-art (1)
- # clojure-berlin (1)
- # clojure-hk (17)
- # clojure-italy (5)
- # clojure-korea (1)
- # clojure-russia (21)
- # clojure-spec (5)
- # clojure-uk (26)
- # clojurescript (125)
- # core-async (1)
- # cursive (23)
- # datomic (7)
- # emacs (17)
- # hoplon (51)
- # jobs (2)
- # leiningen (2)
- # om (11)
- # om-next (26)
- # onyx (39)
- # pedestal (9)
- # proton (4)
- # re-frame (43)
- # reagent (1)
- # ring (2)
- # slack-help (12)
- # sydney (4)
- # test-check (9)
- # yada (40)
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?
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]}
@mjhamrick https://github.com/search?utf8=✓&q=om.next+datascript+extension%3Acljs There’s quite a few 🙂
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})
@mjhamrick: your welcome 😀
Figwheel + fix/continue with om/from-history
never gets old 😌