Skip to content

Latest commit

 

History

History
46 lines (34 loc) · 1.78 KB

2020-07-22.md

File metadata and controls

46 lines (34 loc) · 1.78 KB

Learning Clojure in Public - Week 5 Day 3 (31/35)

Expectations

The only expectation of the day is to open the pull request for the page deletion issue in Athens.

What I learned

And open the PR we did, and even earlier than I expected. Here is a rundown of the most recent changes. First I added Mani's function to get the children of a block from its uid:

(defn get-children-recursively
  "Get list of children UIDs for given block ID"
  [uid]
  (let [document (->> @(pull dsdb '[:block/order :block/uid {:block/children ...}] (get-id uid)))]
    (->> (tree-seq :block/children :block/children document)
         (map :block/uid))))

He also wrote a helper function to get the database id, from the uid:

(defn get-id
  [uid]
  (-> (d/q '[:find ?id
             :in $ ?uid
             :where [?id :block/uid ?uid]]
           @dsdb
           uid)
      ffirst))

Finally we use the function itself in the event handler so we can delete all the UIDs retrieved by get-children-recursively. Datascript's :transact! can take a vector of vectors to batch delete several entries in the database (hence the use of vec, since map returns a list).

(reg-event-fx
  :page/delete
  (fn [_ [_ uid]]
    {:transact! (vec (map (fn [uid] [:db/retract [:block/uid uid] :block/uid]) (get-children-recursively uid)))}))

The PR has been opened and is awaiting feedback.

Takeaways

Not much to bring up and to takeaway. I am learning a lot more about how the different pieces I studied fit together. It really feels like the fun stuff is happening right now. Yet there is still a lot of ground to cover. A few things I want to dig deeper into are datascript, paredit (to edit faster!) and datalog (again)!