Skip to content

Instantly share code, notes, and snippets.

@natac13
Created January 31, 2016 21:31
Show Gist options
  • Save natac13/53b218308dafeaee35ba to your computer and use it in GitHub Desktop.
Save natac13/53b218308dafeaee35ba to your computer and use it in GitHub Desktop.
Start of my middleware to Firebase and Redux
import Firebase from 'firebase';
import Fireproof from 'fireproof';
const fireRef = new Firebase('https://vegan-recipes.firebaseio.com/');
const fp = new Fireproof(fireRef);
const list = fp.child('recipeList');
const firebaseMiddleware = store => next => {
let firebaseRecipeList = {};
list.then(snap => {
firebaseRecipeList = snap.val();
console.log('inside fb middleware recipeList ->');
console.log(firebaseRecipeList);
});
return action => {
/*
When I call the buildList action from RecipeList.js the middleware will
intercept and create the actions signature that I first had.
*/
if (action.type === 'BUILD_LIST') {
const x = {
type: 'BUILD_LIST',
recipeList: firebaseRecipeList
};
return next(x);
}
console.log('store state before');
console.log(action);
console.log(store.getState());
const nextState = next(action);
console.log('store state after');
console.log(store.getState());
return nextState;
};
};
export default firebaseMiddleware;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment