A Firebase driver for Cycle.js.
import firebaseConfig from './firebaseConfig';
import { button, div, h2, makeDOMDriver } from '@cycle/dom';
import { firebaseActions, makeFirebaseDriver } from 'cycle-fire';
import { run } from '@cycle/run';
function main(sources) {
const action$ = sources.DOM
.select('.shuffle')
.events('click')
.map(() => Math.ceil(Math.random() * 99))
.map(firebaseActions.database.ref('test').set);
const vdom$ = sources.firebase.database
.ref('test')
.value.map(value => div([h2(value), button('.shuffle', 'Shuffle')]));
return {
DOM: vdom$,
firebase: action$
};
}
run(main, {
DOM: makeDOMDriver('Application'),
firebase: makeFirebaseDriver(firebaseConfig)
});
Write effects to the connected Firebase database are requested by calling an action generator—a function defined on the firebaseActions
object—and passed to the firebase
sink.
firebaseActions: object
containing:auth: object
containing:-
applyActionCode(code: string)
– triggersAuth.applyActionCode
-
checkActionCode(code: string)
– triggersAuth.checkActionCode
-
confirmPasswordReset(code: string, newPassword: string)
– triggersAuth.confirmPasswordReset
-
createUserWithEmailAndPassword(email: string, password: string)
– triggersAuth.createUserWithEmailAndPassword
-
sendPasswordResetEmail(email: string)
– triggersAuth.sendPasswordResetEmail
-
setPersistence(persistence: firebase.auth.Auth.Persistence)
– triggersAuth.setPersistence
-
signInAndRetrieveDataWithCredential(credential: firebase.auth.AuthCredential)
– triggersAuth.signInAndRetrieveDataUsingCredential
-
signInAnonymously()
– triggersAuth.signInAnonymously
-
signInWithCredential(credential: firebase.auth.AuthCredential)
– triggersAuth.signInWithCredential
-
signInWithCustomToken(token: string)
– triggersAuth.signInWithCustomToken
-
signInWithEmailAndPassword(email: string, password: string)
– triggersAuth.signInWithEmailAndPassword
-
signInWithPhoneNumber(phoneNumber: string, verifier: firebase.auth.ApplicationVerifier)
– triggersAuth.signInWithPhoneNumber
-
signInWithPopup(provider: firebase.auth.AuthProvider)
– triggersAuth.signInWithPopup
-
signInWithRedirect(provider: firebase.auth.AuthProvider)
– triggersAuth.signInWithRedirect
-
signOut()
– triggersAuth.signOut
user(user: firebase.User): object
containing:unlink()
– triggersUser.unlink
updateEmail(email: string)
– triggersUser.updateEmail
updatePassword(password: string)
– triggersUser.updatePassword
updatePhoneNumber(phoneNumber: string)
– triggersUser.updatePhoneNumber
updateProfile(profile: { displayName: (null|string), photoURL: (null|string) })
– triggersUser.updateProfile
-
verifyPasswordResetCode(code: string)
– triggersAuth.verifyPasswordResetCode
-
database: object
containing:-
goOffline()
– triggersDatabase.goOffline
-
goOnline()
– triggersDatabase.goOnline
ref(path: string) => object
containing:-
push(value: any)
– triggersReference.push
-
remove()
– triggersReference.remove
-
set(value: any)
– triggersReference.set
-
setPriority(priority: (null|number|string))
– triggersReference.setPriority
-
setWithPriority(value: any, priority: (null|number|string))
– triggersReference.setWithPriority
-
transaction(updateFn: (value: any) => any)
– triggersReference.transaction
-
update(values: any)
– triggersReference.update
-
-
Effectively attaches a category
to the action's result stream, allowing for lookup using the source's select()
.
import { firebaseActions } from 'cycle-fire';
import xs from 'xstream';
function Cycle(sources) {
const setAction = firebaseActions.database
.ref('test')
.set('newValue')
.as('setTestValue');
sources.firebase.select('setTestValue').addListener({
error: err => {
console.error(err);
},
next: response => {
console.log(response);
}
});
return {
firebase: xs.of(setAction)
};
}
config: object
apiKey: string
authDomain: string
databaseURL: string
messagingSenderId: string
projectId: string
storageBucket: string
name?: string
Initializes a connection to a Firebase database by calling firebase.initializeApp()
, returning a source object containing the following:
auth: object
containing:-
authState: MemoryStream
emitting values fromAuth.onAuthStateChanged
-
currentUser: MemoryStream
emitting changed values ofAuth.currentUser
when triggered byAuth.onIdTokenChanged
-
idToken: MemoryStream
emitting values fromAuth.onIdTokenChanged
-
providersForEmail(email: string): MemoryStream
emitting values fromAuth.fetchProvidersForEmail
-
redirectResult: MemoryStream
emitting values fromAuth.getRedirectResult
-
database: object
containing:-
ref(path: string): ReferenceSource
containing:-
child(path: string): ReferenceSource
-
events(eventType: string): MemoryStream
of theref
'seventType
events, usingReference.on
-
value: MemoryStream
– a shortcut stream equivalent toevents('value')
-
-
refFromURL(url: string): ReferenceSource
-
-
select(category: string): Stream
of results from action requests that were categorized using<action>.as()
.