Skip to content

Instantly share code, notes, and snippets.

@aakashns
Last active March 23, 2017 09:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aakashns/94a937db38c1e58b547b44efe652454d to your computer and use it in GitHub Desktop.
Save aakashns/94a937db38c1e58b547b44efe652454d to your computer and use it in GitHub Desktop.
let mustWrite = true; // Should we write the database?
const fromDb = (db, dispatch) => {
const listener = db.ref('/message').on('value', snap => {
if (snap.val()) {
mustWrite = false; // Don't write the next dispatch
dispatch({ type: 'SET_MESSAGE', payload: data.val()});
mustWrite = true; // Done! Start writing again
}
});
const unsubscribe = () => db.ref('/message');
return unsubscribe;
}
const fromStore = (state, db) => {
if (mustWrite) {
db.ref('/message').set(state.message);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment