Fork me on GitHub

Hi @smith.adriane, I’m still tinkering with membrane. I’m pretty sure the (slightly to big) toy project I’d like to build requires hybrid state consisting of: • “ephemeral” ui data (e.g. which item is selected), stored in memory (atom?) • “durable” data (e.g. the descriptions of items), stored in a database Right now I’m struggling to figure out what is the best way to build this. I was hoping to run my current idea by you: • Create some custom structure that supports IDeref. • The structure contains a regular map, storing the “ephemeral” data. • However some paths in the map would contain database queries. • Whenever the structure is dereffed, all queries are executed and their results stored under the corresponding paths (this step could be cached as well). With this setup I could still use membrane’s state management solution for “ephemeral” data e.g. [:update path], [:delete path] etc. When a component wants to access some data, all it has to do is trigger an effect handler which [:set] s some path in the structure to be query. Do you think this is a viable route? Or is it completely crazy?


That sounds reasonable, but I don't think you need to mimic IDeref. In your make-app function, you can just deref the atom that holds the ephemeral state and merge in the data from the database.


maybe something like:

(defn make-app
  ([ui-var conn query]
   (let [
         ephemeral-state (atom {})
         handler (component/default-handler ephemeral-state)
         arglist (-> ui-var
         m (first arglist)
         arg-names (disj (set (:keys m))
         defaults (:or m)
         top-level (fn []
                     (component/top-level-ui {:state (merge @ephemeral-state
                                                            (db/query @conn query))
                                              :$state []
                                              :body ui-var
                                              :arg-names arg-names
                                              :defaults defaults
                                              :handler handler}))]


If you're able to share, what database and backend are you planning on using? I might be able to provide a better example.


Looks great, thanks!


I’m planning on using crux


What does the $state [] keyval do in the call to top-level-ui?


It doesn’t seem to be something that top-level-ui actually uses


that's true. I made some improvements to defui that makes :$state superfluous in this case

👍 3

generally, the keywords that start with dollar sign allow you to explicitly provide the reference for the corresponding key.


usually, all the $ args are automatically handled for you, but there are some cases where it's useful for dev tooling and testing