The way to easily use DataScript as your webapp's data storage

Noticed that there are a lot of people who prefer using simple atoms as a data store for their web apps. I came from the React/Redux land and initially considered this an ok way. But data normalization (and accessing the normalized store) can be not trivial and sometimes has performance drawbacks.

Then I found DataScript, an awesome in-memory database. But having a database is not enough, one also needs some reactive way to watch queries (it’s 2019 year). Turns out it’s also already done in Posh library. It allows you to have “query as atom”, watch it and update your view accordingly (it’s integrated with reagent and rum is on its way).

You can go even deeper and use Re-Posh to use DataScript as your data storage inside re-frame. Use datalog queries as subscriptions and dispatch transactions instead of regular functions. Re-posh recently got pull-many support.

So, why not give it a shot?

2 Likes

I would like to try re-posh. Is there a way to gradually integrate it to an existing re-frame application? Or do I have to convert all events and subscriptions at once?

No, you don’t have to convert your app. Just connect! DataScript database and use re-frame/reg-sub for atom subscribtons and re-posh/reg-query-sub for query subscriptions, re-frame/reg-event-db for atom updates and re-posh/reg-event-ds for DataScript transaction-like events.
Re-posh not create new functionality, it just wraps re-frame, so use both at the same time is perfectly fine.

2 Likes