0.1.16 • Published 7 years ago

firebase-sagas v0.1.16

Weekly downloads
3
License
MIT
Repository
github
Last release
7 years ago

NPM version NPM downloads

firebase-sagas

A redux-saga integration for firebase (auth, database):

  • Authentication and realtime database support
  • Listen for value and child events (value, child_added, child_removed, child_changed, child_moved)
  • Snapshots as array support
  • Sorting and filtering data ( orderByChild, orderByKey, orderByValue, orderByPriority, limitToLast, limitToFirst, startAt, endAt, equalTo)

Try out the example app

Install

npm install firebase-sagas --save

Getting started

import createFirebaseSagas from 'firebase-sagas';

const config = {
  apiKey: 'YOUR_API_KEY',
  authDomain: 'YOUR_AUTH_DOMAIN',
  databaseURL: 'YOUR_DATABASE_URL',
  projectId: 'YOUR_PROJECT_ID',
  storageBucket: 'YOUR_STORAGE_BUCKET',
  messagingSenderId: 'YOUR_MESSAGING_SENDER_ID'
};

const firebaseSagas = createFirebaseSagas(config);

...

function* fetchDataSaga(action) {
  try {
    const { query } = action.payload;
    const data = yield call(firebaseSagas.database.once, '/data', 'value', { query, asArray: true });
    yield put(fetchDataSuccess(data));
  }
  catch(error) {
    yield put(fetchDataFailure(error));
  }
}

...

API

Modules

Classes

Functions

constants

Constants.

auth

A module for firebaseSagas.auth

auth~createUserWithEmailAndPassword(email, password) ⇒ firebase.User

Creates a new user account associated with the specified email address and password.

Kind: inner method of auth
Returns: firebase.User - user

ParamType
emailstring
passwordstring

auth~signInWithEmailAndPassword(email, password) ⇒ firebase.User

Signs in using an email and password.

Kind: inner method of auth
Returns: firebase.User - user

ParamType
emailstring
passwordstring

auth~signInAnonymously() ⇒ firebase.User

Signs in as an anonymous user.

Kind: inner method of auth
Returns: firebase.User - user

auth~signInWithCustomToken(token) ⇒ firebase.User

Signs in using a custom token.

Kind: inner method of auth
Returns: firebase.User - user

ParamTypeDescription
tokenstringThe custom token to sign in with.

auth~signInWithGoogle(scopes, customParameters) ⇒ firebase.User

Signs in using GoogleAuthProvider.

Kind: inner method of auth
Returns: firebase.User - user

ParamTypeDescription
scopesarrayGoogle OAuth scopes
customParametersobjectThe custom OAuth parameters to pass in the OAuth request

auth~signInWithFacebook(scopes, customParameters) ⇒ firebase.User

Signs in using FacebookAuthProvider.

Kind: inner method of auth
Returns: firebase.User - user

ParamTypeDescription
scopesarrayFacebook OAuth scopes
customParametersobjectThe custom OAuth parameters to pass in the OAuth request

auth~signInWithTwitter(scopes, customParameters) ⇒ firebase.User

Signs in using TwitterAuthProvider.

Kind: inner method of auth
Returns: firebase.User - user

ParamTypeDescription
scopesarrayTwitter OAuth scopes
customParametersobjectThe custom OAuth parameters to pass in the OAuth request

auth~signInWithGithub(scopes, customParameters) ⇒ firebase.User

Signs in using GithubAuthProvider.

Kind: inner method of auth
Returns: firebase.User - user

ParamTypeDescription
scopesarrayGithub OAuth scopes
customParametersobjectThe custom OAuth parameters to pass in the OAuth request

auth~signOut()

Signs out the current user.

Kind: inner method of auth

auth~syncUser(actionCreator)

Kind: inner method of auth

ParamType
actionCreatorfunction

auth~createOnAuthStateChangedChannel() ⇒ eventChannel

Creates channel that will subscribe to changes to the user's sign-in state.

Kind: inner method of auth
Returns: eventChannel - onAuthStateChangedChannel

auth~currentUser() ⇒ firebase.User

Returns the currently signed-in user (or null).

Kind: inner method of auth
Returns: firebase.User - user

database

A module for firebaseSagas.database

database~once(path, eventType, options) ⇒ * | any

Retrieve data from database just once without subscribing or listening for data changes.

Kind: inner method of database

ParamType
pathstring
eventTypestring
optionsobject

database~push(path, value) ⇒ * | any

Generates a new child location using a unique key and returns its Reference

Kind: inner method of database

ParamType
pathstring
value

database~update(path, values)

Writes multiple values to the Database at once.

Kind: inner method of database

ParamType
pathstring
values

database~set(path, value)

Writes data to this Database location.

Kind: inner method of database

ParamType
pathstring
value

database~remove(path)

Removes the data at this Database location.

Kind: inner method of database

ParamType
pathstring

database~on(path, eventType, actionCreator, options)

Kind: inner method of database

ParamType
pathstring
eventTypestring
actionCreatorfunction
optionsobject

database~createOnEventChannel(path, eventType) ⇒ eventChannel

