All Projects → Canner → Redux Firebase Middleware

Canner / Redux Firebase Middleware

🔌 🔥 Redux firebase middleware for React and React-native

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Redux Firebase Middleware

Redux Catch
Error catcher middleware for Redux reducers and sync middlewares
Stars: ✭ 150 (+782.35%)
Mutual labels:  middleware, redux-middleware
ReSwiftMonitor
ReSwift+redeux dev tools
Stars: ✭ 13 (-23.53%)
Mutual labels:  middleware, redux-middleware
Redux Firestore
Redux bindings for Firestore
Stars: ✭ 530 (+3017.65%)
Mutual labels:  redux-middleware, firebase
Laravel Caffeine
Keeping Your Laravel Forms Awake.
Stars: ✭ 723 (+4152.94%)
Mutual labels:  middleware
React Native Firestack
A firestack v3 react-native implementation
Stars: ✭ 726 (+4170.59%)
Mutual labels:  firebase
Supabase
The open source Firebase alternative. Follow to stay updated about our public Beta.
Stars: ✭ 25,142 (+147794.12%)
Mutual labels:  firebase
Thenetwork Open
TheNetwork is a blog cum chat app. It's completely built using firebase. Users can post, comment, like and bookmark the blogs, also users can send follow requests to connect with people. Users can create events and also prepare an event roadmap. Pagination for realtime data is also included in chats, blogs and events.
Stars: ✭ 17 (+0%)
Mutual labels:  firebase
Slim Jwt Auth
PSR-7 and PSR-15 JWT Authentication Middleware
Stars: ✭ 713 (+4094.12%)
Mutual labels:  middleware
Csrf
Package csrf is a middleware that generates and validates CSRF tokens for Macaron.
Stars: ✭ 6 (-64.71%)
Mutual labels:  middleware
Learning laravel kernel
Laravel核心代码学习
Stars: ✭ 789 (+4541.18%)
Mutual labels:  middleware
Wild Workouts Go Ddd Example
Complete application to show how to apply DDD, Clean Architecture, and CQRS by practical refactoring of a Go project.
Stars: ✭ 756 (+4347.06%)
Mutual labels:  firebase
Ocelot
.NET core API Gateway
Stars: ✭ 6,675 (+39164.71%)
Mutual labels:  middleware
Angularfire
The official Angular library for Firebase.
Stars: ✭ 7,029 (+41247.06%)
Mutual labels:  firebase
React Router Firebase Auth
Example of how to have protected routes with Firebase and React Router.
Stars: ✭ 725 (+4164.71%)
Mutual labels:  firebase
Tango
This is only a mirror and Moved to https://gitea.com/lunny/tango
Stars: ✭ 837 (+4823.53%)
Mutual labels:  middleware
Packtpub Crawler
Download your daily free Packt Publishing eBook https://www.packtpub.com/packt/offers/free-learning
Stars: ✭ 717 (+4117.65%)
Mutual labels:  firebase
Omniauth Pge
OmniAuth Strategy for PG&E
Stars: ✭ 6 (-64.71%)
Mutual labels:  middleware
Redux Cycles
Bring functional reactive programming to Redux using Cycle.js
Stars: ✭ 755 (+4341.18%)
Mutual labels:  middleware
Zend Expressive
PSR-15 middleware in minutes!
Stars: ✭ 740 (+4252.94%)
Mutual labels:  middleware
Chat Sdk Ios
Chat SDK iOS - Open Source Mobile Messenger
Stars: ✭ 813 (+4682.35%)
Mutual labels:  firebase

redux-firebase-middleware NPM version Build Status Dependency Status

Redux middleware for firebase, support native web API or react-native-firebase API.

NOTE: Only support for Firebase realtime database at this moment, welcome PRs for supporting Firestore

Why?

Firebase SDK is hard to achieve strict unidirectional data flow in Redux. If you have a hard time manage your Redux states from Firebase realtime database to your Redux store. This middleware help you seamlessly integrate Firebase with Redux workflow.

Installation

$ npm install --save redux-firebase-middleware

Usage

Store

Setting up in your redux store

Web
/** firebase web api **/
const {applyMiddleware, createStore, compose} = require('redux');
const {firMiddleware} = require('redux-firebase-middleware');

const config = {
  apiKey: 'xxxxxxxxxxx',
  authDomain: 'xxxxxxxxxxx',
  databaseURL: 'xxxxxxxxxxx',
  projectId: 'xxxxxxxxxxx',
  storageBucket: 'xxxxxxxxxxx',
  messagingSenderId: 'xxxxxxxxxxx',
};

