Fork me on GitHub

@quoll I'd like an opinion; I have an in-memory db with asami, and from some of the query in that database I'd like to create some visualizations (using reagent). What's the best way of syncing a r/atom to a query in my in-memory db in your opinion?


To be more clear, I'd like that when I do a transaction, the query that powers a r/atom is redone, so that redrawing is triggered on the js side


maybe there's even a library that does this kind of integration for reagent?


I don’t think there is (I certainly haven’t done it)


There’s currently no hook for a transaction to execute code when it’s done. Typically, I’ve created my own transaction function to wrap the central one, though I know that doesn’t always work.


At this point, I would recommend putting a watch on the Connection state field (which is an atom)


So if you have a connection called c then: (add-watch (:state c) :your-key your-fn)


The state atom contains a map with 2 values:

{:db latest-db-value
 :history [...]}
The history is an array of all the previous DB values


I realize that this is unsatisfactory. It’s incentive for me to add a transaction function post haste


Anyway, every call to transact will lead to this atom being updated. The :db value will change to have the updates in it, and the :history value will grow 1 longer


This will take more effort than a simple hook, but would you be interested in seeing this whole API?


thank you so much for the explanation @quoll! In my case I can probably work around the problem with a watch as you suggested. I mostly don't want to cause any urge since I know that you're not working on this directly in these days. Ideally from the API you linked I really like having the possibility to specify checks and constraints, but I'm not very familiar with it - watching the video now :)


Oh? Which video?

william16:10:37 which was linked in the page you suggested


it's a very nice idea, and I didn't realize that asami tends to the same API of datomic! Neat!


anyway, if you ever end up implementing the hook feature ping me - also, if you want to pair on the issue I'm up for it


generally. The idea was to make it easier for people to try using it


can asami dbs be used as immutable values? i.e. w/o a connection container


w/ datascript you can eschew the whole “conn” and just use db-with which returns a new db value. this way you can store it in your own container, like a reagent ratom


Yes. Databases are an immutable value


You can easily wrap them in a new connection and they will be a db-with value


I can’t do that with persisted databases though. (well, I could, but that would create a branch, and I have no idea how to resolve branches!)


can you show me how this technique would look like? I mean, using in-memory databases as values without using the connection abstraction?


Databases (retrieved via (asami.core/db my-connection) or (asami.core/as-of some-db some-time) etc) are already a value, and can be queried. You can make it a connection that can be transacted against with: (asami.memory/new-connection “asami:” my-db)

🙌 1