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
@@ -170,7 +185,72 @@ This hook returns the current database client with some helpful functions for sy
170
185
171
186
Check out the [Firebase example](https://homebaseio.github.io/homebase-react/#!/example.todo_firebase) for a demonstration of how you might integrate a backend.
172
187
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.
0 commit comments