Created
November 17, 2018 10:20
-
-
Save productioncoder/f254711b4f0d336670e9aa49c2f12b1f to your computer and use it in GitHub Desktop.
Youtube in React: comment thread watcher and worker 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
import {fork, take} from 'redux-saga/effects'; | |
import {REQUEST} from '../actions'; | |
import * as commentActions from '../actions/comment' | |
import * as api from '../api/youtube-api'; | |
import {fetchEntity} from './index'; | |
export function* fetchCommentThread(videoId, nextPageToken) { | |
const request = api.buildCommentThreadRequest.bind(null, videoId, nextPageToken); | |
yield fetchEntity(request, commentActions.thread, videoId); | |
} | |
export function* watchCommentThread() { | |
while(true) { | |
const {videoId, nextPageToken} = yield take(commentActions.COMMENT_THREAD[REQUEST]); | |
yield fork(fetchCommentThread, videoId, nextPageToken); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment