Last active
June 5, 2017 06:01
-
-
Save erezrokah/6c9c4efda42ef760fc8ed77dd889d2f7 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
//@flow | |
import firebase from '../firebase' | |
export function messagesRequested() { | |
return { | |
type: 'MESSAGES_REQUESTED' | |
} | |
} | |
export function messagesFulfilled(items: Object) { | |
return { | |
type: 'MESSAGES_FULFILLED', | |
items, | |
} | |
} | |
type Action = { | |
type: string, | |
items?: Object | |
} | |
export function listenToMessages() { | |
return (dispatch: (Action => void)) => { | |
dispatch(messagesRequested()) | |
firebase.database().ref('messages') | |
.on('value', (snap) => { | |
dispatch(messagesFulfilled(snap.val())) | |
}) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment