You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
- The simplest and most declarative state management solution
27
31
- The power of a backend relational graph database, but without having to wait on the network
@@ -103,7 +107,7 @@ const RootComponent = () => (
103
107
104
108
### `useEntity` and `entity.get`
105
109
106
-
Entities are the building blocks of the Homebase data model. They are like JSON objects with bonus features. In particular **you can traverse arbitrarily deep relationship without actually denormalizing and nesting your data**.
110
+
Entities are the building blocks of the Homebase data model. They are like JSON objects with bonus features. In particular **you can traverse arbitrarily deep relationships without actually denormalizing and nesting your data**.
107
111
108
112
```js
109
113
// You can get an entity by its id and get attributes off of it.
@@ -185,107 +189,6 @@ This hook returns the current database client with some helpful functions for sy
185
189
186
190
Check out the [Firebase example](https://homebaseio.github.io/homebase-react/#!/example.todo_firebase) for a demonstration of how you might integrate a backend.
187
191
188
-
### Arrays & Nested JSON
189
-
190
-
Arrays and arbitrary JSON are partially supported for convenience. However in most cases its better to avoid arrays. Using a query and then sorting by an attribute is simpler and more flexible. This is because arrays add extra overhead to keep track of order.
The `entity.get` API is flexible and supports indexing into arrays as well as automatically mapping over individual attributes.
229
-
230
-
Array items are automatically assigned an `order` and either a `value` or a `ref` depending on if item in the array is an entity or not. To reorder an array item change its `order`.
231
-
232
-
```js
233
-
transact([
234
-
{
235
-
id:company.get('numbers', 2, 'id'),
236
-
order: (company.get('numbers', 0, 'order')
237
-
+company.get('numbers', 1, 'order')) /2
238
-
}
239
-
])
240
-
241
-
company.get('numbers', 'value') // => [1 3 2]
242
-
```
243
-
244
-
If you need to transact complex JSON like arrays of arrays then you're better off serializing it to a string first.
Homebase React tracks the attributes consumed in each component via the `entity.get` function and scopes those attributes to their respective `useEntity` or `useQuery` hook. Re-renders are only triggered when an attribute changes.
258
-
259
-
The default caching reduces unnecessary re-renders and virtual DOM thrashing a lot. That said, it is still possible to trigger more re-renders than you might want.
260
-
261
-
One top level `useQuery` + prop drilling the entities it returns will cause all children to re-render on any change to the parent or their siblings.
262
-
263
-
To fix this we recommend passing ids to children, not whole entities. Instead get the entity in the child with `useEntity(id)`. This creates a new scope for each child so they are not affected by changes in the state of the parent or sibling components.
*The graph database for delightful React state management*
12
+
13
+
14
+
Homebase React makes state management painless by enabling you to plug a relational graph database into your React application with just 3 lines of code. This is the same database that powers Roam Research and many other ClojureScript applications, but with an API that's familiar to React and JS developers.
15
+
16
+
## Install
17
+
18
+
```bash
19
+
# NPM
20
+
npm install homebase-react --save
21
+
22
+
# Yarn
23
+
yarn add homebase-react
24
+
```
25
+
## Features
26
+
- The simplest and most declarative state management solution
27
+
- The power of a backend relational graph database, but without having to wait on the network
28
+
- Convenient JSON query syntax
29
+
- Powerful Clojure style [Datalog](https://docs.datomic.com/on-prem/query.html) query syntax if you need it
30
+
- Traverse your data graph like it's a big JSON object
31
+
- Backup your data to the cloud
32
+
33
+
## Roadmap
34
+
35
+
1. Document integration with more backends
36
+
1. Swap [Datascript](https://github.com/tonsky/datascript) out for [Datahike](https://github.com/replikativ/datahike)
37
+
1. Immutability
38
+
1. History / Change Tracking
39
+
2. Persist to IndexedDB
40
+
3.[Local-first](https://www.inkandswitch.com/local-first.html) conflict resolution for offline caching and sync between multiple devices
0 commit comments