-
Notifications
You must be signed in to change notification settings - Fork 10
Added 0900|Sync_With_Database.md #69
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
docs/0900|Sync_With_Database.md
Outdated
@@ -0,0 +1,106 @@ | |||
## Syncing to Database Recipie with Firebase | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The file name maps to the name of this page on the docs site. I think we should call this page Recipes so please rename the file to 0900|Recipes.md
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed the name to 0900|Recipes.md
!
docs/0900|Sync_With_Database.md
Outdated
@@ -0,0 +1,106 @@ | |||
## Syncing to Database Recipie with Firebase |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should just be Syncing to Firebase
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed to Syncing to Firebase
docs/0900|Sync_With_Database.md
Outdated
@@ -0,0 +1,106 @@ | |||
## Syncing to Database Recipie with Firebase | |||
|
|||
The example below shows a recipe for syncing Homebase with Firebase. To communicate with our backend we use the addTransactListener() method that is part of our useClient() API call. addTransactListener() takes in a function as a parameter. transactListener is the function that looks at all of our Datoms that have changed and updates them in Firebase. We also need a way to sync our backend data with Homebase. transactSilently() allows us to do exactly that and it is also part of the useClient() API call. We have a function called softTransact() which will take in a queue with all the changes that have been made in our database and use transactSilently() to notify Homebase of those changes. Debounced is used here to only improve performance as it allows us to wait for a certain number of changes to accumulate before updating Homebase. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks great! I've just made a few copy edits to trim it down a bit.
The example below shows a recipe for keeping Homebase React in sync with Firebase. client.addTransactListener(callback)
lets you listen to every local transaction and send those updates to Firebase. We also need a way to sync Firebase with Homebase React. In this example we create a namespace on Firebase for each user based on their firebase uid and listen to all changes in that namespace. client.transactSilently(tx)
allows us save changes received from Firebase without triggering our transactListener function and sending those changes back to Firebase endlessly.
Debounced is used here to improve performance as it allows us to batch changes that occur close together.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated Description!
docs/0900|Sync_With_Database.md
Outdated
const userId = currentUser.get('uid') | ||
const transactListener = React.useCallback( | ||
(changedDatoms) => { | ||
const cardinalityManyAttrs = new Set([]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's add a comment with some examples
const cardinalityManyAttrs = new Set([]) // E.g. ':project/todos' or ':user/friends'
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added comment
docs/0900|Sync_With_Database.md
Outdated
const transactListener = React.useCallback( | ||
(changedDatoms) => { | ||
const cardinalityManyAttrs = new Set([]) | ||
const localOnlyAttrs = new Set([]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const localOnlyAttrs = new Set([]) // E.g. ':current-user/uid' these are attributes you don't want to save to Firbase, but also don't want to have to call `client.transactSilently()` everytime you change them.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great! Thanks @mchaudhry05
🎉 This PR is included in version 0.5.3 🎉 The release is available on: Your semantic-release bot 📦🚀 |
PR Description
Created a markdown file that shows an example of how you can sync data from Homebase to Firebase and from Firebase to Homebase.
PR Checklist
Testing
Docs
Typescript
Merging
For maintainers.
To merge, select "Squash and Merge". Then: