Fork me on GitHub
#fulcro
<
2020-05-23
>
jacklombard09:05:29

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.

jacklombard10:05:02

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])))))))

jacklombard10:05:32

But not sure why merge component shouldn't work

Chris O’Donnell12:05:06

Your :append clause should not be in a vector, I think.

jacklombard12:05:06

Oops, thanks for pointing out. Removed the enclosing vector and tried but still clears the whole app database

Chris O’Donnell12:05:08

Oh of course. merge/merge-component! takes a component or app as its first parameter, not your state atom.

Chris O’Donnell12:05:43

You want merge/merge-component, which is a pure function from state map to state map.

Chris O’Donnell12:05:18

merge-component! is intended for use outside of mutations

jacklombard12:05:16

Oh great thanks, that is the information I was looking for.

👍 4
jacklombard12:05:04

Works perfectly!

Chris O’Donnell12:05:42

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.)

jacklombard12:05:42

Noted, thanks 👍

murtaza5215:05:52

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 ?

Jakub Holý (HolyJak)18:05:45

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

murtaza5208:05:54

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.

dvingo16:05:19

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

👍 16
Adrian Smith20:05:32

Is there a way to get Cursive to understand the defsc macro?

Björn Ebbinghaus21:05:29

Alt+Enter on defsc -> resolve as -> defn Same for defmutation

❤️ 4
Adrian Smith10:05:11

cool ty, I have no difference but if I disable LSP the errors go away so I assume they're from clj-kondo

Adrian Smith10:05:01

Adding {:lint-as {com.fulcrologic.fulcro.components/defsc clojure.core/defn}} to .clj-kondo/config.edn solved that

dvingo12:05:58

unrelated question.. what color scheme is that? 🙂

Adrian Smith12:05:52

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

Adrian Smith20:05:18

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

Adrian Smith20:05:29

Starting to think I did something wrong lol

Adrian Smith20:05:51

cool fixed it had a typo in my deps.edn file