Last active
March 23, 2017 09:21
-
-
Save aakashns/94a937db38c1e58b547b44efe652454d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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