-
-
Notifications
You must be signed in to change notification settings - Fork 553
feat(core): non-HOC version of firebaseConnect, for use with server side rendering #299
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,6 @@ | ||
| import { isObject } from 'lodash' | ||
| import { authActions, queryActions, storageActions } from './actions' | ||
| import { getEventsFromInput, createCallable } from './utils' | ||
|
|
||
| /** | ||
| * Create a firebase instance that has helpers attached for dispatching actions | ||
|
|
@@ -239,6 +240,27 @@ export const createFirebaseInstance = (firebase, configs, dispatch) => { | |
| const deleteFile = (path, dbPath) => | ||
| storageActions.deleteFile(dispatch, firebase, { path, dbPath }) | ||
|
|
||
| /** | ||
| * @description Connect. Similar to the firebaseConnect Higher Order | ||
| * Component but presented as a function. Useful for populating your redux | ||
| * state without React, e.g., for service side rendering. | ||
| * @param {Array} watchArray - Array of objects or strings for paths to sync | ||
| * from Firebase. Can also be a function that returns the array. The function | ||
| * is passed the props object specified as the next parameter. | ||
| * @param {Object} props - The props object that you would like to pass to | ||
| * your watchArray generating function. | ||
| * @return {Promise} | ||
| */ | ||
| const connect = (watchArray, props) => { | ||
| const inputAsFunc = createCallable(watchArray) | ||
| const prevData = inputAsFunc(props, firebase) | ||
| const firebaseEvents = getEventsFromInput(prevData) | ||
| const promises = firebaseEvents.map(event => | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Kinda a nitpick: We should be able to use Only reason I care is that I followed the same pattern when building the new
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's what I had initially but watchEvents doesn't return a promise, which is important for SSR as you have to wait for the data to be fetched before rendering. I could update watchEvents if you want. |
||
| queryActions.watchEvent(firebase, dispatch, event)) | ||
|
|
||
| return Promise.all(promises) | ||
| } | ||
|
|
||
| /** | ||
| * @description Watch event. **Note:** this method is used internally | ||
| * so examples have not yet been created, and it may not work as expected. | ||
|
|
@@ -407,7 +429,8 @@ export const createFirebaseInstance = (firebase, configs, dispatch) => { | |
| watchEvent, | ||
| unWatchEvent, | ||
| reloadAuth, | ||
| linkWithCredential | ||
| linkWithCredential, | ||
| connect | ||
|
||
| } | ||
|
|
||
| return Object.assign(firebase, helpers, { helpers }) | ||
|
|
||
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.
Great work with the comments here.