Skip to content

Commit 1232da0

Browse files
committed
docs: add docs for RealtimeDB
1 parent d0f59a8 commit 1232da0

File tree

5 files changed

+151
-0
lines changed

5 files changed

+151
-0
lines changed

docs/src/components/SideNav.astro

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@
2121
<li><a href="/storage/upload-task">&ltUploadTask&gt</a></li>
2222
<li><a href="/storage/download-url">&ltDownloadURL&gt</a></li>
2323
<li><a href="/storage/storage-list">&ltStorageList&gt</a></li>
24+
<li class="heading">realtime db</li>
25+
<li><a href="/rtdb/node-store">nodeStore</a></li>
26+
<li><a href="/rtdb/node-list-store">nodeListStore</a></li>
27+
<li><a href="/rtdb/node-component">&ltNode&gt</a></li>
28+
<li><a href="/rtdb/node-list-component">&ltNodeList&gt</a></li>
2429
<li class="heading">analytics</li>
2530
<li><a href="/guide/todo">&ltPageView&gt</a></li>
2631
</ul>

docs/src/pages/rtdb/node-component.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
---
2+
title: Node Component
3+
pubDate: 2023-07-23
4+
description: SvelteFire Node Component API reference
5+
layout: ../../layouts/MainLayout.astro
6+
---
7+
8+
# Node
9+
10+
The `Node` component is a wrapper around the `nodeStore`. It renders the node data and handles the loading state.
11+
12+
### Props
13+
14+
- `path` - RealtimeDB path string (e.g. `posts/hi-mom`)
15+
- `startWith` - (optional) initial value to use before the data is fetched
16+
17+
### Slots
18+
19+
- `default` - The node data
20+
- `loading` - Loading state
21+
22+
### Slot Props
23+
24+
- `data` - The node data
25+
- `path` - The Database reference
26+
- `rtdb` - The Database instance
27+
28+
### Example
29+
30+
```svelte
31+
<script>
32+
import { Node } from 'sveltefire';
33+
</script>
34+
35+
<Node path={'posts/id'} let:data>
36+
<p>{data?.title}</p>
37+
38+
<p slot="loading">Loading...</p>
39+
</Node>
40+
```
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
---
2+
title: NodeList Component
3+
pubDate: 2023-07-23
4+
description: SvelteFire NodeList Component API reference
5+
layout: ../../layouts/MainLayout.astro
6+
---
7+
8+
# NodeList
9+
10+
The `NodeList` component is a wrapper around the `nodeListStore`. It renders the node list data and handles the loading state.
11+
12+
### Props
13+
14+
- `path` - RealtimeDB reference
15+
- `startWith` - (optional) initial value to use before the collection is fetched
16+
17+
### Slots
18+
19+
- `default` - The node list data
20+
- `loading` - Loading state
21+
22+
### Slot Props
23+
24+
- `data` - An array of nodes
25+
- `ref` - The Database node reference
26+
- `rtdb` - The Database instance
27+
- `count` - The number of nodes returned by the query
28+
29+
### Example
30+
31+
```svelte
32+
<script>
33+
import { NodeList } from 'sveltefire';
34+
</script>
35+
36+
<NodeList path={'posts'} let:data let:count>
37+
38+
<p>Found {count} posts</p>
39+
40+
{#each data as post}
41+
<p>{post.title}</p>
42+
{/each}
43+
44+
<p slot="loading">Loading...</p>
45+
</NodeList>
46+
```
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
---
2+
title: nodeListStore
3+
pubDate: 2023-11-23
4+
description: SvelteFire nodeStore API reference
5+
layout: ../../layouts/MainLayout.astro
6+
---
7+
8+
# nodeListStore
9+
10+
Subscribes to RealtimeDB node list data and listens to real-time updates.
11+
12+
### Parameters
13+
14+
- `rtdb` - RealtimeDB instance
15+
- `path` - A RealtimeDB path string (e.g. `posts`)
16+
- `startWith` - (optional) initial value to use before the data is fetched
17+
18+
### Example
19+
20+
```svelte
21+
<script>
22+
import { nodeListStore } from 'sveltefire';
23+
import { rtdb } from '$lib/firebase'; // your rtdb instance
24+
25+
const posts = nodeListStore(rtdb, 'posts');
26+
</script>
27+
28+
{#each $posts as post}
29+
<p>{post.title}</p>
30+
{/each}
31+
```

docs/src/pages/rtdb/node-store.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
---
2+
title: nodeStore
3+
pubDate: 2023-11-23
4+
description: SvelteFire nodeStore API reference
5+
layout: ../../layouts/MainLayout.astro
6+
---
7+
8+
# nodeStore
9+
10+
Subscribes to RealtimeDB node and listens to realtime updates.
11+
12+
### Parameters
13+
14+
- `rtdb` - RealtimeDB instance
15+
- `path` - A RealtimeDB path string (e.g. `posts/hi-mom`)
16+
- `startWith` - (optional) initial value to use before the data is fetched
17+
18+
### Example
19+
20+
```svelte
21+
<script>
22+
import { nodeStore } from 'sveltefire';
23+
import { rtdb } from '$lib/rtdb'; // your RealtimeDB instance
24+
25+
const post = nodeStore(rtdb, 'posts/id');
26+
</script>
27+
28+
{$post?.title}
29+
```

0 commit comments

Comments
 (0)