diff --git a/README.md b/README.md index a11f04d..95b8037 100644 --- a/README.md +++ b/README.md @@ -25,7 +25,7 @@ State management within *any* application, if treated as a secondary concern, ca Start a re-frame project and include this dependency: ```clj -[re-posh "0.2.0"] +[re-posh "0.3.0"] ``` Require `re-posh` in your app: @@ -35,6 +35,19 @@ Require `re-posh` in your app: [re-posh.core :refer [reg-query-sub reg-pull-sub reg-event-ds subscribe dispatch]])) ``` +## Connection + +Connect your DataScript database to `re-posh`: +```clojure +(ns example.db + (:require + [datascript.core :as d] + [re-posh.core :refer [connect!]])) + +(def conn (d/create-conn)) +(connect! conn) +``` + ## Subscriptions You can subscribe to the DataScript database with a query subscription or with a pull subscription. diff --git a/examples/todomvc/project.clj b/examples/todomvc/project.clj index 3c03cfb..1554ac2 100644 --- a/examples/todomvc/project.clj +++ b/examples/todomvc/project.clj @@ -2,7 +2,7 @@ :dependencies [[org.clojure/clojure "1.8.0"] [org.clojure/clojurescript "1.10.238"] [reagent "0.8.1"] - [re-posh "0.2.0"]] + [re-posh "0.3.0"]] :plugins [[lein-cljsbuild "1.1.7"]] diff --git a/examples/todomvc/src/cljs/todomvc/db.cljs b/examples/todomvc/src/cljs/todomvc/db.cljs index 0c92f45..0a28311 100644 --- a/examples/todomvc/src/cljs/todomvc/db.cljs +++ b/examples/todomvc/src/cljs/todomvc/db.cljs @@ -1,4 +1,6 @@ -(ns todomvc.db) +(ns todomvc.db + (:require [datascript.core :as datascript] + [re-posh.core :as re-posh])) (def initial-db [{:db/id -1 @@ -15,3 +17,6 @@ :task/title "Have a coffe" :task/description "Just relax" :task/done? false}]) + +(def conn (datascript/create-conn)) +(re-posh/connect! conn) diff --git a/project.clj b/project.clj index 8fee77f..a86727f 100644 --- a/project.clj +++ b/project.clj @@ -1,8 +1,9 @@ -(defproject re-posh "0.2.0" +(defproject re-posh "0.3.0" :description "Use your re-frame with DataScript as a data storage" :url "https://github.com/denistakeda/re-posh" :license {:name "MIT" :url "https://opensource.org/licenses/MIT"} :dependencies [[org.clojure/clojure "1.9.0"] + [datascript "0.16.6"] [re-frame "0.10.5"] [posh "0.5.5"]]) diff --git a/src/re_posh/core.cljc b/src/re_posh/core.cljc index a711963..04fa2fd 100644 --- a/src/re_posh/core.cljc +++ b/src/re_posh/core.cljc @@ -4,12 +4,14 @@ [re-posh.events :as events] [re-posh.effects] [re-posh.coeffects] + [re-posh.db :as db] [re-frame.core :as re-frame])) (def reg-query-sub subs/reg-query-sub) (def reg-pull-sub subs/reg-pull-sub) (def reg-sub subs/reg-sub) (def reg-event-ds events/reg-event-ds) +(def connect! db/connect!) ;; Reexport re-frame functions (def subscribe re-frame/subscribe) diff --git a/src/re_posh/db.cljc b/src/re_posh/db.cljc index c68c5ae..70172ad 100644 --- a/src/re_posh/db.cljc +++ b/src/re_posh/db.cljc @@ -1,17 +1,13 @@ (ns re-posh.db (:require - [posh.reagent :as p] - [datascript.core :as datascript])) + [posh.reagent :as p])) ;; Basic store. This atom stores another atom ;; @store - datascript connection ;; @@store - datascript database (def store (atom nil)) -(defn- connect! [] +(defn connect! [conn] "Connect DataScript store to the re-frame event system" - (let [conn (datascript/create-conn)] - (p/posh! conn) - (reset! store conn))) - -(connect!) + (p/posh! conn) + (reset! store conn))