firebase.initializeApp(config);

const finalCreateStore = compose(
  applyMiddleware(thunk),
  applyMiddleware(firMiddleware(firebase)) // -----> apply fir middleware in redux store
)(createStore);

React-native
/** react-native-firebase native api **/
import RNFirebase from 'react-native-firebase';

const configOpts = {
  debug: true,
  persistence: true,
};

RNFirebase.initializeApp(configOpts);

const finalCreateStore = compose(
  applyMiddleware(thunk),
  applyMiddleware(firMiddleware(RNFirebase)) // -----> apply fir middleware in redux store
)(createStore);

.....

Basic operations (Read, and write data)

dispatching a firMiddleware action.

const {CALL_FIR_API} = require('redux-firebase-middleware');

export const GET_MY_REF = [
  'GET_MY_REF_REQUEST', // -------> first, must be request type
  'GET_MY_REF_SUCCESS', // -------> second, must be success type
  'GET_MY_REF_FAILURE', // -------> third, must be failure type
];

function callAnAction() {
  return dispatch({[CALL_FIR_API]: {
    types: GET_MY_REF, // -----> normally this should put in constants, see `constants`(next seciton) for more info
    ref: (db) => db.ref('test/path1'), // ----> your firebase reference path
    method: 'once_value',
  }});
}

Reducers

export default function reducer(state: calcState = initialState, action: FSA) {
  const {type, payload} = action;

  switch (type) {
    case 'GET_MY_REF_REQUEST':
      // update request state

    case 'GET_MY_REF_SUCCESS':
      // update success state
      // you can get data from payload.

    case 'GET_MY_REF_FAILURE':
      // update failure state
  }
}

Listener events (Reading and writing lists)

dispatching a firMiddleware listener actions.

  • types (Array<request, success, failure>) : action constants types
  • ref ((firebase.database) => firebase.database.Reference | firebase.database.Query): Instance of firebase reference or firebase query
  • method: could be one of, please reference to: https://firebase.google.com/docs/reference/js/firebase.database.Reference#on
    • on_value
    • on_child_added
    • on_child_changed
    • on_child_removed
    • on_child_moved
const {CALL_FIR_API} = require('redux-firebase-middleware');

export const GET_MY_REF = [
  'GET_MY_REF_REQUEST', // -------> first, must be request type
  'GET_MY_REF_SUCCESS', // -------> second, must be success type
  'GET_MY_REF_FAILURE', // -------> third, must be failure type
];

function callAnAction() {
  return dispatch({[CALL_FIR_API]: {
    types: GET_MY_REF, // -----> normally this should put in constants, see `constants`(next seciton) for more info
    ref: (db) => db.ref('test/path1'), // ----> your firebase reference path
    method: 'on_value',
  }});
}

To remove the listener, you'll get off method in actions' reducer.

Reducers

When the state is successful it'll received data as payload, payload's value is slightly different in different methods.

Payload in methods:

  • on_value: dataSnapshot
  • on_child_added: {childSnapshot, prevChildKey}
  • on_child_changed: {childSnapshot, prevChildKey}
  • on_child_removed: oldChildSnapshot
  • on_child_moved: {childSnapshot, prevChildKey}
export default function reducer(state: calcState = initialState, action: FSA) {
  // or if you're using event listeners you'll get additional `off` method to remove the listening event by calling `off()` 
  const {type, payload, off} = action

  switch (type) {
    case 'GET_MY_REF_REQUEST':
      // update request state

    case 'GET_MY_REF_SUCCESS':
      // update success state
      // you can get data from payload.

    case 'GET_MY_REF_FAILURE':
      // update failure state

    case 'REMOVE_LISTENER':
      // call off method to unlisten the event
      off();
  }
}

Customized payload

export const GET_CALC_CAR_CATEGORY = [
  'GET_MY_REF_REQUEST', // -------> first, must be request type
  {
    type: 'GET_MY_REF_SUCCESS', // ------> second, must be success type
    payload: (action: FirAPI, state: GetState, data: any) => {
      // you can do what ever you want, transforming data or manipulating data .... etc
      // get firebase data called `data.val()`
      return data.val();
    },
  },
  'GET_MY_REF_FAILURE', // -------> third, must be failure type
];

Credits

Inspired by redux-api-middleware

https://github.com/agraboso/redux-api-middleware

License

MIT © chilijung

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].