What are ways to use re-frame with Datascript? I thought of using re-posh, but it seems to be abandoned / not supported.
I would use the function db-with and keep the dereffed datascript db in app-db.
I'd say it still defeats the purpose of re-frame. Your app's state is not in a single location anymore since a mutable reference to the data is not the data itself. E.g. with the intended way of using re-frame, you can pass the whole app-db somewhere and be certain that it won't change from under you. You can have a way to restore the whole app to the most recent working state if it crashes, not losing any data at all. You can somewhat easily create a global undo/redo mechanism. And so on. I use all of that in my apps (undo/redo only where it's needed), and I don't think I'll ever use any other approach in apps where I make decisions. All of that goes out the window with multiple data storages.
https://day8.github.io/re-frame/application-state/#the-benefits
Sorry, if I was unclear. The method I suggested avoids exactly that problem. Datascript can, just like datomic, have derefed, immutable database states.
To derive a new database-state, use the with (`db-with` is a helper availiable in datascript) and add this new reference to the new app-db.
It is like an immutable hash-map and doing assoc or update on it.
(update app-db :datascript db-with [[tx data]])
Ah, so the whole Datascript data will basically live inside re-frame's app-db, without anything external to it at all? If yes and if it's a normal mode of operation for Datascript, then yeah, that's probably the best approach.
Yes. The normal datascript database resides in an atom where it is possible to register transaction listeners (i think using watch), this will not work anymore if you just add transactions to the derefed database using with, but this is the sane way of using the datascript datastructure in an app-db, yes.
This gives benefits mainly in terms of normalization and reference handling and, of course, makes it possible to query the data structure using datalog. Posh tried to do this with streaming datalog queries, If i remember correctly, which did not work exactly as I wanted it to when I evaluated it 10 years ago.
Cool, thanks!
If that use is very niche, just create an effect and maybe some other things that sync a small amount of specific values between a Datascript DB and the re-frame's app-db. Re-posh itself is just 200 loc and most of those are docstrings or slightly modified copy-pasted lines from re-frame. If you want to store all your data in Datascript, then re-frame is a bad fit. But it might make sense to create something like re-frame on top of Datascript.