datascript

Immutable database and Datalog query engine for Clojure, ClojureScript and JS
2021-02-18T16:55:39.044Z

Hey all, Just wanted to share something I’ve been working on recently that essentially lets you use datascript’s d/entity API (well, something similar) in reagent components, only triggering re-renders when the attributes you accessed on each entity change. https://github.com/austinbirch/reactive-entity It’s pretty early on implementation-wise, but I figured that maybe some people here would have experience using reagent and datascript together, so this might be worth sharing now anyway. I apologise in advance for the readme, I just blurted it out in one sitting so it’s a bit stream of consciousness at the moment.

👀 1
teodorlu 2021-02-20T10:35:42.007500Z

I assume this is going to be a bit more efficient than just putting the Datascript DB in a reagent atom?

teodorlu 2021-02-20T10:36:12.007700Z

I did that once, and it was fine for my small DB.

2021-02-21T14:38:30.017300Z

Sorry @teodorlu, I’ve only just seen this. Yeah, that’s it. If you put the DataScript DB in a reagent atom then all components that deref that atom will re-render on any DB change. For many apps this works, but for apps that have a lot of UI components, or components that are expensive to render, then it becomes less than ideal. There are other libraries that help solve this same problem, the most well-known is posh (https://github.com/mpdairy/posh). I’ve used posh a lot and it’s great. This library essentially does the same sort of thing that posh does for d/q & d/pull, but for d/entity.

👍 1