tape.datascript
Integrates the datascript data
structure via a tape.mvc.controller module, and provides co/effects to
interact with an instance.
You can use it as a replacement of app-db, or as an in-browser DB, save it to LocalStorage etc.
You must be familiar with datascript,
tape.module and tape.mvc (particularly the controller part) before
proceeding.
Add tape.datascript to your deps:
{:deps {tape/datascript {:local/root "../datascript"}}}In config.edn add :tape.datascript.controller/module (and your schema, if
any):
{:tape.profile/base {:tape.datascript.controller/schema <schema-map>}
:tape.datascript.controller/module nil}For less verbose destructure calls, require in your ns:
(ns sample.app.some.controller
(:require [tape.datascript.controller :as datascript.c]))In fx handlers that use it, add it to the interceptor chain via metadata and use
the ds coeffect and effect:
(defn save
{::c/reg ::c/event-fx
::c/interceptors [datascript.c/inject]}
[{::datascript.c/keys [ds]} params]
{::datascript.c/ds (d/db-with ds (some-model/make-tx-data params))})If all the handlers in the namespace will require it, you can add the interceptor as metadata at the namespace level:
(ns sample.app.some.controller
"Some docstring."
{:tape.mvc.controller/interceptors [datascript.c/inject]}
(:require [tape.datascript.controller :as datascript.c]))If you used it akin to app-db, the equivalent of re-frame.db/app-db is
::datascript.c/ds entry in the system map and you can build a signal graph on
it via rf/reg-sub-raw.