Liking cljdoc? Tell your friends :D

homebase.reagent


connect!cljs

(connect! db-conn)

Connects a db-conn to a homebase.cache. This is a prerequisite for any of the db read functions in this namespace (entity, q) to be reactive. Returns a homebase.cache connection.

(def db-conn (datascript/create-conn))
(hbr/connect! db-conn)
Connects a db-conn to a homebase.cache. This is a prerequisite for any of the db read functions in this namespace ([[entity]], [[q]]) to be reactive. Returns a homebase.cache connection.

```clojure
(def db-conn (datascript/create-conn))
(hbr/connect! db-conn)
```
sourceraw docstring

disconnect!cljs

(disconnect! db-conn)
source

Entitycljs

source

entitycljs

(entity db-conn lookup)

Returns a reactive homebase.reagent/Entity wrapped in a vector.

It offers a normalized subset of other entity APIs with the primary addition being that implemented protocols are reactive and trigger re-renders when related datoms change.

Usage:

(defn your-component []
  (let [[entity-1] (hbr/entity db-conn 1)
        [entity-2] (hbr/entity db-conn [:uniq-attr :value])]
    (fn []
      [:div
       (:attr @entity-1)
       (get-in @entity-2 [:ref-attr :attr])])))

Gotchas:

  • This takes a conn, not a db.
  • homebase.reagent/Entity only implements the ILookup and IFn protocols, i.e. only attribute lookups like (:attr hbr-entity).
    • Use non-reactive entities from your DB if you need to use other protocols.
      • E.g. (datascript/entity @db-conn 1)
Returns a reactive `homebase.reagent/Entity` wrapped in a vector. 

It offers a normalized subset of other entity APIs with the
primary addition being that implemented protocols are reactive 
and trigger re-renders when related datoms change. 

Usage:

```clojure
(defn your-component []
  (let [[entity-1] (hbr/entity db-conn 1)
        [entity-2] (hbr/entity db-conn [:uniq-attr :value])]
    (fn []
      [:div
       (:attr @entity-1)
       (get-in @entity-2 [:ref-attr :attr])])))
```

Gotchas:

- **This takes a conn, not a db.**
- `homebase.reagent/Entity` only implements the `ILookup` and `IFn` protocols, i.e. only attribute lookups like `(:attr hbr-entity)`.
  - Use non-reactive entities from your DB if you need to use other protocols.
    - E.g. `(datascript/entity @db-conn 1)`
sourceraw docstring

qcljs

(q query db-conn & inputs)

Returns a reactive query result wrapped in a vector.

It will trigger a re-render when its result changes.

Usage:

(defn your-component []
  (let [[query-result] (hbr/q db-conn [:find [?e ...]
                                       :where [?e :attr]])]
    (fn []
      [:div
       (for [eid @query-result]
         ^{:key eid}[another-component eid])])))

Gotchas:

  • This takes a conn, not a db.
  • At the moment it's only possible to connect! to one DB at a time, so reactive query results are only supported on one DB. If you pass more DBs as args the query will only be rerun if the first DB changes.
Returns a reactive query result wrapped in a vector. 

It will trigger a re-render when its result changes. 

Usage:

```clojure
(defn your-component []
  (let [[query-result] (hbr/q db-conn [:find [?e ...]
                                       :where [?e :attr]])]
    (fn []
      [:div
       (for [eid @query-result]
         ^{:key eid}[another-component eid])])))
```

Gotchas:

- **This takes a conn, not a db.**
- At the moment it's only possible to [[connect!]] to one DB at a time, so reactive query results are only supported on one DB. If you pass more DBs as args the query will only be rerun if the first DB changes.
sourceraw docstring

cljdoc is a website building & hosting documentation for Clojure/Script libraries

× close