Kind: inner method of database
Returns: eventChannel - onEventChannel

ParamType
pathstring
eventTypestring

FirebaseSagas

FirebaseSagas

Kind: global class

firebaseSagas.database

See module database

Kind: instance property of FirebaseSagas
See: database

firebaseSagas.auth

See module auth

Kind: instance property of FirebaseSagas
See: auth

Query

Query

Kind: global class

query.equalTo(value, key)

Creates a Query that includes children that match the specified value.

Kind: instance method of Query

ParamTypeDescription
valueThe value to match for. The argument type depends on which orderBy() function was used in this query. Specify a value that matches the orderBy() type. When used in combination with orderByKey(), the value must be a string.
keyoptionalThe child key to start at, among the children with the previously specified priority. This argument is only allowed if ordering by child, value, or priority.

query.startAt(value, key)

Creates a Query with the specified starting point.

Kind: instance method of Query

ParamTypeDescription
valueThe value to start at. The argument type depends on which orderBy() function was used in this query. Specify a value that matches the orderBy() type. When used in combination with orderByKey(), the value must be a string.
keyoptionalThe child key to start at. This argument is only allowed if ordering by child, value, or priority.

query.endAt(value, key)

Creates a Query with the specified ending point.

Kind: instance method of Query

ParamTypeDescription
valueThe value to end at. The argument type depends on which orderBy() function was used in this query. Specify a value that matches the orderBy() type. When used in combination with orderByKey(), the value must be a string.
keyoptional

query.limitToLast(limit)

Generates a new Query object limited to the last specific number of children.

Kind: instance method of Query

ParamDescription
limitThe maximum number of nodes to include in this query.

query.limitToFirst(limit)

Generates a new Query limited to the first specific number of children.

Kind: instance method of Query

ParamDescription
limitThe maximum number of nodes to include in this query.

query.orderByValue()

Generates a new Query object ordered by value.

Kind: instance method of Query

query.orderByPriority()

Generates a new Query object ordered by priority.

Kind: instance method of Query

query.orderByChild(path)

Generates a new Query object ordered by the specified child key.

Kind: instance method of Query

Param
path

query.orderByKey()

Generates a new Query object ordered by key.

Kind: instance method of Query

query.reset()

Resets the query

Kind: instance method of Query

query.toJSON()

Return the query as JSON-String

Kind: instance method of Query

createAuthSaga(FirebaseSagas, options) ⇒ generator

Creates a AuthSaga

Kind: global function
Returns: generator - authSaga

ParamType
FirebaseSagasFirebaseSagas
optionsobject

Example

import { createAuthSaga } from 'firebase-sagas';

...

const authSaga = createAuthSaga(firebaseSagas, {
 signInMethods: [
   { type: 'signInWithEmailAndPassword' },
   { type: 'signInWithGoogle' },
  ],
 onSignInSuccess: function* onSignInSuccess() {
   yield put(push('/Todo'));
 },
 onSignOutSuccess: function* onSignOutSuccess() {
   yield put(push('/'));
 },
});

createFirebaseSagas(config) ⇒ FirebaseSagas

Creates a FirebaseSagas-Instance

Kind: global function
Returns: FirebaseSagas - firebaseSagas

ParamTypeDescription
configobjectFireBase config

Example

import createFirebaseSagas from 'firebase-sagas':

const config = {
  apiKey: 'YOUR_API_KEY',
  authDomain: 'YOUR_AUTH_DOMAIN',
  databaseURL: 'YOUR_DATABASE_URL',
  projectId: 'YOUR_PROJECT_ID',
  storageBucket: 'YOUR_STORAGE_BUCKET',
  messagingSenderId: 'YOUR_MESSAGING_SENDER_ID'
};

const firebaseSagas = createFirebaseSagas(config);

createQuery() ⇒ Query

Creates a new Query

Kind: global function
Returns: Query - query
Example

import { createQuery } from 'firebase-sagas';

const query = createQuery().startAt(10).endAt(15).orderByValue();

License

MIT

0.1.16

7 years ago

0.1.15

7 years ago

0.1.14

7 years ago

0.1.13

7 years ago

0.1.12

7 years ago

0.1.11

7 years ago

0.1.10

7 years ago

0.1.9

7 years ago

0.1.8

7 years ago

0.1.7

7 years ago

0.1.6

7 years ago

0.1.5

7 years ago

0.1.4

7 years ago

0.1.3

7 years ago

0.1.2

7 years ago

0.1.1

7 years ago

0.1.0

7 years ago

0.0.19

7 years ago

0.0.18

7 years ago

0.0.17

7 years ago

0.0.16

7 years ago

0.0.15

7 years ago

0.0.14

7 years ago

0.0.13

7 years ago

0.0.12

7 years ago

0.0.11

7 years ago

0.0.10

7 years ago

0.0.9

7 years ago

0.0.8

7 years ago

0.0.7

7 years ago

0.0.5

7 years ago

0.0.4

7 years ago

0.0.3

7 years ago

0.0.2

7 years ago

0.0.1

7 years ago