https://github.com/carocad/rata
State management through Datascript and Reagent
https://github.com/carocad/rata
datascript react reagent state-management
Last synced: about 2 months ago
JSON representation
State management through Datascript and Reagent
- Host: GitHub
- URL: https://github.com/carocad/rata
- Owner: carocad
- License: lgpl-3.0
- Created: 2018-10-05T21:07:21.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2019-03-31T12:17:48.000Z (almost 7 years ago)
- Last Synced: 2025-10-20T08:39:26.989Z (3 months ago)
- Topics: datascript, react, reagent, state-management
- Language: Clojure
- Homepage:
- Size: 19.5 KB
- Stars: 41
- Watchers: 3
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# rata
[](https://travis-ci.com/hiposfer/rata)
[](https://clojars.org/hiposfer/rata)
State management through [Datascript](https://github.com/tonsky/datascript/)
and [Reagent's](https://github.com/reagent-project/reagent) track mechanism
## usage
Rata hooks itself into the transactor of Datascript. So you just need to register
it against Datascript's connection. From that point onwards, you should use
`rata/q!` and `rata/pull!` with the **connection**. Rata also provides a `transact!`
functions which accepts a sequence of middlewares; middlewares are useful to add
extra capabilities like transaction logging, data based effects, etc.
Check the [example](example) directory for a working project
```clojure
(ns example.core
(:require [reagent.core :as reagent :refer [atom]]
[datascript.core :as data]
[hiposfer.rata.core :as rata]))
(def schema {:user/input {:db.unique :db.unique/identity}})
(defn- logger
[middleware]
(fn log* [db transaction]
(let [transaction (middleware db transaction)]
(apply js/console.log (clj->js transaction))
transaction)))
;; state is a standard Clojure Atom containing a Datascript DB
(defonce state (rata/listen! (data/create-conn schema)
[logger])) ;; middleware chain
(defn example
[]
(let [click-count @(rata/q! '[:find ?count .
:where [?input :user/input "click"]
[?input :click/count ?count]]
state)]
[:div "For each click, you get a greeting :)"
[:input {:type "button" :value "Click me!"
;; rata/transact! usage here instead of data/transact! ------
:on-click #(rata/transact! state [{:user/input "click"
:click/count (inc click-count)}])}]
(for [i (range click-count)]
^{:key i}
[:div "hello " i])]))
(reagent/render-component [example] (. js/document (getElementById "app")))
(defn on-js-reload [])
```
## License
Copyright © 2018
Distributed under LGPLv3