Skip to content

Commit

Permalink
docs: add firebase example with persistence adapter
Browse files Browse the repository at this point in the history
resolves #391
  • Loading branch information
maxnowack committed Nov 29, 2023
1 parent 7186ef1 commit a3345a2
Show file tree
Hide file tree
Showing 39 changed files with 2,126 additions and 32 deletions.
9 changes: 6 additions & 3 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,12 @@ module.exports = {
'coverage',
'docs/.vitepress/dist',
'docs/public/todo-example',
'example/.next',
'example/out',
'example/node_modules',
'examples/rxdb/.next',
'examples/rxdb/out',
'examples/rxdb/node_modules',
'examples/firebase/.next',
'examples/firebase/out',
'examples/firebase/node_modules',
],
settings: {
'import/resolver': {
Expand Down
21 changes: 14 additions & 7 deletions .github/workflows/checks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,16 @@ jobs:
with:
path: |
node_modules
example/node_modules
examples/rxdb/node_modules
examples/firebase/node_modules
key: ${{ runner.OS }}-modules-${{ matrix.node-version }}-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.OS }}-modules-${{ matrix.node-version }}-
- name: install modules
run: |
npm install --no-audit --force --loglevel=error --no-update-notifier
cd example && npm install --no-audit --force --loglevel=error --no-update-notifier
(cd examples/rxdb && npm install --no-audit --force --loglevel=error --no-update-notifier)
(cd examples/firebase && npm install --no-audit --force --loglevel=error --no-update-notifier)
linting:
needs: preflight
Expand All @@ -57,7 +59,8 @@ jobs:
fail-on-cache-miss: true
path: |
node_modules
example/node_modules
examples/rxdb/node_modules
examples/firebase/node_modules
key: ${{ runner.OS }}-modules-20.x-${{ hashFiles('**/package-lock.json') }}
- name: linting
run: |
Expand All @@ -80,7 +83,8 @@ jobs:
fail-on-cache-miss: true
path: |
node_modules
example/node_modules
examples/rxdb/node_modules
examples/firebase/node_modules
key: ${{ runner.OS }}-modules-20.x-${{ hashFiles('**/package-lock.json') }}
- name: typecheck
run: |
Expand All @@ -106,7 +110,8 @@ jobs:
fail-on-cache-miss: true
path: |
node_modules
example/node_modules
examples/rxdb/node_modules
examples/firebase/node_modules
key: ${{ runner.OS }}-modules-${{ matrix.node-version }}-${{ hashFiles('**/package-lock.json') }}
- name: unit testing
run: |
Expand Down Expand Up @@ -136,7 +141,8 @@ jobs:
fail-on-cache-miss: true
path: |
node_modules
example/node_modules
examples/rxdb/node_modules
examples/firebase/node_modules
key: ${{ runner.OS }}-modules-${{ matrix.node-version }}-${{ hashFiles('**/package-lock.json') }}
- name: build package
run: |
Expand All @@ -159,7 +165,8 @@ jobs:
fail-on-cache-miss: true
path: |
node_modules
example/node_modules
examples/rxdb/node_modules
examples/firebase/node_modules
key: ${{ runner.OS }}-modules-20.x-${{ hashFiles('**/package-lock.json') }}
- name: build docs
run: |
Expand Down
6 changes: 4 additions & 2 deletions .github/workflows/deploy-docs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,16 @@ jobs:
with:
path: |
node_modules
example/node_modules
examples/rxdb/node_modules
examples/firebase/node_modules
key: ${{ runner.OS }}-modules-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.OS }}-modules-
- name: install modules
run: |
npm install --no-audit --force --loglevel=error --no-update-notifier
cd example && npm install --no-audit --force --loglevel=error --no-update-notifier
(cd examples/rxdb && npm install --no-audit --force --loglevel=error --no-update-notifier)
(cd examples/firebase && npm install --no-audit --force --loglevel=error --no-update-notifier)
- name: Build vitepress
run: npm run docs:build
- name: Upload artifact
Expand Down
21 changes: 18 additions & 3 deletions docs/.vitepress/config.mts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,14 @@ export default defineConfig({
{ text: 'Installation', link: '/installation/' },
],
},
{ text: 'Example', link: 'https://signaldb.js.org/todo-example/' },
{
text: 'Examples',
collapsed: false,
items: [
{ text: 'RxDB', link: 'https://signaldb.js.org/examples/rxdb/' },
{ text: 'Firebase', link: 'https://signaldb.js.org/examples/firebase/' },
],
},
{
text: 'Documentation',
collapsed: false,
Expand Down Expand Up @@ -136,7 +143,14 @@ export default defineConfig({
sitemap({
hostname: 'https://signaldb.js.org',
outDir: './docs/.vitepress/dist',
exclude: ['/googlef8c159020eb311c9', '/404', '/todo-example', '/todo-example/404'],
exclude: [
'/googlef8c159020eb311c9',
'/404',
'/examples/rxdb',
'/examples/rxdb/404',
'/examples/firebase',
'/examples/firebase/404',
],
})

await new Promise((resolve) => { setTimeout(resolve, 1000) }) // wait a second for the sitemap to be generated
Expand Down Expand Up @@ -175,7 +189,8 @@ export default defineConfig({
'/reactivity/solidjs.html': '/reactivity/solidjs/',
'/reactivity/usignal.html': '/reactivity/usignal/',
'/reactivity/vue.html': '/reactivity/vue/',
'/replication/rxdb.html': '/replication/rxdb/',
'/replication/rxdb.html': '/data-persistence/rxdb/',
'/replication/rxdb/index.html': '/data-persistence/rxdb/',
}

Object.entries(redirects).reduce(async (promise, [from, to]) => {
Expand Down
15 changes: 15 additions & 0 deletions docs/data-persistence/firebase/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
head:
- - link
- rel: canonical
href: https://signaldb.js.org/data-persistence/firebase/
---
# Firebase Persistence Adapter

In the realm of modern data-driven applications, maintaining data persistence and consistency is crucial. SignalDB, known for its efficiency as an in-memory database, faces the challenge of data loss during events like page reloads. This is where the integration of persistence adapters becomes vital, particularly for services like Firebase. Firebase, a comprehensive app development platform, offers robust features that can significantly enhance SignalDB's functionality. Implementing a Firebase persistence adapter not only secures data persistence in SignalDB but also enables seamless integration with Firebase's extensive suite of features.

Exploring the role of persistence adapters within SignalDB, their primary function is to act as a bridge between SignalDB and various storage solutions, including Firebase's Firestore, Realtime Database, or cloud storage. These adapters are designed to translate high-level data operations, typical in applications, into the low-level operations compatible with Firebase's storage systems. The integration of a Firebase persistence adapter allows developers to leverage Firebase's advanced capabilities, such as real-time data synchronization, authentication, and cloud storage. This means using the adapter to store data within Firebase's ecosystem, ensuring it is securely managed and easily accessible.

The key advantage of employing a Firebase persistence adapter lies in the flexibility and abstraction it offers. It enables SignalDB to effectively interface with Firebase's powerful storage and synchronization mechanisms, ensuring data continuity, even through application reloads or prolonged user sessions. Furthermore, by decoupling SignalDB from its storage mechanism via the adapter, transitioning to different storage systems or making updates becomes a smoother process, requiring minimal code changes. Essentially, a Firebase persistence adapter serves as a conduit, linking SignalDB's in-memory processes with Firebase's robust, persistent data storage capabilities.

For a practical demonstration, our [Firebase Example](https://github.com/maxnowack/signaldb/tree/main/examples/firebase) showcases a prototype implementation of a persistence adapter for Firebase. While not fully optimized, it's functional. You can find the helper function to create a Firebase persistence adapter for a SignalCollection here: [`createFirebasePersistenceAdapter`](https://github.com/maxnowack/signaldb/blob/main/examples/firebase/src/utils/createFirebasePersistenceAdapter.ts) and its usage [here](https://github.com/maxnowack/signaldb/blob/main/examples/firebase/src/system/setupCollection/persistence.ts).
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
head:
- - link
- rel: canonical
href: https://signaldb.js.org/replication/rxdb/
href: https://signaldb.js.org/data-persistence/rxdb/
---
# RxDB Persistence Adapter

Expand All @@ -12,4 +12,4 @@ Diving deeper into the mechanics of persistence adapters within SignalDB, their

The inherent benefit of using persistence adapters, especially one optimized for RxDB, is the unparalleled flexibility and abstraction they provide. By allowing SignalDB to communicate with RxDB's powerful storage and replication capabilities, developers can ensure data continuity even in scenarios where applications are reloaded or user sessions are extended. In addition, decoupling SignalDB from the storage mechanism through the adapter ensures that changes or migrations to different storage systems can be made with minimal friction or code changes. In essence, an RxDB persistence adapter acts as a bridge between SignalDB's in-memory operations and persistent, replicated data.

In our [example](https://github.com/maxnowack/signaldb/tree/main/example) is a demo implementation of a persistence adapter for RxDB. It's not optimized, but it works. You'll find the helper function to create a persistence adapter for a RxCollection here: [`createRxPersistenceAdapter`](https://github.com/maxnowack/signaldb/blob/main/example/src/utils/createRxPersistenceAdapter.ts) and the usage of this function [here](https://github.com/maxnowack/signaldb/blob/main/example/src/system/setupCollection/persistence.ts).
In our [RxDB Example](https://github.com/maxnowack/signaldb/tree/main/examples/rxdb) is a demo implementation of a persistence adapter for RxDB. It's not optimized, but it works. You'll find the helper function to create a persistence adapter for a RxCollection here: [`createRxPersistenceAdapter`](https://github.com/maxnowack/signaldb/blob/main/examples/rxdb/src/utils/createRxPersistenceAdapter.ts) and the usage of this function [here](https://github.com/maxnowack/signaldb/blob/main/examples/rxdb/src/system/setupCollection/persistence.ts).
2 changes: 2 additions & 0 deletions docs/public/examples/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*
!.gitignore
5 changes: 3 additions & 2 deletions docs/replication/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ head:
---
# Replication

Data replication is a planned feature and not implemented yet. At the moment, data replication can be achieved by using the RxDB persistence adapter and using their replication functionality.
Data replication is a planned feature and not implemented yet. At the moment, data replication can be achieved by using a persistence adapter like RxDB or Firebase and using their replication functionality.

You'll find more information on this here: [RxDB Persistence Adapter](/replication/rxdb/)
* [RxDB Persistence Adapter](/data-persistence/rxdb/)
* [Firebase Persistence Adapter](/data-persistence/firebase/)
40 changes: 40 additions & 0 deletions examples/firebase/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
/.pnp
.pnp.js

# testing
/coverage

# next.js
/.next/
/out/

# production
/build

# misc
.DS_Store
*.pem

# debug
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# local env files
.env*.local

# vercel
.vercel

# typescript
*.tsbuildinfo
next-env.d.ts

*-debug.log
.firebaserc
firebase.json
database.rules.json
File renamed without changes.
13 changes: 13 additions & 0 deletions examples/firebase/next.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/** @type {import('next').NextConfig} */
const nextConfig = {
basePath: '/examples/firebase',
output: 'export',
eslint: {
ignoreDuringBuilds: true,
},
typescript: {
ignoreBuildErrors: true,
},
}

module.exports = nextConfig
Loading

0 comments on commit a3345a2

Please sign in to comment.