This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-05-23
Channels
- # announcements (5)
- # aws (9)
- # babashka (60)
- # beginners (561)
- # calva (8)
- # cider (17)
- # clj-kondo (1)
- # cljsrn (12)
- # clojure (36)
- # clojure-dev (3)
- # clojure-europe (3)
- # clojure-france (10)
- # clojure-greece (8)
- # clojure-italy (6)
- # clojure-spec (3)
- # clojure-uk (6)
- # clojurescript (30)
- # community-development (2)
- # conjure (15)
- # datascript (24)
- # figwheel-main (49)
- # fulcro (29)
- # helix (72)
- # off-topic (20)
- # pathom (7)
- # rum (7)
- # shadow-cljs (23)
- # spacemacs (6)
- # sql (8)
- # timbre (1)
- # xtdb (10)
I am starting off with a simple todo app just to understand how fulcro works. But I am stuck in adding a todo. When I click on the add button (comp/transact! this [(add-todo {:list-id list-id :value value})])
is called which clears the app database completely instead of merging the component. I can't seem to figure out what I am doing wrong in the defmutation block.
Okay the following worked,
(defmutation add-todo [{:keys [list-id value]}]
(action
[{:keys [state]}]
(let [new-id (inc (get-in @state [:todo-list/id list-id :todo-list/item-count]))]
(swap! state (fn [s]
(-> s
(assoc-in [:todo-item/id new-id] {:todo-item/id new-id :todo-item/value value})
(target/integrate-ident* [:todo-item/id new-id]
:append [:todo-list/id list-id :todo-list/items])))))))
But not sure why merge component shouldn't work
Your :append
clause should not be in a vector, I think.
See http://book.fulcrologic.com/#_merge_component_demo for an example
Oops, thanks for pointing out. Removed the enclosing vector and tried but still clears the whole app database
Oh of course. merge/merge-component!
takes a component or app as its first parameter, not your state atom.
You want merge/merge-component
, which is a pure function from state map to state map.
merge-component!
is intended for use outside of mutations
Works perfectly!
Great 🙂
A minor side note: of course name your components as you like, but it is idiomatic to use camel case. (So Todo-item
would be TodoItem
.)
Noted, thanks 👍
Th below is from the rad demo project -
(defattr line-items :invoice/line-items :ref
{ao/target :line-item/id
:com.fulcrologic.rad.database-adapters.sql/delete-referent? true
:com.fulcrologic.rad.database-adapters.datomic/attribute-schema {:db/isComponent true}
ao/cardinality :many
ao/identities #{:invoice/id}
ao/schema :production})
The above has a property from the sql adapter and another from the datomic adapter, so does the sql property also work for datomic, or is it only for sql ?It has both so that you can use either with Datomic or a SQL DB but only the respective keys work for a particular storage
thanks, that makes sense. I had assumed that the attribute is suppose to be persisted to both db's, or that the sql key also applies to the datomic behaviour.
I wanted a pdf version of the fulcro guide. Attaching here in case others want it also. I put a note here if you want to make your own for future versions: https://github.com/fulcrologic/fulcro-developer-guide/pull/50
Is there a way to get Cursive to understand the defsc macro?
cool ty, I have no difference but if I disable LSP the errors go away so I assume they're from clj-kondo
Adding {:lint-as {com.fulcrologic.fulcro.components/defsc clojure.core/defn}}
to .clj-kondo/config.edn solved that
Not sure, the name says Monokai Pro with my edits, I know I made the edits but I don't know if that was the correct base
Also this seems quite out of date: https://clojars.org/fulcrologic/fulcro Cursive said it couldn't find 2.8.13 on maven, so I went to maven directly and got 3.2.8 which imported correctly
ah I see it's https://clojars.org/com.fulcrologic/fulcro for latest
Starting to think I did something wrong lol
cool fixed it had a typo in my deps.edn file