Created
July 20, 2018 20:45
-
-
Save kaiobrito/495c9ef69a6528761642761f52d21a0a to your computer and use it in GitHub Desktop.
Firebase + Redux Saga
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
export const actionTypes = { | |
FETCH_USER_REQUEST: "USER/FETCH", | |
FETCH_USER_REQUEST_ERROR: "USER/FETCH_ERROR", | |
USER_CHANGED: "USER/CHANGED", | |
LOGOUT: "LOGOUT", | |
ACCESS_TOKEN_CHANGED: "ACCESS_TOKEN/CHANGED" | |
}; |
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
function* startListener() { | |
// #1 | |
const channel = new eventChannel(emiter => { | |
const listener = database.ref("todos").on("value", snapshot => { | |
emiter({ data: snapshot.val() || {} }); | |
}); | |
// #2 | |
return () => { | |
listener.off(); | |
}; | |
}); | |
// #3 | |
while (true) { | |
const { data } = yield take(channel); | |
// #4 | |
yield put(actionsCreators.updateList(data)); | |
} | |
} | |
export default function* root() { | |
yield fork(startListener); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment