Fork me on GitHub

I'm using reagent for a small app. I'd like to persist parts of the "html" / hiccup in the database, since it may change. But I have no idea, how to persist it to a dabase and get it back rendered as valid hiccup. Do you see a way, how to persist "layouted text" in the database?

Daniel Craig15:01:50

are you using re-frame? just out of curiousity


no, not even sure what re-frame is all about...


@USDPTD3FY currently looking into it. looks very interesting, makes fun reading documentation, this one catched me:

Sure, right now, you're thinking "lazy sod - make a proper Computer Science-y diagram". But, no. Joe Armstrong says "don't break the laws of physics" - I'm sure you've seen the videos - and if he says to do something, you do it (unless Rich Hickey disagrees, and says to do something else).

Daniel Craig16:01:13

Reframe is nice 🙂. but since you aren't using it don't feel pressured to dive into it right now

Daniel Craig16:01:29

The reason I ask is that re-frame's philosophy is that rendered views i.e. hiccup should always be derived from data, and that the data should flow into the view functions and not the other way around

Daniel Craig16:01:05

so storing layouted text in the db would be against the recommendations of that particular tool

Daniel Craig16:01:36

but as you are not using re-frame, there is no need to obey this


Are you using a single atom for your app-state?


Oh, I dont feel pressure. It's really fun for me playing around in that domain and exploring all that stuff!


or at least the piece that you want to persist


then, this is a simple approach: you can pr-str the atom into local storage, and edn/read-string it back into data.


does that make sense


@U051GFP2V yes it does! Im gonna give that one a try.


storage-atom persists its own state for you


makes sense....


keys and values have to be strings — I’d writ it like this with the string encoding/decoding

(ns localstorage
  (:require [clojure.edn :as edn]))

(defn set-item!
  "Set `key' in browser's localStorage to `val`."
  [key val]
  (.setItem (.-localStorage js/window) (pr-str key) (pr-str val)))

(defn get-item
  "Returns value of `key' from browser's localStorage."
  (edn/read-string (.getItem (.-localStorage js/window) (pr-str key))))

(defn remove-item!
  "Remove the browser's localStorage value for the given `key`"
  (.removeItem (.-localStorage js/window) (edn/read-string key)))


then you can use arbitrary clojure data (but not funcitons / objects).

Andre Ulle19:01:37

I need to check if a context is true, and the way I know how to do it is through the clojure.core/match function, but I don't need any action, I just want to know if the context fits my conditions. I'm doing something like:

(defn fit-context? [event-name input]
  (match [event-name input]
         [: ({:context {:context/reason (_ :guard is-bla?)}
                                        :person             {:type :nice-person}}
                                       :guard [not-that?
         :else false))
how could i do the same, without needing to explicitly return true or false

Andre Ulle21:01:23

I was adding unnecessary complexity for something very simple rsrs I use the and function for that