Liking cljdoc? Tell your friends :D

homebase.cache

A homebase cache intermediates between a view layer like React or Reagent and a data layer like Datascript or Datahike.

It ensures that as data changes the view is incremently updated to reflect the most recent state while maintaining consistency/transactionality, performing all updates for a transaction simultaneously.

The cache takes the form of a map where components (identified by site-ids) can subscribe to updates of specific data by associng change-handlers into the cache.

E.g.

{:ea
{["EntityId" :attribute]
 {"uuid-for-a-component-or-'hook'" ; multiple components may subscribe to changes in the same datom so each gets their own change-handler
  (fn on-entity-attr-change-handler-fn
    [{:db-after ; the db value that corresponds with this update. Should be used by the consuming component to update the view so it stays in sync because all change-handlers use the same DB snapshot for the same TX.
      :datom ; the updated datom
      :site-id "uuid-for-a-component-or-'hook'"}]
  ; INSERT code to update the view in this component with the newest state of this datom
    )}}
:q
{['[:find ?e ?a ?v
    :where [?e ?a ?v]]
  other-inputs]
 {"uuid-for-a-component-or-'hook'" ; multiple components may subscribe to changes in the same query so each gets their own change-handler
  (fn on-query-change-handler-fn
    [{:db-after ; the db value that corresponds with this update. Should be used by the consuming component to update the view so it stays in sync because all change-handlers use the same DB snapshot for the same TX.
      :site-id "uuid-for-a-component-or-'hook'"}]
  ; INSERT code to update the view with the latest results of the query
    )}}}

The cache takes care of appropriately invoking change-handlers after every transaction.

A homebase cache intermediates between a view layer like React or Reagent and a data layer like Datascript or Datahike.

It ensures that as data changes the view is incremently updated to reflect the most recent state while maintaining consistency/transactionality, performing all updates for a transaction simultaneously.

The cache takes the form of a map where components (identified by site-ids) can subscribe to updates of specific data by associng change-handlers into the cache.

E.g.

```clojure
{:ea
{["EntityId" :attribute]
 {"uuid-for-a-component-or-'hook'" ; multiple components may subscribe to changes in the same datom so each gets their own change-handler
  (fn on-entity-attr-change-handler-fn
    [{:db-after ; the db value that corresponds with this update. Should be used by the consuming component to update the view so it stays in sync because all change-handlers use the same DB snapshot for the same TX.
      :datom ; the updated datom
      :site-id "uuid-for-a-component-or-'hook'"}]
  ; INSERT code to update the view in this component with the newest state of this datom
    )}}
:q
{['[:find ?e ?a ?v
    :where [?e ?a ?v]]
  other-inputs]
 {"uuid-for-a-component-or-'hook'" ; multiple components may subscribe to changes in the same query so each gets their own change-handler
  (fn on-query-change-handler-fn
    [{:db-after ; the db value that corresponds with this update. Should be used by the consuming component to update the view so it stays in sync because all change-handlers use the same DB snapshot for the same TX.
      :site-id "uuid-for-a-component-or-'hook'"}]
  ; INSERT code to update the view with the latest results of the query
    )}}}
```

The cache takes care of appropriately invoking change-handlers after every transaction.
raw docstring

assoccljs

(assoc cache cache-type lookup site-id change-handler)

Helper to assoc a change-handler into the cache.

Usage:

; assoc to the Entity cache
(homebase.cache/assoc cache :ea [1 :attr] "a uid for the call site" (fn change-handler [...] ...))

; assoc to the Query cache
(homebase.cache/assoc cache :q '[:find ... :where ...] "a uid for the call site" (fn change-handler [...] ...))
Helper to assoc a change-handler into the cache.

Usage:
```clojure
; assoc to the Entity cache
(homebase.cache/assoc cache :ea [1 :attr] "a uid for the call site" (fn change-handler [...] ...))

; assoc to the Query cache
(homebase.cache/assoc cache :q '[:find ... :where ...] "a uid for the call site" (fn change-handler [...] ...))
```
sourceraw docstring

connect!cljsmultimethod

Connect the cache to a database connection and listen to changes in the transaction log.

Connect the cache to a database connection and listen to changes in the transaction log.
sourceraw docstring

create-conncljs

(create-conn)

Returns a homebase.cache in an atom.

Returns a homebase.cache in an atom.
sourceraw docstring

create-listenercljs

(create-listener cache-conn)

Returns a db listener function that invokes all subscribed change-handlers in the cache when a datom is transacted.

Entity Attribute cache updates are mostly complete and dispatch on the smallest possible set of change-handlers.

Query cache updates are NOT complete and all of them dispatch on every transaction regardless of whether the transaction can be infered to change the results of a query or not. This is tends to be fine for datasets with thousands of datoms, but could be expensive for applications with lots of datoms and lots of complex queries. Improvements via differential datalog need to be investigated.

Returns a db listener function that invokes all subscribed change-handlers in the cache when a datom is transacted.

Entity Attribute cache updates are mostly complete and dispatch on the smallest possible set of change-handlers.

Query cache updates are NOT complete and all of them dispatch on every transaction regardless of whether the transaction can be infered to change the results of a query or not. This is tends to be fine for datasets with thousands of datoms, but could be expensive for applications with lots of datoms and lots of complex queries. Improvements via differential datalog need to be investigated.
sourceraw docstring

db-conn-typecljs

(db-conn-type db-conn)
source

disconnect!cljsmultimethod

Disconnect the transaction log listener.

Disconnect the transaction log listener.
sourceraw docstring

dissoccljs

(dissoc cache cache-type lookup site-id)
source

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

× close