-
Notifications
You must be signed in to change notification settings - Fork 0
Full API
import {
getFirebaseSyncReducer,
getFirebaseSync,
getFirebaseSyncConnect,
getFirebaseSyncSelector,
getFirebaseSyncMapState,
firebaseSyncActions
} from 'firebase-sync';
getFirebaseSyncReducer( initialState = {} )
Creates the reducer and accepts the reducer initial state as argument.
If you are working with Immutable.js you should pass in a Map()
as initial state.
getFirebaseSync( firebase, store )( defaultProps = {} )
Creates the FirebaseSync
component. You must pass in a previously configured firebase app as well as your redux store object. By using your store directly we don't care if you use redux-thunk, redux-saga or anything else as your async actions wrapper.
Finally we accept an optional defaultProps
arg. If you are working with Immutable.js you should use this to pass fromJS
to the onPostProcessItem
function to turn every fetched item into an immutable object before saving then on the redux store.
e.g. getFirebaseSync(firebase, store)({ defaultProps: { onPostProcessItem: fromJS } })
getFirebaseSyncConnect( firebaseSyncReducerName )
Creates the firebaseSyncConnect
utility.
getFirebaseSyncSelector( firebaseSyncReducerName )
Creates the firebaseSyncSelector
utility.
getFirebaseSyncMapState( firebaseSyncReducerName )
Creates the firebaseSyncMapState
utility.
firebaseSyncActions
This holds the redux actions used internally for updating your redux state. You may use this as you see fit.
<FirebaseSync path={`/users/${userId}`} />
prop | type | examples | description |
---|---|---|---|
path | string | users/${userId} |
required. the firebase path to the object that will be synced. |
localPath | string | 'myUser' | the path that the object will be saved in the redux store. if not provided the path prop will be used. this is really useful when watching the same path with different queries. |
fetch | boolean or string | 'soft', true | if fetch is to true the object will only be fetched once and then the listener will be removed. if fetch is set as soft it will only fetch the object if it's not already present in the redux state. |
orderBy | string | .value, .key, .priority, propName | if provided queries will be used on your path. we use the special .value , .key and .priority values to query using the orderByValue , orderByKey and orderByPriority methods. any other value will be used with the orderByChild method. |
startAt | string or number | 10 | |
endAt | string or number | 20 | |
equalTo | string or number | 7 | |
limitToFirst | number | 5 | |
limitToLast | number | 5 | |
ref | firebase ref | if provided, this custom ref will be used instead of the one that we normally generate automatically. | |
onValue | function | (item, prevItem) => {} |
called every time an item is added, changed or removed - is called at least once per FirebaseSync component instance. |
onProcessItem | function | (item) => item |
called before saving the item to the redux state. you can alter the item and then return the item you actually want to save. if nothing is returned the item is removed from the redux state. |
onPostProcessItem | function | (item) => item |
called after the onProcessItem . normally used when using Immutable.js so you can return the result from the fromJS function passing the item as argument. |