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: objectcontaining:auth: objectcontaining:-
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): objectcontaining:unlink()– triggersUser.unlinkupdateEmail(email: string)– triggersUser.updateEmailupdatePassword(password: string)– triggersUser.updatePasswordupdatePhoneNumber(phoneNumber: string)– triggersUser.updatePhoneNumberupdateProfile(profile: { displayName: (null|string), photoURL: (null|string) })– triggersUser.updateProfile
-
verifyPasswordResetCode(code: string)– triggersAuth.verifyPasswordResetCode
-
database: objectcontaining:-
goOffline()– triggersDatabase.goOffline -
goOnline()– triggersDatabase.goOnline ref(path: string) => objectcontaining:-
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: objectapiKey: stringauthDomain: stringdatabaseURL: stringmessagingSenderId: stringprojectId: stringstorageBucket: string
name?: string
Initializes a connection to a Firebase database by calling firebase.initializeApp(), returning a source object containing the following:
auth: objectcontaining:-
authState: MemoryStreamemitting values fromAuth.onAuthStateChanged -
currentUser: MemoryStreamemitting changed values ofAuth.currentUserwhen triggered byAuth.onIdTokenChanged -
idToken: MemoryStreamemitting values fromAuth.onIdTokenChanged -
providersForEmail(email: string): MemoryStreamemitting values fromAuth.fetchProvidersForEmail -
redirectResult: MemoryStreamemitting values fromAuth.getRedirectResult
-
database: objectcontaining:-
ref(path: string): ReferenceSourcecontaining:-
child(path: string): ReferenceSource -
events(eventType: string): MemoryStreamof theref'seventTypeevents, usingReference.on -
value: MemoryStream– a shortcut stream equivalent toevents('value')
-
-
refFromURL(url: string): ReferenceSource
-
-
select(category: string): Streamof results from action requests that were categorized using<action>.as().