Skip to content

Commit

Permalink
fix(db): revert connect! fuction
Browse files Browse the repository at this point in the history
User should have acces to his datascript connection. It allows him to create
database with schema, store it somewhere and do something else with it.
  • Loading branch information
denistakeda committed Jun 16, 2018
1 parent 424fc11 commit 303d079
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 12 deletions.
15 changes: 14 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion examples/todomvc/project.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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"]]

Expand Down
7 changes: 6 additions & 1 deletion examples/todomvc/src/cljs/todomvc/db.cljs
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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)
3 changes: 2 additions & 1 deletion project.clj
Original file line number Diff line number Diff line change
@@ -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"]])
2 changes: 2 additions & 0 deletions src/re_posh/core.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
12 changes: 4 additions & 8 deletions src/re_posh/db.cljc
Original file line number Diff line number Diff line change
@@ -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))

0 comments on commit 303d079

Please sign in to comment.